BLE lib
Fork of Nucleo_BLE_API by
Diff: services/HeartRateService.h
- Revision:
- 4:f1696bf0e6c6
- Parent:
- 0:289fd2dae405
diff -r a2cd3d33fe44 -r f1696bf0e6c6 services/HeartRateService.h --- a/services/HeartRateService.h Mon Jan 05 18:45:24 2015 +0000 +++ b/services/HeartRateService.h Sun Feb 08 14:26:05 2015 +0000 @@ -62,7 +62,7 @@ /** * Same constructor as above, but with a 16-bit HRM Counter value. */ - HeartRateService(BLEDevice &_ble, uint16_t hrmCounter, uint8_t location) : + HeartRateService(BLEDevice &_ble, uint32_t hrmCounter, uint8_t location) : ble(_ble), valueBytes(hrmCounter), hrmRate(GattCharacteristic::UUID_HEART_RATE_MEASUREMENT_CHAR, valueBytes.getPointer(), @@ -86,7 +86,7 @@ /** * Set a new 16-bit value for heart rate. */ - void updateHeartRate(uint16_t hrmCounter) { + void updateHeartRate(uint32_t hrmCounter) { valueBytes.updateHeartRate(hrmCounter); ble.updateCharacteristicValue(hrmRate.getValueAttribute().getHandle(), valueBytes.getPointer(), valueBytes.getNumValueBytes()); } @@ -127,7 +127,7 @@ private: /* Private internal representation for the bytes used to work with the vaulue of the heart-rate characteristic. */ struct HeartRateValueBytes { - static const unsigned MAX_VALUE_BYTES = 3; /* FLAGS + up to two bytes for heart-rate */ + static const unsigned MAX_VALUE_BYTES = 5; /* FLAGS + up to two bytes for heart-rate */ static const unsigned FLAGS_BYTE_INDEX = 0; static const unsigned VALUE_FORMAT_BITNUM = 0; @@ -137,7 +137,7 @@ updateHeartRate(hrmCounter); } - HeartRateValueBytes(uint16_t hrmCounter) : valueBytes() { + HeartRateValueBytes(uint32_t hrmCounter) : valueBytes() { updateHeartRate(hrmCounter); } @@ -146,10 +146,12 @@ valueBytes[FLAGS_BYTE_INDEX + 1] = hrmCounter; } - void updateHeartRate(uint16_t hrmCounter) { + void updateHeartRate(uint32_t hrmCounter) { valueBytes[FLAGS_BYTE_INDEX] |= VALUE_FORMAT_FLAG; valueBytes[FLAGS_BYTE_INDEX + 1] = (uint8_t)(hrmCounter & 0xFF); valueBytes[FLAGS_BYTE_INDEX + 2] = (uint8_t)(hrmCounter >> 8); + valueBytes[FLAGS_BYTE_INDEX + 3] = (uint8_t)(hrmCounter >> 16); + valueBytes[FLAGS_BYTE_INDEX + 4] = (uint8_t)(hrmCounter >> 24); } uint8_t *getPointer(void) { @@ -161,7 +163,7 @@ } unsigned getNumValueBytes(void) const { - return 1 + ((valueBytes[FLAGS_BYTE_INDEX] & VALUE_FORMAT_FLAG) ? sizeof(uint16_t) : sizeof(uint8_t)); + return 1 + ((valueBytes[FLAGS_BYTE_INDEX] & VALUE_FORMAT_FLAG) ? sizeof(uint32_t) : sizeof(uint8_t)); } private: