Ok, I made it so far. It wasn’t that obvious how to figure out the naming. Does it say in the documentation that the arguments must be named objClassName to work correctly. But fun to get it to discover BT-devices so far
function CBD:centralManagerDidUpdateState_(central)
print("did", central, central.state)
print(cm.state)
if cm.state == 5 then -- poweredOn
print("scan")
cm:scanForPeripheralsWithServices_options_(nil)
end
end
function CBD:centralManager_didDiscoverPeripheral_advertisementData_RSSI_(central,objCBPeripheral,c,d)
print("discovered name", objCBPeripheral.name)
end
function setup()
s = Scene()
d = CBD()
CM = objc.cls.CBCentralManager
cm = CM()
cm:initWithDelegate_queue_(d,nil)
end
~~~
I guess you have to figure out the api for your watch. I think the pinetime watch uses a standard api for heartrate, but I havent tested it with any other device.
I’ve now rewritten it to read the step counter and motion sensor as well. And send a message to the watch.
Comments
~~~
CBD = objc.delegate("CBCentralManagerDelegate")
function CBD:centralManagerDidUpdateState(central)
print(central.state)
end
function setup()
d = CBD()
cm = objc.cls.CBCentralManager(d, nil)
cm:scanForPeripherals_withServices_(nil)
end
~~~
~~~
CBD = objc.delegate("CBCentralManagerDelegate")
function CBD:centralManagerDidUpdateState_(central)
print("did", central, central.state)
print(cm.state)
if cm.state == 5 then -- poweredOn
print("scan")
cm:scanForPeripheralsWithServices_options_(nil)
end
end
function CBD:centralManager_didDiscoverPeripheral_advertisementData_RSSI_(central,objCBPeripheral,c,d)
print("discovered name", objCBPeripheral.name)
end
function setup()
s = Scene()
d = CBD()
CM = objc.cls.CBCentralManager
cm = CM()
cm:initWithDelegate_queue_(d,nil)
end
~~~
Now it reads the heartrate, steps, accelerometer from my watch and displays it. It also sends a message to it.
I’ve now rewritten it to read the step counter and motion sensor as well. And send a message to the watch.