Finetuned the bluetooth scan function for various MicroPython boards. eric7

Tue, 16 May 2023 14:36:05 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 16 May 2023 14:36:05 +0200
branch
eric7
changeset 10032
102b79b2a8cd
parent 10031
6d4b46787f30
child 10033
91b0939626ff

Finetuned the bluetooth scan function for various MicroPython boards.

src/eric7/MicroPython/Devices/CircuitPythonDevices.py file | annotate | diff | comparison | revisions
src/eric7/MicroPython/Devices/EspDevices.py file | annotate | diff | comparison | revisions
src/eric7/MicroPython/Devices/MicrobitDevices.py file | annotate | diff | comparison | revisions
--- a/src/eric7/MicroPython/Devices/CircuitPythonDevices.py	Tue May 16 12:00:00 2023 +0200
+++ b/src/eric7/MicroPython/Devices/CircuitPythonDevices.py	Tue May 16 14:36:05 2023 +0200
@@ -1756,7 +1756,7 @@
     scanResults = a.start_scan(
         buffer_size=1024, extended=True, timeout={0}, minimum_rssi=-120, active=True
     )
-    time.sleep({0})
+    time.sleep({0} + 0.2)
     a.stop_scan()
 
     for res in scanResults:
--- a/src/eric7/MicroPython/Devices/EspDevices.py	Tue May 16 12:00:00 2023 +0200
+++ b/src/eric7/MicroPython/Devices/EspDevices.py	Tue May 16 14:36:05 2023 +0200
@@ -1374,6 +1374,8 @@
             return self.__cpyDevice.getDeviceScan(timeout)
 
         command = """
+_scan_done = False
+
 def ble_scan():
     import bluetooth
     import time
@@ -1383,6 +1385,7 @@
     IRQ_SCAN_DONE = 6
 
     def _bleIrq(event, data):
+        global _scan_done
         if event == IRQ_SCAN_RESULT:
             addr_type, addr, adv_type, rssi, adv_data = data
             if addr:
@@ -1392,6 +1395,8 @@
                     'adv_type': adv_type,
                     'advertisement': bytes(adv_data),
                 }})
+        elif event == IRQ_SCAN_DONE:
+            _scan_done = True
 
     ble = bluetooth.BLE()
 
@@ -1401,13 +1406,14 @@
 
     ble.irq(_bleIrq)
     ble.gap_scan({0} * 1000, 1000000, 50000, True)
-    time.sleep({0})
+    while not _scan_done:
+        time.sleep(0.2)
 
     if not ble_active:
         ble.active(False)
 
 ble_scan()
-del ble_scan
+del ble_scan, _scan_done
 """.format(
             timeout
         )
--- a/src/eric7/MicroPython/Devices/MicrobitDevices.py	Tue May 16 12:00:00 2023 +0200
+++ b/src/eric7/MicroPython/Devices/MicrobitDevices.py	Tue May 16 14:36:05 2023 +0200
@@ -915,7 +915,7 @@
     scanResults = a.start_scan(
         buffer_size=1024, extended=True, timeout={0}, minimum_rssi=-120, active=True
     )
-    time.sleep({0})
+    time.sleep({0} + 0.2)
     a.stop_scan()
 
     for res in scanResults:

eric ide

mercurial