From 92de7dff4f3a4106fa76d0de5ba19dd0875b6be1 Mon Sep 17 00:00:00 2001 From: Michael Mogenson Date: Fri, 21 Oct 2022 13:58:21 -0400 Subject: [PATCH] add 'scan clear' command to console.py Add command to clear scan results and known addresses. Useful for determining if a peripheral has stopped advertising. Also, check if a scan is in progress before connecting. If it is, stop scanning. Some BT controllers will fail to connect while scanning. Testing: Can clear scan results before, during, and after scan. Can clear scan results while disconnected and connected. --- apps/console.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/console.py b/apps/console.py index 77f00b2d..fbe54abd 100644 --- a/apps/console.py +++ b/apps/console.py @@ -151,7 +151,8 @@ class ConsoleApp: return NestedCompleter.from_nested_dict({ 'scan': { 'on': None, - 'off': None + 'off': None, + 'clear': None }, 'advertise': { 'on': None, @@ -472,6 +473,10 @@ class ConsoleApp: self.top_tab = 'scan' elif params[0] == 'off': await self.device.stop_scanning() + elif params[0] == 'clear': + self.device.listener.scan_results.clear() + self.known_addresses.clear() + self.show_scan_results(self.device.listener.scan_results) else: self.show_error('unsupported arguments for scan command') @@ -503,6 +508,9 @@ class ConsoleApp: for phy in phys } + if self.device.is_scanning: + await self.device.stop_scanning() + self.append_to_output('connecting...') try: