diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-09-22 15:48:41 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-09-22 21:19:19 +1000 |
| commit | b192975cb1eeb4e6b7c7bf53cdf42701c55f034a (patch) | |
| tree | 39755851543d596f2630704be9efb56be1f39bfc /src/audio/audio_fsm.cpp | |
| parent | cbd99b2134c6c471708deb409a4b0fcc4c31516d (diff) | |
| download | tangara-fw-b192975cb1eeb4e6b7c7bf53cdf42701c55f034a.tar.gz | |
make bluetooth pairing ui functional
Diffstat (limited to 'src/audio/audio_fsm.cpp')
| -rw-r--r-- | src/audio/audio_fsm.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp index af43c9b9..06b98420 100644 --- a/src/audio/audio_fsm.cpp +++ b/src/audio/audio_fsm.cpp @@ -26,6 +26,7 @@ #include "future_fetcher.hpp" #include "i2s_audio_output.hpp" #include "i2s_dac.hpp" +#include "nvs.hpp" #include "service_locator.hpp" #include "system_events.hpp" #include "track.hpp" @@ -42,6 +43,7 @@ std::shared_ptr<FatfsAudioInput> AudioState::sFileSource; std::unique_ptr<Decoder> AudioState::sDecoder; std::shared_ptr<SampleConverter> AudioState::sSampleConverter; std::shared_ptr<I2SAudioOutput> AudioState::sI2SOutput; +std::shared_ptr<BluetoothAudioOutput> AudioState::sBtOutput; std::shared_ptr<IAudioOutput> AudioState::sOutput; std::optional<database::TrackId> AudioState::sCurrentTrack; @@ -75,6 +77,20 @@ void AudioState::react(const ChangeMaxVolume& ev) { sServices->nvs().AmpMaxVolume(ev.new_max); } +void AudioState::react(const OutputModeChanged& ev) { + // TODO: handle SetInUse + ESP_LOGI(kTag, "output mode changed"); + auto new_mode = sServices->nvs().OutputMode(); + switch (new_mode.get()) { + case drivers::NvsStorage::Output::kBluetooth: + sOutput = sBtOutput; + break; + case drivers::NvsStorage::Output::kHeadphones: + sOutput = sI2SOutput; + break; + } +} + namespace states { void Uninitialised::react(const system_fsm::BootComplete& ev) { @@ -90,13 +106,18 @@ void Uninitialised::react(const system_fsm::BootComplete& ev) { sFileSource.reset(new FatfsAudioInput(sServices->tag_parser())); sI2SOutput.reset(new I2SAudioOutput(sServices->gpios(), std::unique_ptr<drivers::I2SDac>{*dac})); + sBtOutput.reset(new BluetoothAudioOutput(sServices->bluetooth())); auto& nvs = sServices->nvs(); sI2SOutput->SetMaxVolume(nvs.AmpMaxVolume().get()); sI2SOutput->SetVolumeDb(nvs.AmpCurrentVolume().get()); - sOutput = sI2SOutput; - // sOutput.reset(new BluetoothAudioOutput(bluetooth)); + if (sServices->nvs().OutputMode().get() == + drivers::NvsStorage::Output::kHeadphones) { + sOutput = sI2SOutput; + } else { + sOutput = sBtOutput; + } sSampleConverter.reset(new SampleConverter()); sSampleConverter->SetOutput(sOutput); |
