I've got a Polar h7 device around me right now (it's BTLE) and I've got everything working but I am confused about how to get the BPM our of the characteristic.value
now that it is updating. I have to turn some bytes into bpm...
My peripheral is updating:
func peripheral(peripheral: CBPeripheral!, didUpdateValueForCharacteristic characteristic: CBCharacteristic!, error: NSError!) {
if characteristic.UUID == CBUUID.UUIDWithString(heartRateChar) {
getInfoAboutHeartRate(characteristic)
}
}
I am getting info about the heart rate:
func getInfoAboutHeartRate(characteristic:CBCharacteristic) {
println(characteristic.value)
var bytes = characteristic.value.bytes
}
I know I need turn those bytes into the BPM.
According to the specs (this is where I get confused) at bluetooth.org, byte 0 is either going to be a 1
or a 0
.. If it is a 0
the heart rate value is an uint8
and if it is a 1
then it is a uint16
and I can get the BPM from that.
How do I find out if byte 0
is a 1
or a 0
? How to turn that into a uint8
or uint16
. And if I do that do I get the BPM straight up or do I have to do something else to it? Right now the BPM comes back as something like <16447d03>
which makes sense.