From eacea59e8a3f9602ed06834a8edc4e6ab18a4bb9 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 30 Jan 2024 11:03:31 +1100 Subject: Do more to avoid and recover from partial db updates - do not power off in an update is in progress - explicitly store last update time, rather than deriving it from unchanged tracks. --- src/system_fsm/include/system_fsm.hpp | 3 +++ src/system_fsm/running.cpp | 7 +++++++ src/system_fsm/system_fsm.cpp | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp index 2db1cddc..1e340711 100644 --- a/src/system_fsm/include/system_fsm.hpp +++ b/src/system_fsm/include/system_fsm.hpp @@ -13,6 +13,7 @@ #include "battery.hpp" #include "bluetooth.hpp" #include "database.hpp" +#include "db_events.hpp" #include "display.hpp" #include "gpios.hpp" #include "nvs.hpp" @@ -60,6 +61,7 @@ class SystemState : public tinyfsm::Fsm { virtual void react(const StorageError&) {} virtual void react(const KeyLockChanged&) {} virtual void react(const SdDetectChanged&) {} + virtual void react(const database::event::UpdateFinished&) {} virtual void react(const audio::PlaybackFinished&) {} virtual void react(const internal::IdleTimeout&) {} @@ -98,6 +100,7 @@ class Running : public SystemState { void react(const KeyLockChanged&) override; void react(const SdDetectChanged&) override; void react(const audio::PlaybackFinished&) override; + void react(const database::event::UpdateFinished&) override; using SystemState::react; diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp index 9e10f9ec..ec448657 100644 --- a/src/system_fsm/running.cpp +++ b/src/system_fsm/running.cpp @@ -7,6 +7,7 @@ #include "app_console.hpp" #include "audio_events.hpp" #include "database.hpp" +#include "db_events.hpp" #include "file_gatherer.hpp" #include "freertos/projdefs.h" #include "result.hpp" @@ -47,6 +48,12 @@ void Running::react(const audio::PlaybackFinished& ev) { } } +void Running::react(const database::event::UpdateFinished&) { + if (IdleCondition()) { + transit(); + } +} + void Running::react(const SdDetectChanged& ev) { if (ev.has_sd_card) { if (!sStorage && mountStorage()) { diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp index df750e80..977f4a6d 100644 --- a/src/system_fsm/system_fsm.cpp +++ b/src/system_fsm/system_fsm.cpp @@ -95,7 +95,8 @@ void SystemState::react(const internal::SamdInterrupt&) { } auto SystemState::IdleCondition() -> bool { - return sServices->gpios().IsLocked() && + auto db = sServices->database().lock(); + return sServices->gpios().IsLocked() && !(db && db->isUpdating()) && audio::AudioState::is_in_state(); } -- cgit v1.2.3