heart rate monitor
Dependencies: BLE_API GroveEarbudSensor mbed nRF51822
Fork of BLE_HeartRate by
Revision 71:c86b4658af70, committed 2015-08-29
- Comitter:
- ppm2005
- Date:
- Sat Aug 29 17:49:14 2015 +0000
- Parent:
- 70:0a19690e8d23
- Child:
- 72:cc9b1d195d9f
- Commit message:
- commit
Changed in this revision
--- a/BLE_API.lib Tue Aug 11 21:58:13 2015 +0000 +++ b/BLE_API.lib Sat Aug 29 17:49:14 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#920101117187 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#8d316a3271a8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GroveEarbudSensor.lib Sat Aug 29 17:49:14 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ansond/code/GroveEarbudSensor/#8687d42d6798
--- a/main.cpp Tue Aug 11 21:58:13 2015 +0000 +++ b/main.cpp Sat Aug 29 17:49:14 2015 +0000 @@ -19,15 +19,22 @@ #include "ble/services/HeartRateService.h" #include "ble/services/BatteryService.h" #include "ble/services/DeviceInformationService.h" - +// Grove Earbud Sensor include +#include "GroveEarbudSensor.h" BLE ble; DigitalOut led1(LED1); +// Our sensor as an InterruptIn +InterruptIn sensor(P0_0); const static char DEVICE_NAME[] = "HRM1"; static const uint16_t uuid16_list[] = {GattService::UUID_HEART_RATE_SERVICE, GattService::UUID_DEVICE_INFORMATION_SERVICE}; static volatile bool triggerSensorPolling = false; +// callback for receiving heartrate values +void heartrateCallback(float heartrate,void *data) { + printf("Callback: heartrate = %.1f\r\n",heartrate); +} void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { ble.gap().startAdvertising(); // restart advertising @@ -53,6 +60,7 @@ /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps + HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); /* Setup auxiliary service. */ @@ -75,14 +83,37 @@ // Do blocking calls or whatever is necessary for sensor polling. // In our case, we simply update the HRM measurement. - hrmCounter++; + // hrmCounter++; // 100 <= HRM bps <=175 - if (hrmCounter == 175) { + /*if (hrmCounter == 175) { hrmCounter = 100; - } + }*/ + // announce + printf("Grove Earbud Sensor - Montoring Heart Rate\r\n"); + + // allocate the earbud sensor + printf("Allocating earbud sensor instance...\r\n"); + GroveEarbudSensor earbud(&sensor); + + // register our callback function + printf("registering callback...\r\n"); + earbud.registerCallback(heartrateCallback); + + /* begin main loop + printf("Beginning main loop...\r\n"); + while (true) { + // blink... + led1 = !led1; + wait(0.5);*/ + + // we can also call directly + printf("Direct: heartrate = %.1f\r\n", earbud.getHeartRate()); + hrmCounter=earbud.getHeartRate(); + // update bps + //hrService.updateHeartRate(hrmCounter); hrService.updateHeartRate(hrmCounter); } else { ble.waitForEvent(); // low power wait for event
--- a/mbed.bld Tue Aug 11 21:58:13 2015 +0000 +++ b/mbed.bld Sat Aug 29 17:49:14 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/8ed44a420e5c \ No newline at end of file
--- a/nRF51822.lib Tue Aug 11 21:58:13 2015 +0000 +++ b/nRF51822.lib Sat Aug 29 17:49:14 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#041752486b03 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#ca9c9c2cfc6a