ble button A on microbit
Dependencies: BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1
Fork of BLE_HeartRate by
Revision 72:99c283dfe28d, committed 2015-11-02
- Comitter:
- rgrover1
- Date:
- Mon Nov 02 09:49:57 2015 +0000
- Parent:
- 71:469dbde1a238
- Child:
- 73:49b6090478e2
- Commit message:
- update to v2.0.0 of BLE_API. Add bleInitComplete() to main.c
Changed in this revision
--- a/BLE_API.lib Tue Sep 29 09:49:50 2015 +0000 +++ b/BLE_API.lib Mon Nov 02 09:49:57 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#d494ad3e87bd +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#b099c28e8e28
--- a/main.cpp Tue Sep 29 09:49:50 2015 +0000 +++ b/main.cpp Mon Nov 02 09:49:57 2015 +0000 @@ -28,6 +28,11 @@ GattService::UUID_DEVICE_INFORMATION_SERVICE}; static volatile bool triggerSensorPolling = false; +uint8_t hrmCounter = 100; // init HRM to 100bps + +HeartRateService *hrService; +DeviceInformationService *deviceInfo; + void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { ble.gap().startAdvertising(); // restart advertising @@ -42,21 +47,19 @@ triggerSensorPolling = true; } -int main(void) +void bleInitComplete(BLE &ble, ble_error_t error) { - led1 = 1; - Ticker ticker; - ticker.attach(periodicCallback, 1); // blink LED every second + if (error != BLE_ERROR_NONE) { + return; + } - 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"); + deviceInfo = new DeviceInformationService(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); /* Setup advertising. */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); @@ -66,6 +69,15 @@ ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms */ ble.gap().startAdvertising(); +} + +int main(void) +{ + led1 = 1; + Ticker ticker; + ticker.attach(periodicCallback, 1); // blink LED every second + + ble.init(bleInitComplete); // infinite loop while (1) { @@ -76,14 +88,11 @@ // Do blocking calls or whatever is necessary for sensor polling. // In our case, we simply update the HRM measurement. hrmCounter++; - - // 100 <= HRM bps <=175 - if (hrmCounter == 175) { + if (hrmCounter == 175) { // 100 <= HRM bps <=175 hrmCounter = 100; } - // update bps - hrService.updateHeartRate(hrmCounter); + hrService->updateHeartRate(hrmCounter); } else { ble.waitForEvent(); // low power wait for event }
--- a/mbed.bld Tue Sep 29 09:49:50 2015 +0000 +++ b/mbed.bld Mon Nov 02 09:49:57 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11 \ No newline at end of file
--- a/nRF51822.lib Tue Sep 29 09:49:50 2015 +0000 +++ b/nRF51822.lib Mon Nov 02 09:49:57 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#088f5738bf18 +http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#9ff3e688014b