Properly persist bluetooth mode changes

custom
jacqueline 1 year ago
parent 0f03efe868
commit e073309907
  1. 1
      src/audio/audio_fsm.cpp
  2. 31
      src/ui/ui_fsm.cpp

@ -113,7 +113,6 @@ void AudioState::react(const SetVolumeBalance& ev) {
} }
void AudioState::react(const OutputModeChanged& ev) { void AudioState::react(const OutputModeChanged& ev) {
// TODO: handle SetInUse
ESP_LOGI(kTag, "output mode changed"); ESP_LOGI(kTag, "output mode changed");
auto new_mode = sServices->nvs().OutputMode(); auto new_mode = sServices->nvs().OutputMode();
sOutput->SetMode(IAudioOutput::Modes::kOff); sOutput->SetMode(IAudioOutput::Modes::kOff);

@ -77,19 +77,24 @@ lua::Property UiState::sBatteryPct{0};
lua::Property UiState::sBatteryMv{0}; lua::Property UiState::sBatteryMv{0};
lua::Property UiState::sBatteryCharging{false}; lua::Property UiState::sBatteryCharging{false};
lua::Property UiState::sBluetoothEnabled{ lua::Property UiState::sBluetoothEnabled {
false, [](const lua::LuaValue& val) { false, [](const lua::LuaValue& val) {
if (!std::holds_alternative<bool>(val)) { if (!std::holds_alternative<bool>(val)) {
return false; return false;
} }
if (std::get<bool>(val)) { if (std::get<bool>(val)) {
sServices->bluetooth().Enable(); sServices->bluetooth().Enable();
sServices->bluetooth().SetDeviceDiscovery(true); sServices->bluetooth().SetDeviceDiscovery(true);
} else { sServices->nvs().OutputMode(drivers::NvsStorage::Output::kBluetooth);
sServices->bluetooth().Disable(); } else {
} sServices->bluetooth().Disable();
return true; sServices->nvs().OutputMode(drivers::NvsStorage::Output::kHeadphones);
}}; }
events::Audio().Dispatch(audio::OutputModeChanged{});
return true;
}
};
lua::Property UiState::sBluetoothConnected{false}; lua::Property UiState::sBluetoothConnected{false};
lua::Property UiState::sBluetoothPairedDevice{ lua::Property UiState::sBluetoothPairedDevice{
std::monostate{}, [](const lua::LuaValue& val) { std::monostate{}, [](const lua::LuaValue& val) {

Loading…
Cancel
Save