Solution for Bluetooth SIG hands-on training course

Dependencies:   BLE_API mbed-dev-bin nRF51822-bluetooth-mdw

Dependents:   microbit

Fork of microbit-dal-bluetooth-mdw_starter by Martin Woolley

Revision:
23:6055f6c19fa6
Parent:
22:23d7b9a4b082
Child:
24:3373f1fb0353
--- a/source/bluetooth/MicroBitBLEManager.cpp	Wed Jul 13 12:17:54 2016 +0100
+++ b/source/bluetooth/MicroBitBLEManager.cpp	Wed Jul 13 12:17:56 2016 +0100
@@ -109,6 +109,8 @@
   */
 static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *reason)
 {
+    MicroBitEvent(MICROBIT_ID_BLE,MICROBIT_BLE_EVT_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_EVT_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