From bbbc829b7f129b8a8cde118000bb89f1806aff25 Mon Sep 17 00:00:00 2001
From: Bertrand Lemasle <blemasle@gmail.com>
Date: Fri, 16 Mar 2018 22:56:35 +1300
Subject: [PATCH] Defined configuration constants. Added a timeout to the menu.
 The goal is to automatically run normally at boot if no input is detected

---
 GpsTracker/Config.h  | 19 +++++++++++++++----
 GpsTracker/Debug.cpp | 13 ++++++++++++-
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/GpsTracker/Config.h b/GpsTracker/Config.h
index 259ad82..54e8239 100644
--- a/GpsTracker/Config.h
+++ b/GpsTracker/Config.h
@@ -3,7 +3,7 @@
 #include <Arduino.h>
 
 #define BACKUP_ENABLE_SDCARD 0
-#define BACKUP_ENABLE_NETWORK 1
+#define BACKUP_ENABLE_NETWORK 0
 
 #if BACKUP_ENABLE_NETWORK
 #include "NetworkPositionsConfig.h"
@@ -16,14 +16,25 @@
 
 #define SIM808_BAUDRATE 4800
 
-#define SLEEP_DEFAULT_TIME_SECONDS	1800
+#pragma region Default configuration values
 
-#define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS	10000
-#define GPS_DEFAULT_TOTAL_TIMEOUT_MS		180000
+#define MENU_TIMEOUT	10000
+/**
+ \def SLEEP_DEFAULT_TIME_SECONDS
+ Hard coded value for default sleep time between position acquisitions.
+ Exprimed in seconds
+*/
+#define SLEEP_DEFAULT_TIME_SECONDS				1800
+#define SLEEP_DEFAULT_INCREASE_THRESHOLD		3
+
+#define GPS_DEFAULT_INTERMEDIATE_TIMEOUT_MS		10000
+#define GPS_DEFAULT_TOTAL_TIMEOUT_MS			180000
 
 #define NETWORK_DEFAULT_INTERMEDIATE_TIMEOUT_MS 6000
 #define NETWORK_DEFAULT_TOTAL_TIMEOUT_MS		180000
 
+#pragma endregion
+
 struct sleepTimings_t {
 	uint8_t speed;
 	uint16_t seconds;
diff --git a/GpsTracker/Debug.cpp b/GpsTracker/Debug.cpp
index 7892bbe..dbbf6f3 100644
--- a/GpsTracker/Debug.cpp
+++ b/GpsTracker/Debug.cpp
@@ -147,12 +147,23 @@ namespace debug {
 		GPSTRACKER_DEBUG_COMMAND command;
 		size_t menuSize = flash::getArraySize(MENU_ENTRIES);
 		
+		int16_t timeout = MENU_TIMEOUT;
+
 		do {		
 			for (uint8_t i = 0; i < menuSize; i++) {
 				Serial.println(reinterpret_cast<const __FlashStringHelper *>(pgm_read_word_near(&MENU_ENTRIES[i])));
 			}
 
-			while (!Serial.available());		
+			while (!Serial.available()) {
+#ifndef _DEBUG
+				delay(50); 
+				timeout -= 50;
+				if (timeout < 0) {
+					NOTICE_MSG("menu", "Timeout expired.");
+					return GPSTRACKER_DEBUG_COMMAND::RUN;
+				}
+#endif
+			}
 			command = parseCommand(Serial.read());
 			while (Serial.available()) Serial.read();
 		} while (command == GPSTRACKER_DEBUG_COMMAND::NONE);