diff --git a/GpsTracker/Debug.cpp b/GpsTracker/Debug.cpp index ef2a0a4..4e41311 100644 --- a/GpsTracker/Debug.cpp +++ b/GpsTracker/Debug.cpp @@ -136,16 +136,26 @@ namespace debug { return GPSTRACKER_DEBUG_COMMAND::NONE; } - GPSTRACKER_DEBUG_COMMAND menu() { + GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout) { GPSTRACKER_DEBUG_COMMAND command; size_t menuSize = flash::getArraySize(MENU_ENTRIES); + uint8_t intermediate_timeout = 50; do { for (uint8_t i = 0; i < menuSize; i++) { Serial.println(reinterpret_cast(pgm_read_word_near(&MENU_ENTRIES[i]))); } - while (!Serial.available()); delay(50); + while (!Serial.available()) { + if (timeout > 0) { + delay(intermediate_timeout); + timeout -= intermediate_timeout; + if (timeout <= 0) { + NOTICE_MSG("menu", "Timeout expired."); + return GPSTRACKER_DEBUG_COMMAND::RUN; + } + } + } command = parseCommand(Serial.read()); while (Serial.available()) Serial.read(); //flushing input } while (command == GPSTRACKER_DEBUG_COMMAND::NONE); diff --git a/GpsTracker/Debug.h b/GpsTracker/Debug.h index a9ddd38..71644bc 100644 --- a/GpsTracker/Debug.h +++ b/GpsTracker/Debug.h @@ -39,7 +39,7 @@ namespace debug { int freeRam(); void displayFreeRam(); - GPSTRACKER_DEBUG_COMMAND menu(); + GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout); void getAndDisplayBattery(); void getAndDisplayGpsPosition(); diff --git a/GpsTracker/GpsTracker.ino b/GpsTracker/GpsTracker.ino index 6f5d4f2..8d55721 100644 --- a/GpsTracker/GpsTracker.ino +++ b/GpsTracker/GpsTracker.ino @@ -22,7 +22,7 @@ void setup() { void loop() { debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; - if (Serial && !bypassMenu) command = debug::menu(); + if (Serial && !bypassMenu) command = debug::menu(MENU_TIMEOUT); bypassMenu = command == debug::GPSTRACKER_DEBUG_COMMAND::RUN;