Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Diff: services/BatteryService.h
- Revision:
- 710:b2e1a2660ec2
- Parent:
- 671:33ec93d25695
--- a/services/BatteryService.h Fri Jun 19 15:53:06 2015 +0100 +++ b/services/BatteryService.h Fri Jun 19 15:53:28 2015 +0100 @@ -17,7 +17,7 @@ #ifndef __BLE_BATTERY_SERVICE_H__ #define __BLE_BATTERY_SERVICE_H__ -#include "BLE.h" +#include "BLEDevice.h" /** * @class BatteryService @@ -29,19 +29,25 @@ public: /** * @param[ref] _ble - * BLE object for the underlying controller. + * BLEDevice object for the underlying controller. * @param[in] level * 8bit batterly level. Usually used to represent percentage of batterly charge remaining. */ - BatteryService(BLE &_ble, uint8_t level = 100) : + BatteryService(BLEDevice &_ble, uint8_t level = 100) : ble(_ble), batteryLevel(level), batteryLevelCharacteristic(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batteryLevel, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { + static bool serviceAdded = false; /* We should only ever need to add the heart rate service once. */ + if (serviceAdded) { + return; + } + GattCharacteristic *charTable[] = {&batteryLevelCharacteristic}; GattService batteryService(GattService::UUID_BATTERY_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); ble.addService(batteryService); + serviceAdded = true; } /** @@ -56,8 +62,8 @@ ble.updateCharacteristicValue(batteryLevelCharacteristic.getValueAttribute().getHandle(), &batteryLevel, 1); } -protected: - BLE &ble; +private: + BLEDevice &ble; uint8_t batteryLevel; ReadOnlyGattCharacteristic<uint8_t> batteryLevelCharacteristic;