From 56f884cd10fbdb3aafd1a9082e4618d8bdbd4577 Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 12 Feb 2020 14:29:35 -0800 Subject: [PATCH] don't sleep if user pressed button recently --- src/configuration.h | 2 +- src/main.ino | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 2d892018..3c23405f 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -62,7 +62,7 @@ along with this program. If not, see . // If not defined, we will wait for lock forever -#define MINWAKE_MSECS (60 * 1000) // stay awake a long time (30 mins) for debugging +#define MINWAKE_MSECS (5 * 60 * 1000) // stay awake a long time (30 mins) for debugging // #define MINWAKE_MSECS (30 * 1000) // Wait after every boot for GPS lock (may need longer than 5s because we turned the gps off during deep sleep) // ----------------------------------------------------------------------------- diff --git a/src/main.ino b/src/main.ino index c3be5730..66ad55de 100644 --- a/src/main.ino +++ b/src/main.ino @@ -434,7 +434,7 @@ void loop() // if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of this boilerplate) static bool wasPressed = false; static uint32_t minPressMs; // what tick should we call this press long enough - static uint32_t lastPingMs; + static uint32_t lastPingMs, lastPressMs; if (!digitalRead(BUTTON_PIN)) { if (!wasPressed) @@ -444,6 +444,7 @@ void loop() wasPressed = true; uint32_t now = millis(); + lastPressMs = now; minPressMs = now + 3000; if (now - lastPingMs > 60 * 1000) @@ -470,8 +471,8 @@ void loop() #endif #ifdef MINWAKE_MSECS - // Don't deepsleep if we have USB power - if (millis() > MINWAKE_MSECS && !isCharging) + // Don't deepsleep if we have USB power or if the user as pressed a button recently + if (millis() - lastPressMs > MINWAKE_MSECS && !isCharging) { sleep(); }