Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Revision:
0:fc77522f4d28
Child:
8:7ba4f82de9b6
diff -r 000000000000 -r fc77522f4d28 aconno_ble/aconno_ble.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/aconno_ble/aconno_ble.cpp	Wed Mar 07 13:40:28 2018 +0000
@@ -0,0 +1,55 @@
+/*
+ *   Made by Jurica Resetar @ aconno
+ *   More info @ aconno.de
+ *
+ */
+
+#include "aconno_ble.h"
+
+/**
+* Callback triggered when the ble initialization process has finished
+*/
+
+void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
+{
+    advertising_packet advertisementPacket;
+    BLE&        ble   = params->ble;
+    ble_error_t error = params->error;
+
+    if (error != BLE_ERROR_NONE) {
+        return;
+    }
+
+    /* Ensure that it is the default instance of BLE */
+    if(ble.getInstanceID() != BLE::DEFAULT_INSTANCE) {
+        return;
+    }
+    
+    advertisementPacket.header = APPLICATION_ID;
+    advertisementPacket.type = 0x00;
+    advertisementPacket.gyroscope[0] = (int16_t)0;
+    advertisementPacket.gyroscope[1] = (int16_t)0;
+    advertisementPacket.gyroscope[2] = (int16_t)0;
+    advertisementPacket.accelerometer[0] = (int16_t)0;
+    advertisementPacket.accelerometer[1] = (int16_t)0;
+    advertisementPacket.accelerometer[2] = (int16_t)0;
+    advertisementPacket.magnetometer[0] = (int16_t)0;
+    advertisementPacket.magnetometer[1] = (int16_t)0;
+    advertisementPacket.magnetometer[2] = (int16_t)0;
+    
+    /* setup advertising */
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
+    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(uint8_t)*11);
+    ble.gap().setAdvertisingInterval(ADV_INTERVAL_MS);
+    ble.gap().startAdvertising();
+}
+
+void updatePayload(BLE *ble, advertising_packet *advertisementPacket)
+{
+    ble->gap().stopAdvertising();
+    GapAdvertisingData advetisementData = GapAdvertisingData();
+    advetisementData = ble->getAdvertisingData();
+    advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)advertisementPacket, sizeof(advertising_packet));
+    ble->setAdvertisingData(advetisementData);
+    //ble->gap().startAdvertising();
+}