diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/drivers/bluetooth.cpp | 6 | ||||
| -rw-r--r-- | src/drivers/include/drivers/bluetooth.hpp | 2 | ||||
| -rw-r--r-- | src/tangara/app_console/app_console.cpp | 30 | ||||
| -rw-r--r-- | src/tangara/ui/lvgl_task.cpp | 2 |
4 files changed, 39 insertions, 1 deletions
diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp index 3697b33d..4e17011a 100644 --- a/src/drivers/bluetooth.cpp +++ b/src/drivers/bluetooth.cpp @@ -188,6 +188,8 @@ auto Bluetooth::knownDevices() -> std::vector<bluetooth::MacAndName> { auto Bluetooth::forgetKnownDevice(const bluetooth::mac_addr_t& mac) -> void { nvs_.BluetoothName(mac, {}); + std::invoke(bluetooth::BluetoothState::eventHandler(), + bluetooth::SimpleEvent::kKnownDevicesChanged); } auto Bluetooth::discoveryEnabled(bool en) -> void { @@ -427,6 +429,10 @@ auto BluetoothState::pairedDevice(std::optional<MacAndName> dev) -> void { bluetooth::events::PairedDeviceChanged{}); } +auto BluetoothState::eventHandler() -> std::function<void(Event)>& { + return sEventHandler_; +} + auto BluetoothState::discovery() -> bool { return sScanner_->enabled(); } diff --git a/src/drivers/include/drivers/bluetooth.hpp b/src/drivers/include/drivers/bluetooth.hpp index b333bd15..7ee49e2a 100644 --- a/src/drivers/include/drivers/bluetooth.hpp +++ b/src/drivers/include/drivers/bluetooth.hpp @@ -162,6 +162,8 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> { static auto pairedDevice() -> std::optional<bluetooth::MacAndName>; static auto pairedDevice(std::optional<bluetooth::MacAndName>) -> void; + static auto eventHandler() -> std::function<void(Event)>&; + static auto discovery() -> bool; static auto discovery(bool) -> void; static auto discoveredDevices() -> std::vector<Device>; diff --git a/src/tangara/app_console/app_console.cpp b/src/tangara/app_console/app_console.cpp index 2a8f290b..8a3df7c3 100644 --- a/src/tangara/app_console/app_console.cpp +++ b/src/tangara/app_console/app_console.cpp @@ -479,6 +479,35 @@ void RegisterBtList() { esp_console_cmd_register(&cmd); } +int CmdBtForget(int argc, char** argv) { + static const std::pmr::string usage = "usage: bt_forget <index>"; + if (argc != 2) { + std::cout << usage << std::endl; + return 1; + } + + auto devices = AppConsole::sServices->bluetooth().knownDevices(); + int index = std::atoi(argv[1]); + if (index < 0 || index >= devices.size()) { + std::cout << "index out of range" << std::endl; + return -1; + } + + AppConsole::sServices->bluetooth().forgetKnownDevice(devices[index].mac); + std::cout << "Device '" << devices[index].name << "' forgotten" << std::endl; + return 0; +} + +void RegisterBtForget() { + esp_console_cmd_t cmd{ + .command = "bt_forget", + .help = "removes a bluetooth device from known devices list", + .hint = "index", + .func = &CmdBtForget, + .argtable = NULL}; + esp_console_cmd_register(&cmd); +} + int CmdSamd(int argc, char** argv) { static const std::pmr::string usage = "usage: samd [flash|charge|off]"; if (argc != 2) { @@ -739,6 +768,7 @@ auto AppConsole::RegisterExtraComponents() -> void { #endif RegisterBtList(); + RegisterBtForget(); RegisterSamd(); RegisterCoreDump(); diff --git a/src/tangara/ui/lvgl_task.cpp b/src/tangara/ui/lvgl_task.cpp index 287f6b7e..b55e434b 100644 --- a/src/tangara/ui/lvgl_task.cpp +++ b/src/tangara/ui/lvgl_task.cpp @@ -63,7 +63,7 @@ auto UiTask::Main() -> void { } TickType_t delay = lv_timer_handler(); - vTaskDelay(pdMS_TO_TICKS(std::clamp<TickType_t>(delay, 0, 100))); + vTaskDelay(pdMS_TO_TICKS(std::clamp<TickType_t>(delay, 16, 100))); } } |
