From a093a1ea47c2e910cda25a9b7c83cdcc58ea5505 Mon Sep 17 00:00:00 2001 From: Bertrand Lemasle Date: Sun, 18 Mar 2018 12:28:08 +1300 Subject: [PATCH] Revert "Removed menu timeout, that was a bad idea" This reverts commit 92c6a34fef8dc6d7f276bce0e481b3146f57b1bb. --- GpsTracker/Debug.cpp | 14 ++++++++++++-- GpsTracker/Debug.h | 2 +- GpsTracker/GpsTracker.ino | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) 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;