Browse Source

show errors on lcd. update scan result list. notify graph. soft reset at end.

Thomas Buck 11 months ago
parent
commit
98e8cc68c9
4 changed files with 50 additions and 20 deletions
  1. 4
    0
      python-test/state_connect.py
  2. 17
    3
      python-test/state_notify.py
  3. 18
    10
      python-test/state_scan.py
  4. 11
    7
      python-test/states.py

+ 4
- 0
python-test/state_connect.py View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 import uasyncio as asyncio
4 4
 from poll import cache_services_characteristics
5
+import machine
5 6
 
6 7
 class StateConnect:
7 8
     def __init__(self, lcd, state):
@@ -23,6 +24,9 @@ class StateConnect:
23 24
         if self.lock.locked():
24 25
             self.lock.release()
25 26
 
27
+        if self.state == False:
28
+            machine.soft_reset()
29
+
26 30
         return self.client
27 31
 
28 32
     async def progress(self, n):

+ 17
- 3
python-test/state_notify.py View File

@@ -31,15 +31,29 @@ class StateNotify:
31 31
         count, duration = workflow["notify"]
32 32
 
33 33
         async with self.lock:
34
-            self.max = count * 2
34
+            self.max = count * 6
35 35
 
36 36
         for i in range(0, count):
37
-            await asyncio.sleep_ms(int(duration * 1000))
37
+            await asyncio.sleep_ms(int(duration * 500))
38
+            async with self.lock:
39
+                self.step += 1
40
+
41
+            await asyncio.sleep_ms(int(duration * 500))
42
+            async with self.lock:
43
+                self.step += 1
44
+
38 45
             await set_state(device, (None, True))
39 46
             async with self.lock:
40 47
                 self.step += 1
41 48
 
42
-            await asyncio.sleep_ms(int(duration * 1000))
49
+            await asyncio.sleep_ms(int(duration * 500))
50
+            async with self.lock:
51
+                self.step += 1
52
+
53
+            await asyncio.sleep_ms(int(duration * 500))
54
+            async with self.lock:
55
+                self.step += 1
56
+
43 57
             await set_state(device, (None, False))
44 58
             async with self.lock:
45 59
                 self.step += 1

+ 18
- 10
python-test/state_scan.py View File

@@ -26,28 +26,36 @@ class StateScan:
26 26
         while True:
27 27
             new = await ble_scan(None, None, 0.25)
28 28
 
29
-            async with self.lock:
30
-                for n in new:
29
+            for n in new:
30
+                name = n.name()
31
+                mac = n.device.addr_hex()
32
+                rssi = n.rssi
33
+                value = [name, mac, rssi]
34
+
35
+                async with self.lock:
31 36
                     found = False
32
-                    for r in self.results:
33
-                        if r.device.addr_hex() == n.device.addr_hex():
37
+                    for i in range(0, len(self.results)):
38
+                        if self.results[i][1] == mac:
34 39
                             found = True
35
-                            r = n
40
+                            self.results[i][0] = name
41
+                            self.results[i][2] = rssi
36 42
                             break
37
-                    if not found:
38
-                        self.results.append(n)
43
+
44
+                    if found == False:
45
+                        self.results.append(value)
39 46
 
40 47
     def draw_list(self):
41 48
         for i, d in enumerate(self.results):
42
-            s1 = "{}".format(d.name())
43
-            s2 = "{}: [{}] {}".format(i + 1, d.device.addr_hex(), d.rssi)
49
+            name, mac, rssi = self.results[i]
50
+            s1 = "{}: {}".format(i + 1, name)
51
+            s2 = "[{}] {}".format(mac, rssi)
44 52
 
45 53
             off = i * 25 + 30
46 54
             if off >= self.lcd.height:
47 55
                 break
48 56
 
49 57
             c1 = self.lcd.white
50
-            if s1 == "S&B VOLCANO H":
58
+            if name == "S&B VOLCANO H":
51 59
                 c1 = self.lcd.green
52 60
                 if self.current == None:
53 61
                     self.current = i

+ 11
- 7
python-test/states.py View File

@@ -29,11 +29,7 @@ class States:
29 29
             self.current = next
30 30
             self.states[self.current].enter(val)
31 31
 
32
-from lcd import LCD
33
-lcd = LCD()
34
-lcd.brightness(1.0)
35
-
36
-try:
32
+def state_machine(lcd):
37 33
     states = States(lcd)
38 34
 
39 35
     # 0 - Scan
@@ -86,7 +82,15 @@ try:
86 82
 
87 83
     while True:
88 84
         states.run()
85
+
86
+from lcd import LCD
87
+lcd = LCD()
88
+lcd.brightness(1.0)
89
+
90
+try:
91
+    state_machine(lcd)
89 92
 except Exception as e:
90
-    lcd.fill(self.lcd.black)
91
-    lcd.text(str(e), 0, int(lcd.height / 2) - 5, lcd.white)
93
+    lcd.fill(lcd.black)
94
+    lcd.textC(str(e), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
92 95
     lcd.show()
96
+    raise e

Loading…
Cancel
Save