diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-04-09 11:44:20 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-04-09 11:44:20 +1000 |
| commit | e5c6ffdb8b3f1a1a725b387283fdf14f463a8a44 (patch) | |
| tree | 4fd853f36abf8bc46c5d4e4601d3bff52095f60f /src/system_fsm | |
| parent | f93e3c1c69f90fcb963840f8b3a9592c35bd096b (diff) | |
| download | tangara-fw-e5c6ffdb8b3f1a1a725b387283fdf14f463a8a44.tar.gz | |
Unmount storage when there's a bad error
Diffstat (limited to 'src/system_fsm')
| -rw-r--r-- | src/system_fsm/include/system_events.hpp | 5 | ||||
| -rw-r--r-- | src/system_fsm/include/system_fsm.hpp | 1 | ||||
| -rw-r--r-- | src/system_fsm/running.cpp | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/src/system_fsm/include/system_events.hpp b/src/system_fsm/include/system_events.hpp index f9ab9e11..22e3b6bd 100644 --- a/src/system_fsm/include/system_events.hpp +++ b/src/system_fsm/include/system_events.hpp @@ -11,6 +11,7 @@ #include "battery.hpp" #include "bluetooth_types.hpp" #include "database.hpp" +#include "ff.h" #include "haptics.hpp" #include "samd.hpp" #include "service_locator.hpp" @@ -42,7 +43,9 @@ struct OnIdle : tinyfsm::Event {}; */ struct StorageMounted : tinyfsm::Event {}; -struct StorageError : tinyfsm::Event {}; +struct StorageError : tinyfsm::Event { + FRESULT error; +}; struct KeyLockChanged : tinyfsm::Event { bool locking; diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp index a129829e..e0a0ac7a 100644 --- a/src/system_fsm/include/system_fsm.hpp +++ b/src/system_fsm/include/system_fsm.hpp @@ -105,6 +105,7 @@ class Running : public SystemState { void react(const database::event::UpdateFinished&) override; void react(const SamdUsbMscChanged&) override; void react(const internal::UnmountTimeout&) override; + void react(const StorageError&) override; using SystemState::react; diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp index 8625ac66..796c96dc 100644 --- a/src/system_fsm/running.cpp +++ b/src/system_fsm/running.cpp @@ -8,6 +8,7 @@ #include "audio_events.hpp" #include "database.hpp" #include "db_events.hpp" +#include "ff.h" #include "file_gatherer.hpp" #include "freertos/portmacro.h" #include "freertos/projdefs.h" @@ -119,6 +120,13 @@ void Running::react(const SamdUsbMscChanged& ev) { } } +void Running::react(const StorageError& ev) { + ESP_LOGE(kTag, "storage error %u", ev.error); + if (ev.error == FR_DISK_ERR || ev.error == FR_INVALID_OBJECT) { + unmountStorage(); + } +} + auto Running::checkIdle() -> void { xTimerStop(sUnmountTimer, portMAX_DELAY); if (IdleCondition()) { |
