BLE testing connecting
Dependencies: BLE_API mbed nRF51822
Fork of BLE_HeartRate by
Revision 78:cc60d57d699d, committed 2016-08-12
- Comitter:
- titusfong
- Date:
- Fri Aug 12 21:42:25 2016 +0000
- Parent:
- 77:a2ab41a7f067
- Commit message:
- ble testing for chip
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 11 16:21:48 2016 +0000 +++ b/main.cpp Fri Aug 12 21:42:25 2016 +0000 @@ -14,11 +14,19 @@ * limitations under the License. */ +#if NEED_CONSOLE_OUTPUT +#define DEBUG(STR) { if (uart) uart->write(STR, strlen(STR)); } +#else +#define DEBUG(...) /* nothing */ +#endif /* #if NEED_CONSOLE_OUTPUT */ + #include "mbed.h" #include "ble/BLE.h" #include "ble/services/HeartRateService.h" #include "ble/services/BatteryService.h" #include "ble/services/DeviceInformationService.h" +#include "UARTService.h" + DigitalOut led1(LED1); @@ -31,6 +39,8 @@ HeartRateService *hrService; DeviceInformationService *deviceInfo; +UARTService *uart; + void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { @@ -69,7 +79,7 @@ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_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().setAdvertisingInterval(1500); /* 1000ms */ ble.gap().startAdvertising(); } @@ -81,6 +91,8 @@ BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); ble.init(bleInitComplete); + uart = new UARTService(ble); + /* SpinWait for initialization to complete. This is necessary because the * BLE object is used in the main loop below. */ @@ -91,13 +103,17 @@ // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { triggerSensorPolling = false; - + DEBUG("ping\r\n"); + wait_ms(500); // Do blocking calls or whatever is necessary for sensor polling. // In our case, we simply update the HRM measurement. - hrmCounter++; + /* hrmCounter++; if (hrmCounter == 175) { // 100 <= HRM bps <=175 hrmCounter = 100; } + */ + + hrService->updateHeartRate(hrmCounter); } else {