summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-07-12 14:40:54 +1000
committerjacqueline <me@jacqueline.id.au>2024-07-12 14:40:54 +1000
commitf78de39a750d58bfe883a789aa6cc4b0a5d9b9e7 (patch)
treebd7c20afd43745a0648aa36b83f8414f0fe5ba42 /src/drivers
parenta3eb2dd9dc2399ce9c22cd3b07f482f080976440 (diff)
downloadtangara-fw-f78de39a750d58bfe883a789aa6cc4b0a5d9b9e7.tar.gz
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.
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/bluetooth.cpp24
-rw-r--r--src/drivers/include/drivers/nvs.hpp2
-rw-r--r--src/drivers/nvs.cpp2
3 files changed, 16 insertions, 12 deletions
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<Disabled>();
}
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<Idle>();
+ if (sPairedWith_) {
+ connect(*sPairedWith_);
+ }
}
void Connected::react(const events::SourceChanged& ev) {
diff --git a/src/drivers/include/drivers/nvs.hpp b/src/drivers/include/drivers/nvs.hpp
index 2bc77a31..8eb28cc9 100644
--- a/src/drivers/include/drivers/nvs.hpp
+++ b/src/drivers/include/drivers/nvs.hpp
@@ -34,7 +34,7 @@ class Setting {
dirty_ = true;
}
}
- auto get() -> std::optional<T>& { return val_; }
+ auto get() -> std::optional<T> { return val_; }
/* Reads the stored value from NVS and parses it into the correct type. */
auto load(nvs_handle_t) -> std::optional<T>;
diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp
index c4d8dedc..e3c4aa06 100644
--- a/src/drivers/nvs.cpp
+++ b/src/drivers/nvs.cpp
@@ -391,7 +391,7 @@ auto NvsStorage::BluetoothNames() -> std::vector<bluetooth::MacAndName> {
auto NvsStorage::BluetoothName(const bluetooth::mac_addr_t& mac,
std::optional<std::string> name) -> void {
std::lock_guard<std::mutex> lock{mutex_};
- auto& val = bt_names_.get();
+ auto val = bt_names_.get();
if (!val) {
val.emplace();
}