add iBeacon functionality

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal by Ken Ogami

Revision:
80:1d4526d816a8
Parent:
78:e4c9170fd9b9
Child:
81:5691aae23431
--- a/source/bluetooth/MicroBitBLEManager.cpp	Wed Aug 02 00:23:30 2017 +0000
+++ b/source/bluetooth/MicroBitBLEManager.cpp	Mon Oct 16 18:35:40 2017 +0000
@@ -31,6 +31,7 @@
 #include "MicroBitStorage.h"
 #include "MicroBitFiber.h"
 #include "MicroBitSystemTimer.h"
+#include "MicroBitIBeacon.h"
 
 /* The underlying Nordic libraries that support BLE do not compile cleanly with the stringent GCC settings we employ.
  * If we're compiling under GCC, then we suppress any warnings generated from this code (but not the rest of the DAL)
@@ -209,7 +210,7 @@
 #if (MICROBIT_BLE_ADVERTISING_TIMEOUT > 0)
     ble->gap().setAdvertisingTimeout(MICROBIT_BLE_ADVERTISING_TIMEOUT);
 #endif
-    ble-?gap().startAdvertising();
+    ble->gap().startAdvertising();
 }
 
 
@@ -280,7 +281,7 @@
     ble->gap().setAdvertisingTimeout(MICROBIT_BLE_ADVERTISING_TIMEOUT);
 #endif
     ble->gap().startAdvertising();
-
+    
     return ret;
 }
 
@@ -299,6 +300,43 @@
 }
 #endif
 
+/**
+  * Set the content of Eddystone URL frames
+  *
+  * @param proximityUUID 16-byte proximity UUID
+  *
+  * @param major 2-byte major value
+  *
+  * @param minor 2-byte minor value
+  *
+  * @param calibratedPower the transmission range of the beacon (Defaults to: 0xF0 ~10m).
+  *
+  * @param interval the rate at which the micro:bit will advertise url frames. (Defaults to MICROBIT_BLE_EDDYSTONE_ADV_INTERVAL)
+  *
+  * @note The calibratedPower value ranges from -100 to +20 to a resolution of 1. The calibrated power should be binary encoded.
+  * More information can be found at https://github.com/google/eddystone/tree/master/eddystone-uid#tx-power
+  */
+int MicroBitBLEManager::advertiseIBeacon(const UUID &proximityUUID, int16_t major, int16_t minor, int8_t calibratedPower, uint16_t interval)
+{
+    int retVal = MICROBIT_OK;
+
+    ble->gap().stopAdvertising();
+    ble->clearAdvertisingPayload();
+
+    ble->setAdvertisingType(GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED);
+    ble->setAdvertisingInterval(interval);
+
+    ble->accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
+
+    retVal = MicroBitIBeacon::getInstance()->setParams(ble, proximityUUID, major, minor, calibratedPower);
+
+#if (MICROBIT_BLE_ADVERTISING_TIMEOUT > 0)
+    ble->gap().setAdvertisingTimeout(MICROBIT_BLE_ADVERTISING_TIMEOUT);
+#endif
+    ble->gap().startAdvertising();
+
+    return retVal;
+}
 
  void MicroBitBLEManager::pairingMode(MicroBitDisplay &display, MicroBitButton &authorisationButton)
  {