Heart Rate Monitor example for the BLE API using nRF51822 native mode drivers
Dependencies: BLE_API mbed nRF51822
Fork of BLE_HeartRate by
Diff: main.cpp
- Revision:
- 71:ecf479422c04
- Parent:
- 67:b2d2dee347c0
- Child:
- 72:fa6520343b72
--- a/main.cpp Tue Aug 11 21:58:13 2015 +0000 +++ b/main.cpp Mon Aug 31 05:11:16 2015 +0000 @@ -19,6 +19,7 @@ #include "ble/services/HeartRateService.h" #include "ble/services/BatteryService.h" #include "ble/services/DeviceInformationService.h" +#include "PulseSensor.h" BLE ble; DigitalOut led1(LED1); @@ -33,27 +34,19 @@ ble.gap().startAdvertising(); // restart advertising } -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; -} +HeartRateService * hrService; +void sendDataToProcessing(int hrmCounter); int main(void) { led1 = 1; - Ticker ticker; - ticker.attach(periodicCallback, 1); // blink LED every second - + ble.init(); ble.gap().onDisconnection(disconnectionCallback); /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps - HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); + hrService = new HeartRateService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); /* Setup auxiliary service. */ DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); @@ -66,8 +59,12 @@ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms */ ble.gap().startAdvertising(); + + PulseSensor sensor(P0_5, sendDataToProcessing); + sensor.start(); // infinite loop + /* while (1) { // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { @@ -83,9 +80,17 @@ } // update bps - hrService.updateHeartRate(hrmCounter); + sendDataToProcessing(hrmCounter); } else { ble.waitForEvent(); // low power wait for event } - } + }*/ } + +//PulseSensor.h expects a function with argument (int)..you can't use uint8 here + void sendDataToProcessing(int hrmCounter){ + hrService->updateHeartRate((uint8_t)hrmCounter); + //or you could just cast it to unit8..this just eases debugging + //int* ans = &hrmCounter; +} +