Browse Source

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

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

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

31
         count, duration = workflow["notify"]
31
         count, duration = workflow["notify"]
32
 
32
 
33
         async with self.lock:
33
         async with self.lock:
34
-            self.max = count * 2
34
+            self.max = count * 6
35
 
35
 
36
         for i in range(0, count):
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
             await set_state(device, (None, True))
45
             await set_state(device, (None, True))
39
             async with self.lock:
46
             async with self.lock:
40
                 self.step += 1
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
             await set_state(device, (None, False))
57
             await set_state(device, (None, False))
44
             async with self.lock:
58
             async with self.lock:
45
                 self.step += 1
59
                 self.step += 1

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

26
         while True:
26
         while True:
27
             new = await ble_scan(None, None, 0.25)
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
                     found = False
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
                             found = True
39
                             found = True
35
-                            r = n
40
+                            self.results[i][0] = name
41
+                            self.results[i][2] = rssi
36
                             break
42
                             break
37
-                    if not found:
38
-                        self.results.append(n)
43
+
44
+                    if found == False:
45
+                        self.results.append(value)
39
 
46
 
40
     def draw_list(self):
47
     def draw_list(self):
41
         for i, d in enumerate(self.results):
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
             off = i * 25 + 30
53
             off = i * 25 + 30
46
             if off >= self.lcd.height:
54
             if off >= self.lcd.height:
47
                 break
55
                 break
48
 
56
 
49
             c1 = self.lcd.white
57
             c1 = self.lcd.white
50
-            if s1 == "S&B VOLCANO H":
58
+            if name == "S&B VOLCANO H":
51
                 c1 = self.lcd.green
59
                 c1 = self.lcd.green
52
                 if self.current == None:
60
                 if self.current == None:
53
                     self.current = i
61
                     self.current = i

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

29
             self.current = next
29
             self.current = next
30
             self.states[self.current].enter(val)
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
     states = States(lcd)
33
     states = States(lcd)
38
 
34
 
39
     # 0 - Scan
35
     # 0 - Scan
86
 
82
 
87
     while True:
83
     while True:
88
         states.run()
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
 except Exception as e:
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
     lcd.show()
95
     lcd.show()
96
+    raise e

Loading…
Cancel
Save