cycle speed and cadence service
Dependencies: BLE_API mbed nRF51822
Fork of Bluetooth_Heart_Rate_Monitor_dummy by
Diff: main.cpp
- Revision:
- 64:43e7ddf9dba5
- Parent:
- 63:e4f933430f17
- Child:
- 65:7f84fa8c59ac
diff -r e4f933430f17 -r 43e7ddf9dba5 main.cpp --- a/main.cpp Mon May 04 22:48:46 2015 +0000 +++ b/main.cpp Thu May 07 21:00:29 2015 +0000 @@ -24,6 +24,7 @@ * particularly for applications where the central may want a fast connection * interval.*/ #define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0 +#define TICK_TIME 1.0/1024 BLEDevice ble; DigitalOut led1(LED1); @@ -31,7 +32,14 @@ const static char DEVICE_NAME[] = "CSC tracker"; static const uint16_t uuid16_list[] = {GattService::UUID_CYCLING_SPEED_AND_CADENCE, GattService::UUID_DEVICE_INFORMATION_SERVICE}; -static volatile bool triggerSensorPolling = false; +static volatile bool updateWheel = false; +static volatile bool updateCrank = false; + +static volatile uint32_t wheelCounter; +static volatile uint16_t wheelEvent; +static volatile uint16_t crankCounter; +static volatile uint16_t crankEvent; +static volatile uint16_t counter; void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { @@ -40,27 +48,21 @@ void periodicCallback(void) { - 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. */ - triggerSensorPolling = true; + counter++; } int main(void) { led1 = 1; Ticker ticker; - ticker.attach(periodicCallback, 1); // blink LED every second + ticker.attach(periodicCallback, TICK_TIME); // blink LED every second ble.init(); ble.onDisconnection(disconnectionCallback); - /* Setup primary service. */ - uint32_t counter = 0; // init HRM to 100bps - uint16_t cadence = 0; // init HRM to 100bps - uint16_t event = 1; // init HRM to 100bps - CycleSpeedCadenceService speedService(ble, counter,event,cadence,event, CycleSpeedCadenceService::LOCATION_REAR_DROPOUT, false); + + + CycleSpeedCadenceService speedService(ble, wheelCounter,wheelEvent,crankCounter,crankEvent, CycleSpeedCadenceService::LOCATION_REAR_DROPOUT); /* Setup auxiliary service. */ DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); @@ -77,21 +79,16 @@ // infinite loop while (1) { // check for trigger from periodicCallback() - if (triggerSensorPolling && ble.getGapState().connected) { - triggerSensorPolling = false; - - // Do blocking calls or whatever is necessary for sensor polling. - // In our case, we simply update the HRM measurement. - counter++; - counter++; - cadence++; //ADDED TO CHECK - event++; //ADDED TO CHECK + if ((updateWheel || updateCrank) && ble.getGapState().connected) { - - - // update bps - speedService.updateWheel(counter,event); - speedService.updateCrank(cadence,event); + if (updateWheel){ + speedService.updateWheel(wheelCounter,wheelCounter); + updateWheel=false; + } + if (updateCrank){ + speedService.updateCrank(crankCounter,crankEvent); + updateCrank=false; + } } else { ble.waitForEvent(); // low power wait for event }