summaryrefslogtreecommitdiff
path: root/src/system_fsm/idle.cpp
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2023-08-28 14:59:52 +1000
committerailurux <ailuruxx@gmail.com>2023-08-28 14:59:52 +1000
commitdb601935c6145445467692c0a4ff2b81e27cf6ce (patch)
treee2eed4a38abd03f14dba504ce5e8dedee0da6a12 /src/system_fsm/idle.cpp
parent6f4ace1dd4b9b34f95af1ba365b68624e209d147 (diff)
parent3a0c42f9240eedfbc6a1e94ad3a59c52664fb5b5 (diff)
downloadtangara-fw-db601935c6145445467692c0a4ff2b81e27cf6ce.tar.gz
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
Diffstat (limited to 'src/system_fsm/idle.cpp')
-rw-r--r--src/system_fsm/idle.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/system_fsm/idle.cpp b/src/system_fsm/idle.cpp
index 91075fc6..7cc1fa39 100644
--- a/src/system_fsm/idle.cpp
+++ b/src/system_fsm/idle.cpp
@@ -49,12 +49,17 @@ void Idle::exit() {
}
void Idle::react(const KeyLockChanged& ev) {
- if (!ev.falling) {
+ if (ev.falling) {
transit<Running>();
}
}
void Idle::react(const internal::IdleTimeout& ev) {
+ if (!IdleCondition()) {
+ // Defensively ensure that we didn't miss an idle-ending event.
+ transit<Running>();
+ return;
+ }
ESP_LOGI(kTag, "system shutting down");
// FIXME: It would be neater to just free a bunch of our pointers, deinit the
@@ -79,7 +84,12 @@ void Idle::react(const internal::IdleTimeout& ev) {
sGpios->Flush();
- sSamd->PowerDown();
+ // Retry shutting down in case of a transient failure with the SAMD. e.g. i2c
+ // timeouts. This guards against a buggy SAMD firmware preventing idle.
+ for (;;) {
+ sSamd->PowerDown();
+ vTaskDelay(pdMS_TO_TICKS(1000));
+ }
}
} // namespace states