From 8ff93f5467b0eef54d18b35d742de05c8a63da9a Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 28 Aug 2023 10:18:02 +1000 Subject: Make idle state more robust + check playback state --- src/system_fsm/idle.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/system_fsm/idle.cpp') 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(); } } void Idle::react(const internal::IdleTimeout& ev) { + if (!IdleCondition()) { + // Defensively ensure that we didn't miss an idle-ending event. + transit(); + 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 -- cgit v1.2.3