Cycle speed and cadence example for the BLE API using nRF51822 native mode drivers

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_HeartRate by Bluetooth Low Energy

Revision:
71:7b6a488af957
Parent:
67:b2d2dee347c0
Child:
73:bae88c99c2ae
diff -r 0a19690e8d23 -r 7b6a488af957 main.cpp
--- a/main.cpp	Tue Aug 11 21:58:13 2015 +0000
+++ b/main.cpp	Sun Aug 16 13:23:48 2015 +0000
@@ -16,15 +16,15 @@
 
 #include "mbed.h"
 #include "ble/BLE.h"
-#include "ble/services/HeartRateService.h"
+#include "CyclingSpeedAndCadenceService.h"
 #include "ble/services/BatteryService.h"
 #include "ble/services/DeviceInformationService.h"
 
 BLE  ble;
 DigitalOut led1(LED1);
 
-const static char     DEVICE_NAME[]        = "HRM1";
-static const uint16_t uuid16_list[]        = {GattService::UUID_HEART_RATE_SERVICE,
+const static char     DEVICE_NAME[]        = "CSC1";
+static const uint16_t uuid16_list[]        = {GattService::UUID_CYCLING_SPEED_AND_CADENCE,
                                               GattService::UUID_DEVICE_INFORMATION_SERVICE};
 static volatile bool  triggerSensorPolling = false;
 
@@ -52,22 +52,24 @@
     ble.gap().onDisconnection(disconnectionCallback);
 
     /* Setup primary service. */
-    uint8_t hrmCounter = 100; // init HRM to 100bps
-    HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER);
+    uint32_t wheelCounter = 100; // init Wheel to 100revs
+    uint16_t crankCounter = 10; // init crank to 10revs
+    CyclingSpeedAndCadenceService cscService(ble, CyclingSpeedAndCadenceService::LOCATION_CHAINSTAY);
 
     /* Setup auxiliary service. */
-    DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
+    DeviceInformationService deviceInfo(ble, "ROB", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1");
 
     /* Setup advertising. */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
-    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::CYCLING_SPEED_AND_CADENCE_SENSOR);
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
     ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
     ble.gap().setAdvertisingInterval(1000); /* 1000ms */
     ble.gap().startAdvertising();
 
     // infinite loop
+    uint16_t when = 0;
     while (1) {
         // check for trigger from periodicCallback()
         if (triggerSensorPolling && ble.getGapState().connected) {
@@ -75,15 +77,12 @@
 
             // Do blocking calls or whatever is necessary for sensor polling.
             // In our case, we simply update the HRM measurement.
-            hrmCounter++;
-
-            //  100 <= HRM bps <=175
-            if (hrmCounter == 175) {
-                hrmCounter = 100;
-            }
+            wheelCounter += 3;
+            crankCounter++;
+            when += 1024;
 
             // update bps
-            hrService.updateHeartRate(hrmCounter);
+            cscService.updateCounters(wheelCounter, crankCounter, when);
         } else {
             ble.waitForEvent(); // low power wait for event
         }