fork microbit-dal
Dependencies: BLE_API mbed-dev-bin nRF51822
Fork of microbit-dal by
Diff: source/bluetooth/MicroBitBLEManager.cpp
- Revision:
- 21:cab56b701601
- Parent:
- 1:8aa5cdb4ab67
- Child:
- 22:23d7b9a4b082
--- a/source/bluetooth/MicroBitBLEManager.cpp Wed Jul 13 12:17:51 2016 +0100 +++ b/source/bluetooth/MicroBitBLEManager.cpp Wed Jul 13 12:17:53 2016 +0100 @@ -109,6 +109,8 @@ */ static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason) { + MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_DISCONNECTED); + storeSystemAttributes(reason->handle); if (manager) @@ -116,6 +118,14 @@ } /** + * Callback when a BLE connection is established. + */ +static void bleConnectionCallback(const Gap::ConnectionCallbackParams_t *params) +{ + MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_CONNECTED); +} + +/** * Callback when a BLE SYS_ATTR_MISSING. */ static void bleSysAttrMissingCallback(const GattSysAttrMissingCallbackParams *params) @@ -267,6 +277,9 @@ // automatically restart advertising after a device disconnects. ble->gap().onDisconnection(bleDisconnectionCallback); ble->gattServer().onSysAttrMissing(bleSysAttrMissingCallback); + + // generate an event when a Bluetooth connection is lost + ble->gap().onConnection(bleConnectionCallback); // Configure the stack to hold onto the CPU during critical timing events. // mbed-classic performs __disable_irq() calls in its timers that can cause @@ -599,4 +612,4 @@ for (int j=0; j<h+1; j++) display.image.setPixelValue(MICROBIT_DFU_HISTOGRAM_WIDTH-i-1, MICROBIT_DFU_HISTOGRAM_HEIGHT-j-1, 255); } -} +} \ No newline at end of file