Geo beacon for VF.

Dependencies:   MMA8452 aconno_bsp adc52832_common

Revision:
23:729717272b31
Parent:
22:8d106fd5fa84
Child:
24:201b9d8b6c5a
Child:
25:8ac3ff431ab1
--- a/main.cpp	Mon Aug 28 19:58:11 2017 +0000
+++ b/main.cpp	Wed Aug 30 08:10:53 2017 +0000
@@ -15,20 +15,22 @@
 #include "nrf52_uart.h"
 #include "nrf52_digital.h"
 
-#define DEBUG               (0)
+#define DEBUG               (1)
 #define DEBUG_ACC           (0)
 #define PRINT               (0)
 #define DEBUG_MAC           (0)
 #define DEBUG_CONNECTION    (0)
 #define USE_ACC             (0)
 
-#define SLEEP_TIME_S              (9.0)           /* Sleep time (in s)          */
-#define ADV_TIMER_TIME_S          (0.5)           /* Advertising time (in s)    */
-#define SCAN_TIMER_TIME_S         (0.5)           /* Scanning time (in s)       */
+#define SLEEP_TIME_S              (6.0)           /* Sleep time (in s)          */
+#define ADV_TIMER_TIME_S          (0.25)           /* Advertising time (in s)    */
+#define SCAN_TIMER_TIME_S         (0.25)           /* Scanning time (in s)       */
 #define FREE_TIME_S               (0.1)           /* Time between end of a scanning and sleep mode */
 #define AWAKE_TIME_S              (ADV_TIMER_TIME_S+SCAN_TIMER_TIME_S+FREE_TIME_S)      /* Was 0.15 */
 #define SHORT_SLEEP_TIME_S        (0.5)           /* Shorter sleep time (s) */
 #define SHORT_SLEEP_TIME_PERIOD_S (10)            /* Time after a last scanned advertisment. In the period, sleep time is SHORT_SLEEP_TIME */
+#define BUZZ_PERIOD_US            (250)
+#define BUZZ_DURATION_MS          (1000)
 #define MAC_SIZE_B                (6)
 
 /* Static constants for the BLE example */
@@ -66,7 +68,7 @@
 uint8_t sleepFlag = false;
 uint8_t tempSleepTime = SLEEP_TIME_S;
 uint8_t msd[MSD_SIZE] = {0x59, 0x00, 0xE1, 0x61, 0x35, 0xBA, 0xC0, 0xEC, 0x47, 0x2A, 0x98, 0x00, 0xAF, 0x18, 0x43, 0xFF, 0x05, 0x00};
-uint8_t myMacAddress[6] = {};          
+uint8_t myMacAddress[6] = {};   
 uint8_t buzzer_flag = 0;
 
 enum RadioState{
@@ -176,7 +178,7 @@
                     connectedLED = 1;
                     wait_ms(100);
                 #endif    
-                buzz(900,1000);
+                buzz(BUZZ_PERIOD_US,BUZZ_DURATION_MS);
                 WakeSleepT.detach();
                 WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
                 /*
@@ -230,10 +232,9 @@
     ble.gap().onConnection(onConnectionCallback);         // -->> Uncomment these two lines for shush-shush 
     ble.gattServer().onDataWritten(onDataWrittenCallback);
     
-    /* setup advertising */
     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, (uint8_t *)msd, MSD_SIZE);
     ble.gap().setAdvertisingInterval(ADV_INTERVAL);  // --> Has to be at least 100ms!
-    //ble.gap().startAdvertising();
+    
 
 }
 
@@ -312,7 +313,7 @@
             if ((params->advertisingData[msdOffset+2]) == 0x00){
                 if(CheckMac(params, myMacAddress, msdOffset)){
                     //ble.gap().stopScan();
-                    buzz(900,1000);
+                    buzz(BUZZ_PERIOD_US,BUZZ_DURATION_MS);
                     WakeSleepT.detach();
                     WakeSleepT.attach(WakeMeUp, FREE_TIME_S);
                 }
@@ -333,8 +334,6 @@
  *  The function is called when ticker generates interrupt
  */
 void TurnBuzzOff(void){
-    //buzzer.period(0.00F);
-    //buzzer.write(0.0F);
     tempSleepTime = SHORT_SLEEP_TIME_S;
     turnBuzzOffT.detach();
     WakeSleepT.detach();
@@ -356,8 +355,6 @@
     }
     else{
         ble.gap().startAdvertising();
-        //buzzer.period(0.00F);
-        //buzzer.write(0.0F);
         #if DEBUG
             advLED = 0;
             scanLED = 1;
@@ -369,11 +366,10 @@
 
 void startScanning(){
     ble.gap().stopAdvertising();
-    ble.gap().setScanParams(SCAN_INTERVAL, SCAN_WINDOW);
-    ble.gap().setScanTimeout(SCAN_TIMER_TIME_S);
+    ble.gap().setScanInterval(SCAN_INTERVAL);
+    ble.gap().setScanWindow(SCAN_WINDOW);
+    ble.gap().setScanParams();
     ble.gap().startScan(advertisementCallback);
-    //buzzer.period(0.00F);
-    //buzzer.write(0.0F);
     #if DEBUG
         advLED = 1;
         scanLED = 0;
@@ -407,8 +403,6 @@
 }
 
 void GoToSleep(){
-    //buzzer.period(0.00F);
-    //buzzer.write(0.0f);
     WakeSleepT.detach();
     WakeSleepT.attach(WakeMeUp, tempSleepTime);
     ble.gap().stopAdvertising();
@@ -425,8 +419,6 @@
         #if DEBUG_ACC
             int_led = !int_led;
         #endif
-        //buzzer.period(0.0009F);
-        //buzzer.write(0.5f);
     }
 #endif
 
@@ -437,8 +429,6 @@
         connectedLED = 1;
     #endif
     
-    //buzzer.period(0.0009F);
-    //buzzer.write(0.0F);
     #if USE_ACC
         accPower = 1;
         i2cPower = 1;