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