From 7523772886ca37cf05d0ad5b24f6d520e314242e Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 16 Oct 2023 13:52:43 +1100 Subject: Decouple play/pause from output on/off I think this was the cause of toggling play/pause making audio go away. Or at least I can't repro that bug anymore, anyway. --- src/audio/audio_fsm.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/audio/audio_fsm.cpp') diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp index e470300f..5020a6ef 100644 --- a/src/audio/audio_fsm.cpp +++ b/src/audio/audio_fsm.cpp @@ -81,6 +81,7 @@ void AudioState::react(const OutputModeChanged& ev) { // TODO: handle SetInUse ESP_LOGI(kTag, "output mode changed"); auto new_mode = sServices->nvs().OutputMode(); + sOutput->SetMode(IAudioOutput::Modes::kOff); switch (new_mode) { case drivers::NvsStorage::Output::kBluetooth: sOutput = sBtOutput; @@ -89,6 +90,7 @@ void AudioState::react(const OutputModeChanged& ev) { sOutput = sI2SOutput; break; } + sOutput->SetMode(IAudioOutput::Modes::kOnPaused); } namespace states { @@ -125,6 +127,7 @@ void Uninitialised::react(const system_fsm::BootComplete& ev) { } else { sOutput = sBtOutput; } + sOutput->SetMode(IAudioOutput::Modes::kOnPaused); sSampleConverter.reset(new SampleConverter()); sSampleConverter->SetOutput(sOutput); @@ -170,7 +173,7 @@ void Standby::react(const TogglePlayPause& ev) { void Playback::entry() { ESP_LOGI(kTag, "beginning playback"); - sOutput->SetInUse(true); + sOutput->SetMode(IAudioOutput::Modes::kOnPlaying); events::System().Dispatch(PlaybackStarted{}); events::Ui().Dispatch(PlaybackStarted{}); @@ -181,7 +184,7 @@ void Playback::exit() { // TODO(jacqueline): Second case where it's useful to wait for the i2s buffer // to drain. vTaskDelay(pdMS_TO_TICKS(10)); - sOutput->SetInUse(false); + sOutput->SetMode(IAudioOutput::Modes::kOnPaused); events::System().Dispatch(PlaybackFinished{}); events::Ui().Dispatch(PlaybackFinished{}); -- cgit v1.2.3