PUBLISH HelloBlue

Dependencies:   BLE_API mbed nRF51822

Fork of HelloBlue by Wayne Keenan

Files at this revision

API Documentation at this revision

Comitter:
waynek
Date:
Mon Jan 18 11:13:31 2016 +0000
Parent:
1:b84d6e0b404e
Commit message:
updated to confirm to the latest BLE API

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
diff -r b84d6e0b404e -r 4f0d8bf09690 BLE_API.lib
--- a/BLE_API.lib	Wed Jan 28 17:44:09 2015 +0000
+++ b/BLE_API.lib	Mon Jan 18 11:13:31 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#1407d2f1ce3c
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#ff83f0020480
diff -r b84d6e0b404e -r 4f0d8bf09690 main.cpp
--- a/main.cpp	Wed Jan 28 17:44:09 2015 +0000
+++ b/main.cpp	Mon Jan 18 11:13:31 2016 +0000
@@ -1,31 +1,50 @@
 #include "mbed.h"
-#include "BLEDevice.h"
+#include "ble/BLE.h"
 
-// DFUService is already included & automatically advertised by the mbed lib dependancies (currently)
+// DFUService is already included & automatically advertised by the mbed lib dependancies
 
 const static char     DEVICE_NAME[]        = "HelloBlue";
 
 BLEDevice ble;
 
-void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
+void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
+{
+    BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising(); // restart advertising
+}
+
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
 {
-    ble.startAdvertising(); // restart advertising
+    BLE &ble          = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        return;
+    }
+
+    ble.gap().onDisconnection(disconnectionCallback);
+    
+    /* Setup advertising. */
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+    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); /* ms */
+    ble.gap().startAdvertising();
 }
 
+
 int main(void)
 {
-    ble.init();
-    ble.onDisconnection(disconnectionCallback);
-
-    /* Setup advertising. */
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
-    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
-    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
-    ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000));
-    ble.startAdvertising();
+    BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE);
+    ble.init(bleInitComplete);
     
-   while (true) {
-        ble.waitForEvent();
+    /* SpinWait for initialization to complete. This is necessary because the
+     * BLE object is used in the main loop below. */
+    while (ble.hasInitialized()  == false) { /* spin loop */ }
+    
+    while (1) 
+    {
+        // to see if a Central device is currently connected you can call: ble.getGapState().connected
+        ble.waitForEvent(); // low power wait for event
     }
 }
 
diff -r b84d6e0b404e -r 4f0d8bf09690 mbed.bld
--- a/mbed.bld	Wed Jan 28 17:44:09 2015 +0000
+++ b/mbed.bld	Mon Jan 18 11:13:31 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file
diff -r b84d6e0b404e -r 4f0d8bf09690 nRF51822.lib
--- a/nRF51822.lib	Wed Jan 28 17:44:09 2015 +0000
+++ b/nRF51822.lib	Mon Jan 18 11:13:31 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#0e7a9efee6d7
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#1751e2e2637a