From 9fdf94e9cee5a5180ffefc2b8314f7a9879ebbc6 Mon Sep 17 00:00:00 2001 From: ayumi Date: Sat, 15 Feb 2025 02:25:27 +0100 Subject: Allow manually unmounting the SD card --- src/tangara/audio/audio_events.hpp | 4 ++++ src/tangara/audio/audio_fsm.cpp | 7 +++---- src/tangara/audio/audio_fsm.hpp | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/tangara/audio') diff --git a/src/tangara/audio/audio_events.hpp b/src/tangara/audio/audio_events.hpp index 89dc28ff..24a5cf83 100644 --- a/src/tangara/audio/audio_events.hpp +++ b/src/tangara/audio/audio_events.hpp @@ -150,6 +150,10 @@ struct TtsPlaybackChanged : tinyfsm::Event { bool is_playing; }; +struct UnmountReady : tinyfsm::Event { + bool idle; +}; + namespace internal { struct DecodingStarted : tinyfsm::Event { std::shared_ptr track; diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp index 7854818d..27c29eee 100644 --- a/src/tangara/audio/audio_fsm.cpp +++ b/src/tangara/audio/audio_fsm.cpp @@ -534,10 +534,7 @@ auto Standby::entry() -> void { updateOutputMode(); } -void Standby::react(const system_fsm::KeyLockChanged& ev) { - if (!ev.locking) { - return; - } +void Standby::react(const system_fsm::UnmountRequest& ev) { auto current = sStreamCues.current(); sServices->bg_worker().Dispatch([=]() { auto db = sServices->database().lock(); @@ -548,6 +545,7 @@ void Standby::react(const system_fsm::KeyLockChanged& ev) { if (queue.totalSize() <= queue.currentPosition()) { // Nothing is playing, so don't bother saving the queue. db->put(kQueueKey, ""); + events::System().Dispatch(UnmountReady{.idle = ev.idle}); return; } db->put(kQueueKey, queue.serialise()); @@ -562,6 +560,7 @@ void Standby::react(const system_fsm::KeyLockChanged& ev) { }; db->put(kCurrentFileKey, current_track.toString()); } + events::System().Dispatch(UnmountReady{.idle = ev.idle}); }); } diff --git a/src/tangara/audio/audio_fsm.hpp b/src/tangara/audio/audio_fsm.hpp index fb42e387..c30012d9 100644 --- a/src/tangara/audio/audio_fsm.hpp +++ b/src/tangara/audio/audio_fsm.hpp @@ -65,7 +65,7 @@ class AudioState : public tinyfsm::Fsm { void react(const OutputModeChanged&); virtual void react(const system_fsm::BootComplete&) {} - virtual void react(const system_fsm::KeyLockChanged&){}; + virtual void react(const system_fsm::UnmountRequest&) {} virtual void react(const system_fsm::SdStateChanged&) {} virtual void react(const system_fsm::BluetoothEvent&); virtual void react(const system_fsm::HasPhonesChanged&); @@ -114,7 +114,7 @@ class Uninitialised : public AudioState { class Standby : public AudioState { public: void entry() override; - void react(const system_fsm::KeyLockChanged&) override; + void react(const system_fsm::UnmountRequest&) override; void react(const system_fsm::SdStateChanged&) override; using AudioState::react; -- cgit v1.2.3