From f78de39a750d58bfe883a789aa6cc4b0a5d9b9e7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 12 Jul 2024 14:40:54 +1000 Subject: Give Bluetooth settings a bit of a refresh It's now a bit more responsive to stuff happening, gives you more information, and remembers your previously paired devices for faster switching between them. --- src/drivers/bluetooth.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/drivers/bluetooth.cpp') diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp index 2edf5ad9..a0a318e9 100644 --- a/src/drivers/bluetooth.cpp +++ b/src/drivers/bluetooth.cpp @@ -603,16 +603,21 @@ void Disabled::react(const events::Enable&) { void Idle::entry() { ESP_LOGI(kTag, "bt is idle"); + std::invoke(sEventHandler_, SimpleEvent::kConnectionStateChanged); } -void Idle::exit() {} +void Idle::exit() { + std::invoke(sEventHandler_, SimpleEvent::kConnectionStateChanged); +} void Idle::react(const events::Disable& ev) { transit(); } void Idle::react(const events::PairedDeviceChanged& ev) { - connect(*sPairedWith_); + if (sPairedWith_) { + connect(*sPairedWith_); + } } void Idle::react(events::internal::Gap ev) { @@ -633,18 +638,10 @@ void Connecting::entry() { sTimeoutTimer = xTimerCreate("bt_timeout", pdMS_TO_TICKS(15000), false, NULL, timeoutCallback); xTimerStart(sTimeoutTimer, portMAX_DELAY); - - if (sEventHandler_) { - std::invoke(sEventHandler_, SimpleEvent::kConnectionStateChanged); - } } void Connecting::exit() { xTimerDelete(sTimeoutTimer, portMAX_DELAY); - - if (sEventHandler_) { - std::invoke(sEventHandler_, SimpleEvent::kConnectionStateChanged); - } } void Connecting::react(const events::ConnectTimedOut& ev) { @@ -751,12 +748,16 @@ void Connected::entry() { sStorage_->PreferredBluetoothDevice(sPairedWith_); } + std::invoke(sEventHandler_, SimpleEvent::kConnectionStateChanged); + // TODO: if we already have a source, immediately start playing } void Connected::exit() { ESP_LOGI(kTag, "exiting connected state"); esp_a2d_source_disconnect(connected_to_.data()); + + std::invoke(sEventHandler_, SimpleEvent::kConnectionStateChanged); } void Connected::react(const events::Disable& ev) { @@ -765,6 +766,9 @@ void Connected::react(const events::Disable& ev) { void Connected::react(const events::PairedDeviceChanged& ev) { transit(); + if (sPairedWith_) { + connect(*sPairedWith_); + } } void Connected::react(const events::SourceChanged& ev) { -- cgit v1.2.3