Add timeout to menu so you don't accidentally drain your battery by entering the menu before going to sleep.

This commit is contained in:
leblane 2023-06-16 16:59:01 +03:00
parent 93d7bde7dc
commit 39a2432410
2 changed files with 20 additions and 0 deletions

View file

@ -45,9 +45,11 @@ void WatchFace::HandleButtonPress(uint64_t buttonMask)
const std::vector<int> 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) {

View file

@ -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