From 8de07fe8fac23d508ae64dfd6ffb332f568f4e45 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 6 Jun 2024 04:52:00 +0000 Subject: daniel/bluetooth-avrc (#80) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Have a squizzy and lemme know if any issues @cooljqln 🐝 Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/80 Co-authored-by: ailurux Co-committed-by: ailurux --- src/tangara/audio/audio_fsm.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/tangara/audio/audio_fsm.cpp') diff --git a/src/tangara/audio/audio_fsm.cpp b/src/tangara/audio/audio_fsm.cpp index d6ddff8d..80611082 100644 --- a/src/tangara/audio/audio_fsm.cpp +++ b/src/tangara/audio/audio_fsm.cpp @@ -217,18 +217,32 @@ void AudioState::react(const internal::StreamEnded& ev) { } void AudioState::react(const system_fsm::BluetoothEvent& ev) { - if (ev.event != drivers::bluetooth::Event::kConnectionStateChanged) { - return; + using drivers::bluetooth::SimpleEvent; + if (std::holds_alternative(ev.event)) { + auto simpleEvent = std::get(ev.event); + switch (simpleEvent) { + case SimpleEvent::kConnectionStateChanged: { + auto dev = sServices->bluetooth().ConnectedDevice(); + if (!dev) { + return; + } + sBtOutput->SetVolume(sServices->nvs().BluetoothVolume(dev->mac)); + events::Ui().Dispatch(VolumeChanged{ + .percent = sOutput->GetVolumePct(), + .db = sOutput->GetVolumeDb(), + }); + break; + } + default: + break; + } } - auto dev = sServices->bluetooth().ConnectedDevice(); - if (!dev) { - return; + if (std::holds_alternative(ev.event)) { + auto volume_chg = std::get(ev.event).new_vol; + events::Ui().Dispatch(RemoteVolumeChanged{ + .value = volume_chg + }); } - sBtOutput->SetVolume(sServices->nvs().BluetoothVolume(dev->mac)); - events::Ui().Dispatch(VolumeChanged{ - .percent = sOutput->GetVolumePct(), - .db = sOutput->GetVolumeDb(), - }); } void AudioState::react(const StepUpVolume& ev) { -- cgit v1.2.3