From 99c56641e9ee531a0553ff19422009dd667a3add Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 6 Feb 2024 12:38:11 +1100 Subject: fix various of bluetooth issues connecting and disconnecting is a bit more consistent now! --- src/ui/ui_fsm.cpp | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/ui/ui_fsm.cpp') diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index b3546d55..55c8c84b 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -77,30 +77,33 @@ lua::Property UiState::sBatteryPct{0}; lua::Property UiState::sBatteryMv{0}; lua::Property UiState::sBatteryCharging{false}; -lua::Property UiState::sBluetoothEnabled { - false, [](const lua::LuaValue& val) { - if (!std::holds_alternative(val)) { - return false; - } - if (std::get(val)) { - sServices->bluetooth().Enable(); - sServices->bluetooth().SetDeviceDiscovery(true); - sServices->nvs().OutputMode(drivers::NvsStorage::Output::kBluetooth); - } else { - sServices->bluetooth().Disable(); - sServices->nvs().OutputMode(drivers::NvsStorage::Output::kHeadphones); - } - events::Audio().Dispatch(audio::OutputModeChanged{}); - return true; - } -}; +lua::Property UiState::sBluetoothEnabled{ + false, [](const lua::LuaValue& val) { + if (!std::holds_alternative(val)) { + return false; + } + if (std::get(val)) { + sServices->nvs().OutputMode(drivers::NvsStorage::Output::kBluetooth); + sServices->bluetooth().Enable(); + sServices->bluetooth().SetDeviceDiscovery(true); + } else { + sServices->nvs().OutputMode(drivers::NvsStorage::Output::kHeadphones); + sServices->bluetooth().Disable(); + } + events::Audio().Dispatch(audio::OutputModeChanged{}); + return true; + }}; lua::Property UiState::sBluetoothConnected{false}; lua::Property UiState::sBluetoothPairedDevice{ std::monostate{}, [](const lua::LuaValue& val) { if (std::holds_alternative(val)) { auto dev = std::get(val); - sServices->bluetooth().SetPreferredDevice(dev.address); + sServices->bluetooth().SetPreferredDevice( + drivers::bluetooth::MacAndName{ + .mac = dev.address, + .name = {dev.name.data(), dev.name.size()}, + }); } return false; }}; -- cgit v1.2.3