BLE heart rate example, with yotta machinations.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Revision:
45:98c5a34b07a4
Parent:
43:dbb025ed4a55
Child:
46:ee7c55907f36
--- a/main.cpp	Tue Sep 23 15:11:57 2014 +0000
+++ b/main.cpp	Mon Sep 29 18:27:56 2014 +0000
@@ -19,9 +19,10 @@
 #include "HeartRateService.h"
 #include "BatteryService.h"
 #include "DeviceInformationService.h"
+#include "DFUService.h"
 
 BLEDevice  ble;
-DigitalOut led1(LED1);
+// DigitalOut led1(LED1);
 
 #define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
                                * it will have an impact on code-size and power consumption. */
@@ -33,7 +34,7 @@
 #define DEBUG(...) /* nothing */
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
-const static char     DEVICE_NAME[]        = "HRMonitor";
+const static char     DEVICE_NAME[]        = "Nordic_HRM";
 static const uint16_t uuid16_list[]        = {GattService::UUID_HEART_RATE_SERVICE,
                                               GattService::UUID_BATTERY_SERVICE,
                                               GattService::UUID_DEVICE_INFORMATION_SERVICE};
@@ -48,7 +49,7 @@
 
 void periodicCallback(void)
 {
-    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
+    // led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
 
     /* Note that the periodicCallback() executes in interrupt context, so it is safer to do
      * heavy-weight sensor polling from the main thread. */
@@ -57,7 +58,7 @@
 
 int main(void)
 {
-    led1 = 1;
+    // led1 = 1;
     Ticker ticker;
     ticker.attach(periodicCallback, 1);
 
@@ -65,7 +66,16 @@
     ble.init();
     ble.onDisconnection(disconnectionCallback);
 
-    /* setup advertising */
+    /* Setup primary service. */
+    uint8_t hrmCounter = 100;
+    HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER);
+
+    /* Setup auxiliary services. */
+    BatteryService           battery(ble);
+    DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
+    DFUService               dfuService(ble);
+
+    /* Setup advertising. */
     ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
     ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
     ble.accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
@@ -74,11 +84,6 @@
     ble.setAdvertisingInterval(1600); /* 1000ms; in multiples of 0.625ms. */
     ble.startAdvertising();
 
-    uint8_t hrmCounter = 100;
-    HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER);
-    BatteryService battery(ble);
-    DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
-
     while (true) {
         if (triggerSensorPolling) {
             triggerSensorPolling = false;