summaryrefslogtreecommitdiff
path: root/src/system_fsm/idle.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-28 10:18:02 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-28 10:18:02 +1000
commit8ff93f5467b0eef54d18b35d742de05c8a63da9a (patch)
treeca0215b64d1a779a69c30b71f8d7870f5aa3dbcb /src/system_fsm/idle.cpp
parent0f5cf25e73fb2e789b472317966ff80323dddd75 (diff)
downloadtangara-fw-8ff93f5467b0eef54d18b35d742de05c8a63da9a.tar.gz
Make idle state more robust + check playback state
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