
cycle speed and cadence service
Dependencies: BLE_API mbed nRF51822
Fork of Bluetooth_Heart_Rate_Monitor_dummy by
Diff: main.cpp
- Revision:
- 65:7f84fa8c59ac
- Parent:
- 64:43e7ddf9dba5
- Child:
- 67:688f92dc0f49
- Child:
- 68:bff4ebcb9f12
--- a/main.cpp Thu May 07 21:00:29 2015 +0000 +++ b/main.cpp Fri May 08 06:36:02 2015 +0000 @@ -25,6 +25,7 @@ * interval.*/ #define UPDATE_PARAMS_FOR_LONGER_CONNECTION_INTERVAL 0 #define TICK_TIME 1.0/1024 +#define DEBOUNCE_TIME 100 BLEDevice ble; DigitalOut led1(LED1); @@ -35,6 +36,13 @@ static volatile bool updateWheel = false; static volatile bool updateCrank = false; +InterruptIn wheelSwitch(p1); +InterruptIn crankSwitch(p2); + +Timer wheelDebounce; +Timer crankDebounce; + + static volatile uint32_t wheelCounter; static volatile uint16_t wheelEvent; static volatile uint16_t crankCounter; @@ -51,12 +59,37 @@ counter++; } +void incrementWheel() { + if (wheelDebounce.read_ms()>DEBOUNCE_TIME){ //only allow toggle if debounce timer has passed 200ms + wheelDebounce.reset(); //restart timer when toggle is performed + wheelCounter++; + wheelEvent=counter; + led1= !led1; + } +} + +void incrementCrank() { + if (crankDebounce.read_ms()>DEBOUNCE_TIME){ //only allow toggle if debounce timer has passed 200ms + crankDebounce.reset(); //restart timer when toggle is performed + crankCounter++; + crankEvent=counter; + led1= !led1; + } +} + + int main(void) { led1 = 1; Ticker ticker; ticker.attach(periodicCallback, TICK_TIME); // blink LED every second + wheelDebounce.start(); + crankDebounce.start(); + + wheelSwitch.rise(&incrementWheel); + crankSwitch.rise(&incrementCrank); + ble.init(); ble.onDisconnection(disconnectionCallback); @@ -82,7 +115,7 @@ if ((updateWheel || updateCrank) && ble.getGapState().connected) { if (updateWheel){ - speedService.updateWheel(wheelCounter,wheelCounter); + speedService.updateWheel(wheelCounter,wheelEvent); updateWheel=false; } if (updateCrank){