From 39a2432410bc3af85304982a6d724a2763167897 Mon Sep 17 00:00:00 2001 From: leblane Date: Fri, 16 Jun 2023 16:59:01 +0300 Subject: [PATCH] Add timeout to menu so you don't accidentally drain your battery by entering the menu before going to sleep. --- src/WatchFace.cpp | 19 +++++++++++++++++++ src/config.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/WatchFace.cpp b/src/WatchFace.cpp index 65df974..680febc 100644 --- a/src/WatchFace.cpp +++ b/src/WatchFace.cpp @@ -45,9 +45,11 @@ void WatchFace::HandleButtonPress(uint64_t buttonMask) const std::vector buttons = {MENU_BTN_PIN, UP_BTN_PIN, DOWN_BTN_PIN, BACK_BTN_PIN}; + uint64_t lastPressTime = m_features.rtc.GetTimestamp(); while (m_inMenu) { for (int button : buttons) { if (digitalRead(button) == HIGH) { + lastPressTime = m_features.rtc.GetTimestamp(); switch (button) { case MENU_BTN_PIN: m_menu.HandleButtonPress(MENU_BTN_MASK); @@ -65,14 +67,31 @@ void WatchFace::HandleButtonPress(uint64_t buttonMask) while (true) { if (digitalRead(button) == LOW) { + lastPressTime = m_features.rtc.GetTimestamp(); break; } +#if MENU_TIMEOUT > 0 + if (m_features.rtc.GetTimestamp() - lastPressTime > 60) { + m_inMenu = false; + ShowWatchFace(true); + break; + } +#endif + delay(10); } } } +#if MENU_TIMEOUT > 0 + if (m_features.rtc.GetTimestamp() - lastPressTime > 60) { + m_inMenu = false; + ShowWatchFace(true); + break; + } +#endif + delay(10); } } else if (buttonMask & UP_BTN_MASK) { diff --git a/src/config.h b/src/config.h index 9340672..f307310 100644 --- a/src/config.h +++ b/src/config.h @@ -40,6 +40,7 @@ #define UPDATE_INTERVAL 60 // seconds #define WAKE_ON_ACCEL_EVENTS false // useful if saving battery by not updating every minute +#define MENU_TIMEOUT 60 // seconds #define WEATHER_UPDATE_INTERVAL 3600 // seconds #define WEATHER_UPDATE_BACKOFF 900 // If weather update fails, how long to wait before trying again