Application running on nRF51822 PCA10001

Dependencies:   BLE_API MMA8652 nRF51822 mbed-src

Revision:
6:2fb6cf3c9047
Parent:
4:630f1560a0f3
diff -r 21ec0f1f019a -r 2fb6cf3c9047 main.cpp
--- a/main.cpp	Tue Sep 16 08:23:26 2014 +0000
+++ b/main.cpp	Tue Oct 14 13:04:06 2014 +0000
@@ -26,8 +26,9 @@
 #include "BLEDevice.h"
 //#include "nRF51822n.h"
 //#include "MMA8652.h"
-#include "DevInfoService.h"
 #include "BuddiService.h"
+#include "BatteryService.h"
+#include "DeviceInformationService.h"
 
 /******************************************************************************
 * Module Preprocessor Constants
@@ -57,23 +58,13 @@
 
 void bluetoothInit();
 
-// https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml
-static uint8_t      batteryLevel = 100;
-GattCharacteristic  batteryPercentage(GattCharacteristic::UUID_BATTERY_LEVEL_CHAR, (uint8_t *)batteryLevel, sizeof(batteryLevel), sizeof(batteryLevel),
-                           GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
-GattCharacteristic *batteryChars[] = {&batteryPercentage };
-GattService         batteryService(GattService::UUID_BATTERY_SERVICE, batteryChars, sizeof(batteryChars) / sizeof(GattCharacteristic *));
-
-//static const uint16_t uuid16_list[] = {GattService::UUID_DEVICE_INFORMATION_SERVICE,
-//                                       GattService::UUID_BATTERY_SERVICE};
-//static const unit8_t uuid128_list[] = {(const uint8_t *)buddi_service_uuid_rev, 
-//                                       (const uint8_t *)buddi_service_uuid_rev, 
-//                                       (const uint8_t *)buddi_service_uuid_rev};
-
 static volatile bool triggerSensorPolling = false; /* set to high periodically to indicate to the main thread that
                                                     * polling is necessary. */
 static Gap::ConnectionParams_t connectionParams;
-                                         
+
+uint8_t batteryLevel = 100;
+BatteryService *batteryServicePtr = NULL;
+
 /******************************************************************************
 * Function Prototypes
 *******************************************************************************/
@@ -130,10 +121,10 @@
     DEBUG("Notifications enabled for %d\r\n", handle);
 }
 
-void onDataWritten(uint16_t charHandle, const GattCharacteristicWriteCBParams *params)
+void onDataWritten(const GattCharacteristicWriteCBParams *params)
 {
     // bubble up to services, they will emit callbacks if handle matches
-    Nudge::handleDataWritten(charHandle, params);
+    //Nudge::handleDataWritten(params);
 }
 
 /**
@@ -176,10 +167,9 @@
           connectionParams.connectionSupervisionTimeout);
     
     // Initialise services
-    //ble.addService(devInfoService);
-    DevInfo::init(ble);
-    ble.addService(batteryService);
-    //ble.addService(buddiService);
+    BatteryService batteryService(ble);
+    batteryServicePtr = &batteryService;
+    DeviceInformationService deviceInfo(ble, "Buddi Ltd.", "BlueBand", "1234567890", "Hardware: 0", "Firmware: 0001", "Build: 0001");
     Nudge::init(ble);
     
     /* setup advertising */
@@ -222,12 +212,12 @@
             /* Do blocking calls or whatever is necessary for sensor polling. */
             if (ble.getGapState().connected) {
                 /* Update the battery measurement */
-                //batteryLevel = adc1.read_u16()&0x0FFF) * 3.3/4096;
+                //batteryLevel = adc1.read_u16()&0x0FFF) * 3.3/4096;                
                 batteryLevel--;
                 if (batteryLevel == 1) {
                     batteryLevel = 100;
                 }
-                //ble.updateCharacteristicValue(batteryPercentage.getHandle(), &batteryLevel, sizeof(batteryLevel));
+                batteryServicePtr->updateBatteryLevel(batteryLevel);
             }
             
         } else {