+ battery and device information
Dependencies: BLE_API X_NUCLEO_IDB0XA1 mbed
Fork of BLE_HeartRate_IDB0XA1 by
Revision 22:519a64a68971, committed 2016-10-12
- Comitter:
- a29
- Date:
- Wed Oct 12 10:41:44 2016 +0000
- Parent:
- 21:0e7c08f5386f
- Commit message:
- + battery and device information service
;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0e7c08f5386f -r 519a64a68971 main.cpp --- a/main.cpp Wed Oct 05 09:16:58 2016 +0000 +++ b/main.cpp Wed Oct 12 10:41:44 2016 +0000 @@ -17,11 +17,15 @@ #include "mbed.h" #include "ble/BLE.h" #include "ble/services/HeartRateService.h" +#include "ble/services/BatteryService.h" +#include "ble/services/DeviceInformationService.h" DigitalOut led1(LED1, 1); const static char DEVICE_NAME[] = "HRM1"; -static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE}; +static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, + GattService::UUID_DEVICE_INFORMATION_SERVICE, + GattService::UUID_BATTERY_SERVICE}; static volatile bool triggerSensorPolling = false; @@ -65,6 +69,12 @@ /* Setup primary service. */ uint8_t hrmCounter = 60; // init HRM to 60bps HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); + + /* Setup auxiliary service. */ + uint8_t batteryLevel = 90; // init battery level + BatteryService battery(ble,batteryLevel); + DeviceInformationService deviceInfo(ble, "MY_ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); + /* Setup advertising. */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); @@ -86,12 +96,22 @@ hrmCounter++; // 60 <= HRM bps <= 100 - if (hrmCounter == 100) { + if (hrmCounter == 90) { hrmCounter = 60; } - + // update bps hrService.updateHeartRate(hrmCounter); + + batteryLevel++; + + // 90 <= battery level <= 100 + if (batteryLevel == 100) { + batteryLevel = 90; + } + + // update battery level + battery.updateBatteryLevel(batteryLevel); } else { ble.waitForEvent(); // low power wait for event }