aconno acnsensa project for iOS devices with iBeacon packets support.

Dependencies:   LSM9DS1 Si7006A20 aconno_SEGGER_RTT aconno_bsp adc52832_common

Branch:
PowerConsumption
Revision:
34:714dfddf2cd9
Parent:
33:c93573163958
Child:
36:9e40cdef6bd6
diff -r c93573163958 -r 714dfddf2cd9 main.cpp
--- a/main.cpp	Mon Aug 06 14:11:51 2018 +0200
+++ b/main.cpp	Mon Aug 06 16:08:51 2018 +0200
@@ -22,33 +22,6 @@
 #include <events/mbed_events.h>
 #include "aconnoConfig.h"
 
-#define V0 0.47    /* In volts */
-#define TC 0.01    /* In volts */
-#define VCC (3.6)
-#define VALUE_TO_PERCENTAGE (100)
-#define WAKEUP_TIME_DELAY_MS (150)
-#define APPLICATION_ID (0xCF170059)
-
-#define ADC_REFERENCE    (3.6f)    /* adc reference voltage */
-#define ADC_RESOLUTION   (1024)    /* 10-bit adc            */
-
-#define I2C_DATA (p19)
-#define I2C_CLK  (p20)
-#define SPI_MISO (p5)
-#define SPI_MOSI (p3)
-#define SPI_SCLK (p4)
-
-#define DEBUG           	(0)
-#define DEBUG_PRINT     	(1)
-#define SLEEP_TIME      	(0.150)          /* Sleep time in seconds 		*/
-#define WAKE_UP_TIME    	(0.150)          /* Awake time in ms 			*/
-#define ADV_INTERVAL    	(100)           /* Advertising interval in ms 	*/
-#define GO_TO_SLEEP     	(0)
-/* Sleep flag: 0 -> Device will not go to sleep, 1 -> Will go to sleep mode */
-#define CALIBRATION_STEPS 	(20)
-#define TX_POWER_DB      	(4)
-#define INVERT_AXES			(1)
-
 uint8_t gConnected = 0;
 
 static NRF52_SAADC analogIn;
@@ -284,6 +257,12 @@
 
     if(!advertisementType && !gConnected)
     {
+		power = 1;
+	    wait_ms(WAKEUP_TIME_DELAY_MS);
+		mems->startAccelerometer();
+	    mems->startGyroscope();
+	    mems->startMagnetometer();
+
         printf("Sensor format 1.\n");
         ble.gap().clearAdvertisingPayload();
 		/* setup advertising */
@@ -311,9 +290,18 @@
         adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA,
             (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
         ble.setAdvertisingData(adv_data);
+
+		power = 0;
+	    wait_ms(WAKEUP_TIME_DELAY_MS);
     }
     else if (advertisementType == 1 && !gConnected)
     {
+		power = 1;
+	    wait_ms(WAKEUP_TIME_DELAY_MS);
+	    temperaturePower = 1;
+	    lightPower = 1;
+	    shdn = 1; // Wake up the pressure sensor
+
         printf("Sensor format 2.\n");
         analogIn.updateData();
         adv_data = ble.getAdvertisingData();
@@ -327,6 +315,12 @@
         adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA,
             (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
         ble.setAdvertisingData(adv_data);
+
+		power = 0;
+	    wait_ms(WAKEUP_TIME_DELAY_MS);
+	    temperaturePower = 0;
+	    lightPower = 0;
+	    shdn = 0; // Wake up the pressure sensor
     }
 
     else if (!gConnected)
@@ -345,8 +339,6 @@
 
 int main()
 {
-    printf("Main started.\n");
-
     Thread bleT;
 
     power = 1;
@@ -354,6 +346,7 @@
     temperaturePower = 1;
     lightPower = 1;
     shdn = 1; // Wake up the pressure sensor
+
     analogIn.addChannel(9); // Set VDD  as source to SAADC
     analogIn.addChannel(6); // Light
     analogIn.addChannel(7); // Temp
@@ -373,13 +366,8 @@
     spi      = new SPI(SPI_MOSI, SPI_MISO, SPI_SCLK);
     mpl115a1 = new MPL115A1(*spi, cs);
 
-    mems->startAccelerometer();
-    mems->startGyroscope();
-    mems->startMagnetometer();
-
-    eventQueue.call_every(100, updateData);
+    eventQueue.call_every(UPDATE_SENSORS_TIME_MS, updateData);
 
     // This call stops main thread
     eventQueue.dispatch_forever();
 }
-