init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Files at this revision

API Documentation at this revision

Comitter:
pathfindr
Date:
Sun Jan 20 12:50:31 2019 +0000
Parent:
43:7b232f03628f
Child:
45:6c7f5b556d74
Commit message:
tweaks

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jan 20 00:15:03 2019 +0000
+++ b/main.cpp	Sun Jan 20 12:50:31 2019 +0000
@@ -17,7 +17,7 @@
 bool             GLOBAL_modemOn                      = false;
 bool             GLOBAL_LEDSequenceinProgress        = false;
 time_t           GLOBAL_wakeTime                     = 0;
-char             GLOBAL_exceptionString[32];
+char             GLOBAL_exceptionString[30];
 char             GLOBAL_debug_buffer[200];
 
 
@@ -189,16 +189,17 @@
 
     //button logic, only when device asleep
     if (RET_asleep == true) {
+        //led indicator
+        //if (RET_buttonPressTime > 0 && (RET_RTCunixtime - RET_buttonPressTime) > 4) led1 = 0;
+        //if (RET_buttonPressTime > 0 && (RET_RTCunixtime - RET_buttonPressTime) > 14) led1 = 1;
         //hold check
         if (RET_buttonHoldTime > 4 && RET_buttonHoldTime < 10) {
-            led1 = 0; // led on
             RET_buttonHoldTime = 0;
             RET_buttonPressCount = 0;
             RET_state_prev = RET_state;
             RET_state = STATE_BUTTONHOLD;
             mainthread.release();
         } else if (RET_buttonHoldTime > 14 && RET_buttonHoldTime < 30) {
-            led1 = 1; //led off
             RET_buttonHoldTime = 0;
             RET_buttonPressCount = 0;
             RET_state_prev = RET_state;
@@ -229,6 +230,7 @@
                         //do nothing
                         break;
                 }
+                RET_SetupRunAt = 0; //allow setup to run again
                 RET_buttonPressCount = 0;
             }
         }
@@ -401,7 +403,7 @@
     if (RET_motionPendingOnState) {
         //check if above threshold
         time_t inMotionForSeconds = (RET_RTCunixtime - RET_motionStartTime) + (DEFAULT_SLEEP_FRAME / 1000); //Plus DEFAULT_SLEEP_FRAME as it should include frame time
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "MOTION FOR:%d",inMotionForSeconds);debug_exe();}
+        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "MOT:%d s",inMotionForSeconds);debug_exe();}
         if (inMotionForSeconds >= RET_setting_motion_start_seconds && RET_motionState == false) {
             RET_motionState = true;
             RET_motionTriggeredInTXInterval = true;
@@ -414,7 +416,7 @@
     }
     if (RET_motionPendingOffState) {
         time_t noMotionForSeconds = (RET_RTCunixtime - RET_motionStopTime) + (DEFAULT_SLEEP_FRAME / 1000); //Plus DEFAULT_SLEEP_FRAME as it should include frame time
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "MOTIONLESS FOR:%d",noMotionForSeconds);debug_exe();}
+        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "MOTLESS:%d s",noMotionForSeconds);debug_exe();}
         if (noMotionForSeconds >= RET_setting_motion_stop_seconds && RET_motionState == true) {
             //if (GLOBAL_debugLED) LED1blink(2,50);
             RET_motionPendingOffState = false;
@@ -469,7 +471,7 @@
         if(TEMP_s != -1) { RET_setting_beacon_scan = TEMP_s;                            }
         
         if (critical_fail_count == 0) { 
-            if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "GOT SETTINGS OK");debug_exe();}
+            if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "SETTINGS OK");debug_exe();}
             dumpSettings();
             RET_haveSettings = true;
             GLOBAL_needToConfigureLis3dh = true;
@@ -479,7 +481,7 @@
                 read_app_data_from_flash(&app_data);
                 app_data.target_firmware_version = RET_setting_firmware;
                 write_app_data_to_flash(&app_data);
-                if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "Perform fw update\n");debug_exe();}
+                if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "OTA\n");debug_exe();}
                 ThisThread::sleep_for(250);
                 system_reset();
             }
@@ -487,11 +489,13 @@
         } else {
             if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "CRITICAL FAILS:%d",critical_fail_count);debug_exe();}
             dumpSettings();
-            RET_haveSettings = false; 
+            addToExceptionString("SCF");
+            //dont set RET_haveSettings = false; here, if we already have settings continue to use them
             return false;
         }
     } else {
-        RET_haveSettings = false;
+        //dont set RET_haveSettings = false; here, if we already have settings continue to use them
+        addToExceptionString("SPE");
         return false;
     }
 }
@@ -502,24 +506,24 @@
 void setEventTime_Location() {
     if(RET_setting_location_tx_interval_mins > 0) { 
         RET_eventTime_location_tx = (RET_RTCunixtime + (RET_setting_location_tx_interval_mins * 60));
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVENTSET - LOCATION TX at %u, MODE %d",RET_eventTime_location_tx, RET_setting_location_mode);debug_exe();}
+        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVTSET - LOC TX @ %u, MODE %d",RET_eventTime_location_tx, RET_setting_location_mode);debug_exe();}
     }
     if(RET_setting_location_tx_failsafe_hrs > 0) { 
         RET_eventTime_location_failsafe_tx = (RET_RTCunixtime + (RET_setting_location_tx_failsafe_hrs * 3600));
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVENTSET - LOCATION FAILSAFE TX at %u",RET_eventTime_location_failsafe_tx);debug_exe();}
+        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVTSET - LOC FS TX @ %u",RET_eventTime_location_failsafe_tx);debug_exe();}
     }
 }
 void setEventTime_Activity() {
     if(RET_setting_activity_tx_interval_hrs > 0) { 
         RET_motionFrameStart = RET_RTCunixtime; //SET START FRAME INITAL
         RET_eventTime_activity_tx = (RET_RTCunixtime + (RET_setting_activity_tx_interval_hrs * 3600));
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVENTSET - ACTIVITY TX at %u",RET_eventTime_activity_tx);debug_exe();}
+        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVTSET - ACT TX @ %u",RET_eventTime_activity_tx);debug_exe();}
     }
 }
 void setEventTime_Environmental() {
     if(RET_eventTime_environmental_tx > 0) { 
         RET_eventTime_environmental_tx = (RET_RTCunixtime + (RET_setting_environmental_tx_interval_mins * 60));
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVENTSET - ENVIRONMENTAL TX at %u",RET_eventTime_environmental_tx);debug_exe();}
+        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "EVTSET - ENV TX @ %u",RET_eventTime_environmental_tx);debug_exe();}
     }
 }
 void setEventTimes() {
@@ -537,7 +541,7 @@
     int timetaken = (RET_RTCunixtime - GLOBAL_wakeTime);
     char bytestosend[100];
     memset(bytestosend,0x00,sizeof(bytestosend));
-    snprintf(bytestosend,sizeof(bytestosend),"(%s,a:log,f:%d,v:%.2f,e:%d,z:%s,c:1,s:0)\0",GLOBAL_defaultApi,FW_VERSION,voltage,timetaken,error);
+    snprintf(bytestosend,sizeof(bytestosend),"(%s,a:log,f:%d,v:%.2f,e:%d,z:%s.%s,c:1,s:0)\0",GLOBAL_defaultApi,FW_VERSION,voltage,timetaken,error,GLOBAL_exceptionString);
     if (modem.on(RET_force2G)) {
         if (modem.registerOnNetwork(DEFAULT_CONNECTION_ATTEMPTS,(RET_setting_connection_timeout*1000))) {
             modem.USSDmessage(bytestosend, false, 2, GLOBAL_defaultApi);
@@ -572,11 +576,11 @@
                     pass = false;
                     modem.off(true);
                     if(GLOBAL_debugLED) LED1errorCode(5,10); //ERROR 5
-                    sendErrorLog("ERRSETTINGS");
+                    sendErrorLog("ERR:SU-IR");
                 }                      
             } else {
                 //Response error
-                sendErrorLog("ERRRESP");
+                sendErrorLog("ERR:SU-NR");
             }
         } else {
             //FAILUREMODE modem failed to register on network
@@ -646,10 +650,10 @@
             snprintf(result,sizeof(result),"%s",modem.USSDmessage(bytesToSend, getSettings, 2, GLOBAL_defaultApi));
             if (result != "err") {
                 if (getSettings) {
-                    if (saveSettings(result) == false){sendErrorLog("ERRSETTINGS");}
+                    if (saveSettings(result) == false){sendErrorLog("ERR:LOC-IR");}
                 }
             } else {
-                sendErrorLog("ERRRESP");
+                sendErrorLog("ERR:LOC-NR");
             }
         } else {
             modem.off(true);
@@ -776,7 +780,7 @@
         {
             setState(STATE_NORMAL);
             if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"BUTTON PRESS 2\n");debug_exe();}
-            LED1blink(2,300);
+            LED1blink(3,300);
             LED1on(0);
             event_setup(true);
             LED1off();
@@ -786,7 +790,7 @@
         {
             setState(STATE_NORMAL);
             if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"BUTTON PRESS 3\n");debug_exe();}
-            LED1blink(3,300);
+            LED1blink(5,300);
             LED1on(0);
             event_location_tx();
             LED1off();
--- a/main.h	Sun Jan 20 00:15:03 2019 +0000
+++ b/main.h	Sun Jan 20 12:50:31 2019 +0000
@@ -16,7 +16,7 @@
 //------------------------------------------------------------------------------
 //DEFINES
 //------------------------------------------------------------------------------ 
-#define FW_VERSION          1
+#define FW_VERSION          4
 #define SKU                 "GPSP"
 #define HW_MAJORREVISION    "001"