Modified sample program of BLE_BatteryLevel. The program add analog input pin setting and batteryLevel data is changed by analog input.
Dependencies: BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1
Fork of BLE_BatteryLevel by
Revision 8:45beed07b093, committed 2014-09-22
- Comitter:
- rgrover1
- Date:
- Mon Sep 22 10:28:55 2014 +0000
- Parent:
- 7:85c603b950f3
- Child:
- 9:e03630cd5009
- Commit message:
- updating to 0.2.0 of the BLE_API
Changed in this revision
--- a/BLE_API.lib Fri Jun 13 12:12:18 2014 +0000 +++ b/BLE_API.lib Mon Sep 22 10:28:55 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#5d2102351bf4 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#620d28e7a1ba
--- a/main.cpp Fri Jun 13 12:12:18 2014 +0000
+++ b/main.cpp Mon Sep 22 10:28:55 2014 +0000
@@ -16,6 +16,7 @@
#include "mbed.h"
#include "BLEDevice.h"
+#include "BatteryService.h"
BLEDevice ble;
@@ -32,17 +33,11 @@
#define DEBUG(...) /* nothing */
#endif /* #if NEED_CONSOLE_OUTPUT */
-/* Battery Level Service */
-uint8_t batt = 72; /* Battery level */
-GattCharacteristic battLevel (GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, &batt, sizeof(batt), sizeof(batt),
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
-GattCharacteristic *battChars[] = {&battLevel};
-GattService battService (GattService::UUID_BATTERY_SERVICE, battChars, sizeof(battChars) / sizeof(GattCharacteristic *));
+BatteryService *batteryServicePtr = NULL;
-
-void disconnectionCallback(void)
+void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
- DEBUG("Disconnected!\n\r");
+ DEBUG("Disconnected handle %u!\n\r", handle);
DEBUG("Restarting the advertising process\n\r");
ble.startAdvertising();
}
@@ -57,11 +52,12 @@
if (ble.getGapState().connected) {
/* Update battery level */
+ static uint8_t batt = 50;
batt++;
if (batt > 100) {
batt = 72;
}
- ble.updateCharacteristicValue(battLevel.getHandle(), (uint8_t *)&batt, sizeof(batt));
+ batteryServicePtr->updateBatteryLevel(batt);
}
}
@@ -81,7 +77,8 @@
ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */
ble.startAdvertising();
- ble.addService(battService);
+ BatteryService batterService(ble);
+ batteryServicePtr = &batterService;
while (true) {
ble.waitForEvent();
--- a/mbed.bld Fri Jun 13 12:12:18 2014 +0000 +++ b/mbed.bld Mon Sep 22 10:28:55 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file
--- a/nRF51822.lib Fri Jun 13 12:12:18 2014 +0000 +++ b/nRF51822.lib Mon Sep 22 10:28:55 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#c3ce6ee5d300 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#b3680699d9a4
