aconno acnsensa project for iOS devices with iBeacon packets support.

Dependencies:   LSM9DS1 Si7006A20 aconno_SEGGER_RTT aconno_bsp adc52832_common

Revision:
29:b65cab4fa70f
Parent:
21:71f2f1b314f2
Child:
30:eadbeb23fe95
diff -r fb90a508f50f -r b65cab4fa70f main.cpp
--- a/main.cpp	Fri Aug 03 14:41:28 2018 +0200
+++ b/main.cpp	Mon Aug 06 12:32:27 2018 +0200
@@ -55,7 +55,6 @@
 static NRF52_DigitalOut lightPower(p28);
 static NRF52_DigitalOut temperaturePower(p31);
 static NRF52_DigitalOut shdn(p6);
-static NRF52_DigitalOut led(p23);
 static NRF52_DigitalOut power(p2);
 static NRF52_DigitalOut cs(p7);
 static Si7006   *si;
@@ -74,27 +73,31 @@
     #define printf(...)
 #endif
 
-static bool sleepFlag = true;
-
 static vector3_s memsAccelerometerInit;
 static vector3_s memsGyroscopeInit;
 static vector3_s memsMagnetometerInit;
 
 static GapAdvertisingData adv_data = GapAdvertisingData();
 
-typedef struct __attribute__((packed, aligned(1)))
+struct __attribute__((packed, aligned(1))) iBeaconMSD_t
 {
 	// AppleID is constant
-	uint16_t appleID = 0x004C;
+	uint16_t appleID;
 	// secondID is constant
-	uint8_t  secondID = 0x02;
+	uint8_t  secondID;
 	// DataSize is constant
-	uint8_t  DataSize = 0x15;
-	uint8_t  UUID[16] = {UUID_INIT};
-	uint16_t  major = MAJOR;
-	uint16_t  minor = MINOR;
-	int8_t   RSSI = RSSI_INIT;
-}IBeaconMSD;
+	uint8_t  dataSize;
+	uint8_t  UUID[16];
+	uint16_t  major;
+	uint16_t  minor;
+	int8_t   RSSI;
+}static iBeaconMSD = {.appleID = 0x004C,
+					  .secondID = 0x02,
+					  .dataSize = 0x15,
+					  .UUID = {UUID_INIT},
+					  .major = MAJOR,
+					  .minor = MINOR,
+					  .RSSI = RSSI_INIT};
 
 struct __attribute__((packed, aligned(1))) advertising_packet
 {
@@ -124,7 +127,6 @@
 }
 
 static advertising_packet advertisementPacket;
-IBeaconMSD ibeaconMSD;
 
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
 {
@@ -133,14 +135,6 @@
     BLE::Instance().gap().startAdvertising();
 }
 
-/**
- *  Function for waking the core up
- */
-void wakeMeUp()
-{
-    sleepFlag = false;
-}
-
 void onConnectionCallback(const Gap::ConnectionCallbackParams_t *params)
 {
     printf("Connection callback.\n");
@@ -343,7 +337,7 @@
 	        GapAdvertisingData::BREDR_NOT_SUPPORTED);
 	    ble.gap().accumulateAdvertisingPayload(
 	        GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA,
-	        (uint8_t*)&ibeaconMSD, sizeof(ibeaconMSD));
+	        (uint8_t*)&iBeaconMSD, sizeof(iBeaconMSD_t));
 		ble.gap().startAdvertising();
     }
     if(++advertisementType > 2) advertisementType = 0;
@@ -365,22 +359,13 @@
     analogIn.addChannel(7); // Temp
     analogIn.calibrate();
 
-    advertisementPacket.header = APPLICATION_ID;
-
-    ibeaconMSD.appleID = 0x004C;
-    ibeaconMSD.secondID = 0x02;
-    ibeaconMSD.DataSize = 0x15;
-    ibeaconMSD.UUID[0] = 0x11;
-    ibeaconMSD.UUID[1] = 0x22;
-    ibeaconMSD.UUID[2] = 0x33;
-    ibeaconMSD.RSSI = -4;
-
     BLE &ble = BLE::Instance();
     ble.init(bleInitCompleteSensors);
     while(ble.hasInitialized() == false){
         /* spin loop */
     }
     ble.onEventsToProcess(scheduleBleEventsProcessing);
+	advertisementPacket.header = APPLICATION_ID;
 
     I2C i2c(I2C_DATA, I2C_CLK);
     si       = new Si7006(&i2c);
@@ -392,11 +377,6 @@
     mems->startGyroscope();
     mems->startMagnetometer();
 
-    led = 1;
-
-    Ticker ticker;
-    ticker.attach(wakeMeUp, SLEEP_TIME); // Wake the device up
-
     eventQueue.call_every(500, updateData);
 
     // This call stops main thread