summaryrefslogtreecommitdiff
path: root/src/ui/screen_settings.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-11-06 08:19:28 +1100
committerjacqueline <me@jacqueline.id.au>2023-11-06 08:19:28 +1100
commitc6f2b523312320f1ab2f6b2396c507d1e76d4a5b (patch)
treed24c7ee5b77f321b42c5c997b109ed2e7790de27 /src/ui/screen_settings.cpp
parent2dd72320dd83a6f51c0df40d71823f8b310e4843 (diff)
downloadtangara-fw-c6f2b523312320f1ab2f6b2396c507d1e76d4a5b.tar.gz
Improve bt scanning responsiveness
Diffstat (limited to 'src/ui/screen_settings.cpp')
-rw-r--r--src/ui/screen_settings.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/ui/screen_settings.cpp b/src/ui/screen_settings.cpp
index 021b5bfc..a3a24eeb 100644
--- a/src/ui/screen_settings.cpp
+++ b/src/ui/screen_settings.cpp
@@ -119,6 +119,11 @@ static auto select_device_cb(lv_event_t* ev) {
instance->OnDeviceSelected(lv_obj_get_index(ev->target));
}
+static auto remove_preferred_cb(lv_event_t* ev) {
+ Bluetooth* instance = reinterpret_cast<Bluetooth*>(ev->user_data);
+ instance->OnDeviceSelected(-1);
+}
+
Bluetooth::Bluetooth(models::TopBar& bar,
drivers::Bluetooth& bt,
drivers::NvsStorage& nvs)
@@ -141,6 +146,11 @@ Bluetooth::Bluetooth(models::TopBar& bar,
devices_list_ = lv_list_create(content_);
RefreshDevicesList();
+ bt_.SetDeviceDiscovery(true);
+}
+
+Bluetooth::~Bluetooth() {
+ bt_.SetDeviceDiscovery(false);
}
auto Bluetooth::ChangeEnabledState(bool enabled) -> void {
@@ -228,6 +238,11 @@ auto Bluetooth::RemoveAllDevices() -> void {
auto Bluetooth::AddPreferredDevice(const drivers::bluetooth::Device& dev)
-> void {
preferred_device_ = lv_list_add_btn(devices_list_, NULL, dev.name.c_str());
+ lv_obj_t* remove = lv_btn_create(preferred_device_);
+ lv_obj_t* remove_icon = lv_label_create(remove);
+ lv_label_set_text(remove_icon, "x");
+ lv_group_add_obj(group_, remove);
+
macs_in_list_.push_back(dev.address);
}
@@ -238,7 +253,16 @@ auto Bluetooth::AddDevice(const drivers::bluetooth::Device& dev) -> void {
macs_in_list_.push_back(dev.address);
}
-auto Bluetooth::OnDeviceSelected(size_t index) -> void {
+auto Bluetooth::OnDeviceSelected(ssize_t index) -> void {
+ if (index == -1) {
+ events::System().RunOnTask([=]() {
+ nvs_.PreferredBluetoothDevice({});
+ bt_.SetPreferredDevice({});
+ });
+ RefreshDevicesList();
+ return;
+ }
+
// Tell the bluetooth driver that our preference changed.
auto it = macs_in_list_.begin();
std::advance(it, index);