From 22a44e48bc12ad39916017f0d54b85c981fb7c41 Mon Sep 17 00:00:00 2001 From: Wesley Ellis Date: Fri, 28 Feb 2025 11:42:23 -0500 Subject: [PATCH] add bt_forget console command --- src/tangara/app_console/app_console.cpp | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 "; + 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();