init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Files at this revision

API Documentation at this revision

Comitter:
pathfindr
Date:
Fri Jan 18 00:07:45 2019 +0000
Parent:
41:07e41dbd5304
Child:
43:7b232f03628f
Commit message:
state engine fix

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
modem.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jan 17 23:40:03 2019 +0000
+++ b/main.cpp	Fri Jan 18 00:07:45 2019 +0000
@@ -215,16 +215,22 @@
             if((RET_RTCunixtime - RET_buttonPressTime) > 1) {
                 switch (RET_buttonPressCount) {   
                     case 1 :
-                        RET_state = STATE_BUTTONPRESS1;
-                        mainthread.release();
+                        if(RET_state != STATE_DORMANT) {
+                            RET_state = STATE_BUTTONPRESS1;
+                            mainthread.release();
+                        }
                         break;
                     case 3 :
-                        RET_state = STATE_BUTTONPRESS2;
-                        mainthread.release();
+                        if(RET_state != STATE_DORMANT) {
+                            RET_state = STATE_BUTTONPRESS2;
+                            mainthread.release();
+                        }
                         break;
                     case 5 :
-                        RET_state = STATE_BUTTONPRESS3;
-                        mainthread.release();
+                        if(RET_state != STATE_DORMANT) {
+                            RET_state = STATE_BUTTONPRESS3;
+                            mainthread.release();
+                        }
                         break;
                     default :
                         //do nothing
@@ -399,8 +405,8 @@
     //calculate motion state
     if (RET_motionPendingOnState) {
         //check if above threshold
-        time_t inMotionForSeconds = (RET_RTCunixtime - RET_motionStartTime) + 5; //Plus 5 to account for rounding and non exact clocks
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "IN MOTION FOR:%d",inMotionForSeconds);debug_exe();}
+        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 (inMotionForSeconds >= RET_setting_motion_start_seconds && RET_motionState == false) {
             RET_motionState = true;
             RET_motionTriggeredInTXInterval = true;
@@ -412,8 +418,8 @@
         }
     }
     if (RET_motionPendingOffState) {
-        time_t noMotionForSeconds = (RET_RTCunixtime - RET_motionStopTime) + 5; //Plus 5 to account for rounding and non exact clocks
-        if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "STOPPED FOR:%d",noMotionForSeconds);debug_exe();}
+        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 (noMotionForSeconds >= RET_setting_motion_stop_seconds && RET_motionState == true) {
             //if (GLOBAL_debugLED) LED1blink(2,50);
             RET_motionPendingOffState = false;
@@ -862,6 +868,7 @@
         }
         case STATE_SCORCHEDEARTH :
         {
+            if(DEBUG_ON){debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer),"SCORCHED EARTH - RESETTING");debug_exe();}
             setState(STATE_SETUP); //this wont be used but just incase to kick it out of this state
             read_app_data_from_flash(&app_data);
             app_data.current_firmware_version = 0;
@@ -941,13 +948,14 @@
         //MAIN LOGIC
         if(DEBUG_ON){
             if (RET_state != 99) {
-                debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "FW:%d,ST:%d, SET:%d, MOTFR:%d, MOTST: %d, RTC:%u, LOC:%u, LOCFS:%u, ACT:%u \n", FW_VERSION, RET_state, RET_haveSettings, RET_motionTriggeredinFrame, RET_motionState, RET_RTCunixtime,RET_eventTime_location_tx,RET_eventTime_location_failsafe_tx,RET_eventTime_activity_tx);debug_exe();
+                debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "FW:%d,ST:%d, SET:%d, MFR:%d, MST: %d, RTC:%u, L:%u, LFS:%u, A:%u", FW_VERSION, RET_state, RET_haveSettings, RET_motionTriggeredinFrame, RET_motionState, RET_RTCunixtime,RET_eventTime_location_tx,RET_eventTime_location_failsafe_tx,RET_eventTime_activity_tx);debug_exe();
                 debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "ACT:%s\n",RET_activityData);debug_exe();
             } else {
                 debug_prep();snprintf(GLOBAL_debug_buffer, sizeof(GLOBAL_debug_buffer), "FW:%d, ST:%d, WAKE@:%u\n", FW_VERSION, RET_state, RET_eventTime_wakeFromDormant);debug_exe();
             }
         }
 
+        //STATE ENGINE
         mainStateEngine();
                 
         //LOG FIRST RUN - BOOTLOADER COMMS
--- a/modem.h	Thu Jan 17 23:40:03 2019 +0000
+++ b/modem.h	Fri Jan 18 00:07:45 2019 +0000
@@ -8,7 +8,7 @@
     #define UC20_BAUDRATE       115200
     #define SIM7600_BAUDRATE    115200
     #define USSD_MAXLENGTH      160
-    #define ATTIMEOUT_VERYSHORT 2000
+    #define ATTIMEOUT_VERYSHORT 3000
     #define ATTIMEOUT_SHORT     5000
     #define ATTIMEOUT_MED       10000
     #define ATTIMEOUT_LONG      20000