简体   繁体   中英

Cadence from BLE Device

-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
     dispatch_async(dispatch_get_main_queue(), ^{

         NSData *data = characteristic.value;
         uint8_t *array = (uint8_t*) data.bytes;

         cadenceValue = [CharacteristicReader readUInt8Value:&array];
         self.cadence.text = [NSString stringWithFormat:@"%d", cadenceValue];
         });
}

How to get cadence from bLE (Bluetooth low energy) device in swift 2 . I am unable to find exact code for this. For this didUpdateValueForCharacteristic delegate method is called.

I have a code of nRF Toolbox but it is in objective c or swift 3 but my project is in swift 2 . I tried to call objective c method using bridging header but it was always returned 0 cadence.

I'm not sure the definition of CharacteristicReader , but you might try:

[CharacteristicReader readUInt8Value:&array];
cadenceValue = Int(array[0])
self.cadence.text = [NSString stringWithFormat:@"%d", cadenceValue];

The above assumes that the result of the call to readUInt8Value gets put into the array of UInt8 objects, and the cadence value is in the first byte of the array. You could also check if the proper value is in other bytes by trying cadenceValue = Int(array[1]) or cadenceValue = Int(array[2]) , etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM