Browse Source

remove unneeded stuff

Thomas Buck 1 year ago
parent
commit
34b99d09db

+ 0
- 2
python-test/copy.sh View File

@@ -2,7 +2,6 @@
2 2
 
3 3
 if [ $# -ne 0 ] ; then
4 4
 cat << EOF | rshell
5
-cp flow.py /pyboard
6 5
 cp poll.py /pyboard
7 6
 cp scan.py /pyboard
8 7
 cp lcd.py /pyboard
@@ -20,7 +19,6 @@ cp $1 /pyboard/main.py
20 19
 EOF
21 20
 else
22 21
 cat << EOF | rshell
23
-cp flow.py /pyboard
24 22
 cp poll.py /pyboard
25 23
 cp scan.py /pyboard
26 24
 cp lcd.py /pyboard

+ 0
- 119
python-test/flow.py View File

@@ -1,119 +0,0 @@
1
-#!/usr/bin/env python
2
-
3
-import uasyncio as asyncio
4
-import sys
5
-import time
6
-
7
-from poll import (
8
-    ble_conn,
9
-    get_current_temp,
10
-    get_target_temp, set_target_temp,
11
-    get_unit_is_fahrenheit,
12
-    get_state, set_state
13
-)
14
-
15
-terminal_width = 100 #os.get_terminal_size().columns - 15
16
-
17
-def print_bar(value, start, end, unit):
18
-    width = terminal_width
19
-    s = "\r"
20
-    s += "#" * int((value - start) / (end - start) * width)
21
-    s += "-" * (width - int((value - start) / (end - start) * width))
22
-    s += " {}{}".format(value, unit)
23
-    print(s, end="")
24
-
25
-def sleep(t):
26
-    print_bar(0, 0, t, "s")
27
-    for i in range(0, t):
28
-        time.sleep(1.0)
29
-        print_bar(i + 1, 0, t, "s")
30
-    print()
31
-
32
-async def wait_for_temp(client, temp):
33
-    print("Setting temperature {}".format(temp))
34
-    await set_target_temp(client, temp)
35
-
36
-    print("Waiting for temperature to rise...")
37
-    start = await get_current_temp(client)
38
-    curr = start
39
-    print_bar(curr, start, temp, " degC")
40
-    while curr < temp:
41
-        time.sleep(1.0)
42
-        curr = await get_current_temp(client)
43
-        print_bar(curr, start, temp, " degC")
44
-    print()
45
-
46
-    print("Reached temperature {}".format(temp))
47
-
48
-async def flow_step(client, temp, t_wait, t_pump):
49
-    await wait_for_temp(client, temp)
50
-
51
-    print("Waiting {}s for heat to settle...".format(t_wait))
52
-    sleep(t_wait)
53
-
54
-    print("Pumping for {}s".format(t_pump))
55
-    await set_state(client, (True, True)) # turn on pump
56
-    sleep(t_pump)
57
-    await set_state(client, (True, False)) # turn off pump
58
-
59
-async def flow(client):
60
-    print("Turning on heater")
61
-    await set_state(client, (True, False))
62
-
63
-    await flow_step(client, 190.0, 15.0, 5.0 - 4)
64
-    await flow_step(client, 205.0, 10.0, 20.0 - 4)
65
-    await flow_step(client, 220.0, 10.0, 20.0 - 4)
66
-
67
-    print("Notification by pumping three times...")
68
-    for i in range(0, 3):
69
-        #time.sleep(1.0 / 3)
70
-        await set_state(client, (True, True)) # turn on pump
71
-        #time.sleep(1.0 / 3)
72
-        await set_state(client, (True, False)) # turn off pump
73
-
74
-    print("Turning heater off")
75
-    await set_state(client, (False, False)) # turn off heater and pump
76
-
77
-    print("Setting temperature back to 190")
78
-    await set_target_temp(client, 190.0)
79
-
80
-if __name__ == "__main__":
81
-    async def main(address):
82
-        client = await ble_conn(address)
83
-
84
-        try:
85
-            if await get_unit_is_fahrenheit(client):
86
-                raise RuntimeError("Imperial American scum is currently not supported :P")
87
-
88
-            print("Starting Workflow")
89
-            await flow(client)
90
-        except:
91
-            print("\nTurning heater off")
92
-            await set_state(client, (False, False)) # turn off heater and pump
93
-            raise
94
-
95
-    import machine
96
-    led_onboard = machine.Pin("LED", machine.Pin.OUT)
97
-
98
-    for i in range(0, 3):
99
-        led_onboard.on()
100
-        time.sleep(0.2)
101
-        led_onboard.off()
102
-        time.sleep(0.2)
103
-
104
-    print("ready")
105
-    while True:
106
-        if rp2.bootsel_button() == 1:
107
-            led_onboard.on()
108
-            print("run")
109
-
110
-            try:
111
-                asyncio.run(main(None))
112
-                print("done")
113
-            except Exception as e:
114
-                print(e)
115
-
116
-            led_onboard.off()
117
-            machine.reset()
118
-
119
-        time.sleep(0.2)

+ 16
- 109
python-test/lcd.py View File

@@ -8,6 +8,7 @@ import framebuf
8 8
 import time
9 9
 import os
10 10
 import math
11
+import gc
11 12
 
12 13
 class KeyCheck:
13 14
     def __init__(self, new, old):
@@ -34,6 +35,7 @@ class LCD(framebuf.FrameBuffer):
34 35
         self.dc = Pin(8, Pin.OUT)
35 36
         self.dc(1)
36 37
 
38
+        gc.collect()
37 39
         self.buffer = bytearray(self.height * self.width * 2)
38 40
 
39 41
         super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
@@ -112,45 +114,33 @@ class LCD(framebuf.FrameBuffer):
112 114
         self.rst(1)
113 115
         self.rst(0)
114 116
         self.rst(1)
115
-
116 117
         self.write_cmd(0x36)
117 118
         self.write_data(0x70)
118
-
119
-        self.write_cmd(0x3A) 
119
+        self.write_cmd(0x3A)
120 120
         self.write_data(0x05)
121
-
122 121
         self.write_cmd(0xB2)
123 122
         self.write_data(0x0C)
124 123
         self.write_data(0x0C)
125 124
         self.write_data(0x00)
126 125
         self.write_data(0x33)
127 126
         self.write_data(0x33)
128
-
129 127
         self.write_cmd(0xB7)
130
-        self.write_data(0x35) 
131
-
128
+        self.write_data(0x35)
132 129
         self.write_cmd(0xBB)
133 130
         self.write_data(0x19)
134
-
135 131
         self.write_cmd(0xC0)
136 132
         self.write_data(0x2C)
137
-
138 133
         self.write_cmd(0xC2)
139 134
         self.write_data(0x01)
140
-
141 135
         self.write_cmd(0xC3)
142
-        self.write_data(0x12)   
143
-
136
+        self.write_data(0x12)
144 137
         self.write_cmd(0xC4)
145 138
         self.write_data(0x20)
146
-
147 139
         self.write_cmd(0xC6)
148
-        self.write_data(0x0F) 
149
-
140
+        self.write_data(0x0F)
150 141
         self.write_cmd(0xD0)
151 142
         self.write_data(0xA4)
152 143
         self.write_data(0xA1)
153
-
154 144
         self.write_cmd(0xE0)
155 145
         self.write_data(0xD0)
156 146
         self.write_data(0x04)
@@ -166,7 +156,6 @@ class LCD(framebuf.FrameBuffer):
166 156
         self.write_data(0x0B)
167 157
         self.write_data(0x1F)
168 158
         self.write_data(0x23)
169
-
170 159
         self.write_cmd(0xE1)
171 160
         self.write_data(0xD0)
172 161
         self.write_data(0x04)
@@ -182,11 +171,8 @@ class LCD(framebuf.FrameBuffer):
182 171
         self.write_data(0x1F)
183 172
         self.write_data(0x20)
184 173
         self.write_data(0x23)
185
-        
186 174
         self.write_cmd(0x21)
187
-
188 175
         self.write_cmd(0x11)
189
-
190 176
         self.write_cmd(0x29)
191 177
 
192 178
     def show(self):
@@ -195,15 +181,12 @@ class LCD(framebuf.FrameBuffer):
195 181
         self.write_data(0x00)
196 182
         self.write_data(0x00)
197 183
         self.write_data(0xef)
198
-        
199 184
         self.write_cmd(0x2B)
200 185
         self.write_data(0x00)
201 186
         self.write_data(0x00)
202 187
         self.write_data(0x00)
203 188
         self.write_data(0xEF)
204
-
205 189
         self.write_cmd(0x2C)
206
-
207 190
         self.cs(1)
208 191
         self.dc(1)
209 192
         self.cs(0)
@@ -237,102 +220,26 @@ class LCD(framebuf.FrameBuffer):
237 220
                    start_angle, end_angle,
238 221
                    filled = True,
239 222
                    num_segments = 128):
240
-        point_list = [0, 0]
241
-
242 223
         start_segment = int(start_angle / 360 * num_segments)
243 224
         end_segment = int(end_angle / 360 * num_segments)
244 225
 
226
+        gc.collect()
227
+        point_list = array('h')
228
+        point_list.append(0)
229
+        point_list.append(0)
230
+
245 231
         for segment in range(start_segment, end_segment + 1):
246 232
             theta = 2.0 * 3.1415926 * segment / num_segments
247 233
             x = w * math.cos(theta) / 2
248 234
             y = h * math.sin(theta) / 2
235
+
236
+            i = (segment - start_segment + 1) * 2
249 237
             point_list.append(int(x))
250 238
             point_list.append(int(y))
251 239
 
252
-        self.poly(int(x_off), int(y_off), array('h', point_list), c, True)
240
+        self.poly(int(x_off), int(y_off), point_list, c, True)
253 241
 
254 242
     def pie(self, x0, y0, w, c_border, c_circle, v):
255 243
         if v > 0.0:
256
-            lcd.arc(int(x0), int(y0), int(w), int(w), c_circle, -90, int(v * 360) - 90)
257
-        lcd.ring(int(x0), int(y0), int(w / 2), c_border)
258
-
259
-if __name__  == '__main__':
260
-    start = time.time()
261
-    def gfx_test(lcd):
262
-        v = (time.time() - start)
263
-        lcd.fill(lcd.black)
264
-        lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width, lcd.red, lcd.green, (v % 11) / 10)
265
-
266
-    def key_test(lcd):
267
-        lcd.fill(lcd.white)
268
-
269
-        if lcd.keyA.value() == 0:
270
-            lcd.fill_rect(208,15,30,30,lcd.red)
271
-        else:
272
-            lcd.fill_rect(208,15,30,30,lcd.white)
273
-            lcd.rect(208,15,30,30,lcd.red)
274
-
275
-        if lcd.keyB.value() == 0:
276
-            lcd.fill_rect(208,75,30,30,lcd.red)
277
-        else:
278
-            lcd.fill_rect(208,75,30,30,lcd.white)
279
-            lcd.rect(208,75,30,30,lcd.red)
280
-
281
-        if lcd.keyX.value() == 0:
282
-            lcd.fill_rect(208,135,30,30,lcd.red)
283
-        else:
284
-            lcd.fill_rect(208,135,30,30,lcd.white)
285
-            lcd.rect(208,135,30,30,lcd.red)
286
-
287
-        if lcd.keyY.value() == 0:
288
-            lcd.fill_rect(208,195,30,30,lcd.red)
289
-        else:
290
-            lcd.fill_rect(208,195,30,30,lcd.white)
291
-            lcd.rect(208,195,30,30,lcd.red)
292
-
293
-        if lcd.up.value() == 0:
294
-            lcd.fill_rect(60,60,30,30,lcd.red)
295
-        else:
296
-            lcd.fill_rect(60,60,30,30,lcd.white)
297
-            lcd.rect(60,60,30,30,lcd.red)
298
-
299
-        if lcd.down.value() == 0:
300
-            lcd.fill_rect(60,150,30,30,lcd.red)
301
-        else:
302
-            lcd.fill_rect(60,150,30,30,lcd.white)
303
-            lcd.rect(60,150,30,30,lcd.red)
304
-
305
-        if lcd.left.value() == 0:
306
-            lcd.fill_rect(15,105,30,30,lcd.red)
307
-        else:
308
-            lcd.fill_rect(15,105,30,30,lcd.white)
309
-            lcd.rect(15,105,30,30,lcd.red)
310
-
311
-        if lcd.right.value() == 0:
312
-            lcd.fill_rect(105,105,30,30,lcd.red)
313
-        else:
314
-            lcd.fill_rect(105,105,30,30,lcd.white)
315
-            lcd.rect(105,105,30,30,lcd.red)
316
-
317
-        if lcd.ctrl.value() == 0:
318
-            lcd.fill_rect(60,105,30,30,lcd.red)
319
-        else:
320
-            lcd.fill_rect(60,105,30,30,lcd.white)
321
-            lcd.rect(60,105,30,30,lcd.red)
322
-
323
-    lcd = LCD()
324
-    lcd.brightness(1.0)
325
-
326
-    try:
327
-        while True:
328
-            #key_test(lcd)
329
-            gfx_test(lcd)
330
-
331
-            lcd.show()
332
-            time.sleep(0.1)
333
-    except KeyboardInterrupt:
334
-        pass
335
-
336
-    lcd.fill(lcd.black)
337
-    lcd.show()
338
-    lcd.brightness(0.0)
244
+            self.arc(int(x0), int(y0), int(w), int(w), c_circle, -90, int(v * 360) - 90)
245
+        self.ring(int(x0), int(y0), int(w / 2), c_border)

+ 41
- 64
python-test/poll.py View File

@@ -20,19 +20,7 @@ characteristic10 = None
20 20
 characteristic13 = None
21 21
 characteristic14 = None
22 22
 
23
-async def ble_conn(address):
24
-    dev = await ble_scan(address)
25
-
26
-    if dev:
27
-        address = dev.device.addr_hex()
28
-        print("Connecting to '{}'...".format(address))
29
-        connection = await dev.device.connect()
30
-        await cache_services_characteristics(connection)
31
-        return connection
32
-
33
-    return None
34
-
35
-async def cache_services_characteristics(device):
23
+async def cache_services_characteristics(device, cb = None):
36 24
     global service3, service4
37 25
     global characteristic1, characteristic3
38 26
     global characteristicd, characteristicc
@@ -40,31 +28,52 @@ async def cache_services_characteristics(device):
40 28
     global characteristic13, characteristic14
41 29
 
42 30
     service3 = await device.service(serviceUuidVolcano3)
31
+    if cb != None:
32
+        await cb(0.1)
33
+
43 34
     service4 = await device.service(serviceUuidVolcano4)
35
+    if cb != None:
36
+        await cb(0.2)
44 37
 
45 38
     uuid1 = bluetooth.UUID("10110001-5354-4f52-5a26-4249434b454c")
46 39
     characteristic1 = await service4.characteristic(uuid1)
40
+    if cb != None:
41
+        await cb(0.3)
47 42
 
48 43
     uuid3 = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
49 44
     characteristic3 = await service4.characteristic(uuid3)
45
+    if cb != None:
46
+        await cb(0.4)
50 47
 
51 48
     uuidd = bluetooth.UUID("1010000d-5354-4f52-5a26-4249434b454c")
52 49
     characteristicd = await service3.characteristic(uuidd)
50
+    if cb != None:
51
+        await cb(0.5)
53 52
 
54 53
     uuidc = bluetooth.UUID("1010000c-5354-4f52-5a26-4249434b454c")
55 54
     characteristicc = await service3.characteristic(uuidc)
55
+    if cb != None:
56
+        await cb(0.6)
56 57
 
57 58
     uuidf = bluetooth.UUID("1011000f-5354-4f52-5a26-4249434b454c")
58 59
     characteristicf = await service4.characteristic(uuidf)
60
+    if cb != None:
61
+        await cb(0.7)
59 62
 
60 63
     uuid10 = bluetooth.UUID("10110010-5354-4f52-5a26-4249434b454c")
61 64
     characteristic10 = await service4.characteristic(uuid10)
65
+    if cb != None:
66
+        await cb(0.8)
62 67
 
63 68
     uuid13 = bluetooth.UUID("10110013-5354-4f52-5a26-4249434b454c")
64 69
     characteristic13 = await service4.characteristic(uuid13)
70
+    if cb != None:
71
+        await cb(0.9)
65 72
 
66 73
     uuid14 = bluetooth.UUID("10110014-5354-4f52-5a26-4249434b454c")
67 74
     characteristic14 = await service4.characteristic(uuid14)
75
+    if cb != None:
76
+        await cb(1.0)
68 77
 
69 78
 async def get_current_temp(device):
70 79
     val = await characteristic1.read()
@@ -103,54 +112,22 @@ async def get_state(device):
103 112
     return (heater, pump)
104 113
 
105 114
 async def set_state(device, state):
106
-    heater, pump = state
107
-    if heater == True:
108
-        await characteristicf.write(int(0).to_bytes(1, "little"))
109
-    elif heater == False:
110
-        await characteristic10.write(int(0).to_bytes(1, "little"))
111
-
112
-    if pump == True:
113
-        await characteristic13.write(int(0).to_bytes(1, "little"))
114
-    elif pump == False:
115
-        await characteristic14.write(int(0).to_bytes(1, "little"))
116
-
117
-if __name__ == "__main__":
118
-    async def test_poll(device):
119
-        temp = await get_current_temp(device)
120
-        print("Current Temperature: {}".format(temp))
121
-
122
-        target = await get_target_temp(device)
123
-        print("Target Temperature: {}".format(target))
124
-
125
-        fahrenheit = await get_unit_is_fahrenheit(device)
126
-        if fahrenheit:
127
-            print("Unit is Fahrenheit")
128
-        else:
129
-            print("Unit is Celsius")
130
-
131
-        heater, pump = await get_state(device)
132
-        if heater:
133
-            print("Heater is On")
134
-        else:
135
-            print("Heater is Off")
136
-        if pump:
137
-            print("Pump is On")
138
-        else:
139
-            print("Pump is Off")
140
-
141
-    async def test(address):
142
-        device = await ble_conn(address)
143
-        if device == None:
144
-            return
145
-
146
-        async with device:
147
-            print("Writing...")
148
-            await set_target_temp(device, 190.0)
149
-
150
-            print("Reading...")
151
-            for i in range(0, 5):
152
-                await test_poll(device)
153
-                print()
154
-                time.sleep(2.0)
155
-
156
-    asyncio.run(test(None))
115
+    attempts = 3
116
+    while attempts > 0:
117
+        attempts -= 1
118
+        try:
119
+            heater, pump = state
120
+            if heater == True:
121
+                await characteristicf.write(int(0).to_bytes(1, "little"))
122
+            elif heater == False:
123
+                await characteristic10.write(int(0).to_bytes(1, "little"))
124
+
125
+            if pump == True:
126
+                await characteristic13.write(int(0).to_bytes(1, "little"))
127
+            elif pump == False:
128
+                await characteristic14.write(int(0).to_bytes(1, "little"))
129
+        except:
130
+            time.sleep(0.05)
131
+            continue
132
+
133
+        break

+ 0
- 8
python-test/scan.py View File

@@ -6,12 +6,10 @@ import bluetooth
6 6
 import sys
7 7
 
8 8
 async def ble_scan(addr = None, name = "S&B VOLCANO H", timeout = 0.5):
9
-    #print("Scanning for '{}' for {}s...".format(addr, timeout))
10 9
     scanner = aioble.scan(int(timeout * 1000.0), interval_us=30000, window_us=30000, active=True)
11 10
     async with scanner as s:
12 11
         results = []
13 12
         async for d in s:
14
-            #print("Scan: '{}' [{}]".format(d.name(), d.device.addr_hex()))
15 13
             if addr != None:
16 14
                 if addr == d.device.addr_hex():
17 15
                     return d
@@ -22,10 +20,4 @@ async def ble_scan(addr = None, name = "S&B VOLCANO H", timeout = 0.5):
22 20
                 results.append(d)
23 21
         return results
24 22
 
25
-    print("No device found")
26 23
     return None
27
-
28
-if __name__ == "__main__":
29
-    dev = asyncio.run(ble_scan())
30
-    if dev != None:
31
-        print("{}".format(dev.device.addr_hex()))

+ 13
- 7
python-test/state_connect.py View File

@@ -12,6 +12,7 @@ class StateConnect:
12 12
 
13 13
     def enter(self, val = None):
14 14
         self.step = False
15
+        self.iteration = 0.0
15 16
         self.done = False
16 17
         self.client = None
17 18
         self.connector = asyncio.create_task(self.connect(val))
@@ -24,6 +25,10 @@ class StateConnect:
24 25
 
25 26
         return self.client
26 27
 
28
+    async def progress(self, n):
29
+        async with self.lock:
30
+            self.iteration = n
31
+
27 32
     async def connect(self, d):
28 33
         async with self.lock:
29 34
             self.done = False
@@ -32,7 +37,8 @@ class StateConnect:
32 37
             client = await d[0].device.connect()
33 38
             async with self.lock:
34 39
                 self.step = True
35
-            await cache_services_characteristics(client)
40
+
41
+            await cache_services_characteristics(client, self.progress)
36 42
         else:
37 43
             await d[0].disconnect()
38 44
             client = None
@@ -47,18 +53,17 @@ class StateConnect:
47 53
         keys = self.lcd.buttons()
48 54
 
49 55
         if keys.once("y"):
50
-            print("user abort")
51 56
             if self.state:
52
-                return 5 # disconnect
57
+                return 5
53 58
             else:
54
-                return 0 # scan
59
+                return 0
55 60
 
56 61
         async with self.lock:
57 62
             if self.done:
58 63
                 if self.state:
59
-                    return 3 # heater on
64
+                    return 3
60 65
                 else:
61
-                    return 0 # scan
66
+                    return 0
62 67
             else:
63 68
                 if self.state == False:
64 69
                     self.lcd.text("Disconnecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
@@ -66,6 +71,7 @@ class StateConnect:
66 71
                     if self.step == False:
67 72
                         self.lcd.text("Connecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
68 73
                     else:
74
+                        self.lcd.pie(self.lcd.width / 2, self.lcd.height / 2, self.lcd.width - 30, self.lcd.red, self.lcd.green, self.iteration)
69 75
                         self.lcd.text("Fetching parameters...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
70 76
 
71
-        return -1 # stay in this state
77
+        return -1

+ 7
- 10
python-test/state_heat.py View File

@@ -12,9 +12,9 @@ class StateHeat:
12 12
 
13 13
     def enter(self, val = None):
14 14
         self.value = val
15
-        self.heater = asyncio.create_task(self.heat())
16 15
         self.done = False
17 16
         self.step = False
17
+        self.heater = asyncio.create_task(self.heat())
18 18
 
19 19
     def exit(self):
20 20
         self.heater.cancel()
@@ -29,7 +29,6 @@ class StateHeat:
29 29
         if self.state == False:
30 30
             pump = False
31 31
 
32
-        print("Setting heater: {}".format(self.state))
33 32
         await set_state(self.value[0], (self.state, pump))
34 33
 
35 34
         if self.state == False:
@@ -38,7 +37,6 @@ class StateHeat:
38 37
 
39 38
             temp = self.value[1]["reset_temperature"]
40 39
             if temp != None:
41
-                print("Reset temperature to default value")
42 40
                 await set_target_temp(self.value[0], temp)
43 41
 
44 42
         async with self.lock:
@@ -50,22 +48,21 @@ class StateHeat:
50 48
         keys = self.lcd.buttons()
51 49
 
52 50
         if keys.once("y"):
53
-            print("user abort")
54 51
             if self.state:
55 52
                 async with self.lock:
56 53
                     if self.done:
57
-                        return 4 # heat off
54
+                        return 4
58 55
                     else:
59
-                        return 5 # disconnect
56
+                        return 5
60 57
             else:
61
-                return 5 # disconnect
58
+                return 5
62 59
 
63 60
         async with self.lock:
64 61
             if self.done:
65 62
                 if self.state == False:
66
-                    return 5 # disconnect
63
+                    return 5
67 64
                 else:
68
-                    return 6 # wait for temperature
65
+                    return 6
69 66
             else:
70 67
                 if self.state == False:
71 68
                     if self.state == False:
@@ -75,4 +72,4 @@ class StateHeat:
75 72
                 else:
76 73
                     self.lcd.text("Turning heater on...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
77 74
 
78
-        return -1 # stay in this state
75
+        return -1

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

@@ -13,8 +13,10 @@ class StateNotify:
13 13
 
14 14
     def enter(self, val = None):
15 15
         self.value = val
16
-        self.notifier = asyncio.create_task(self.notify())
17 16
         self.done = False
17
+        self.step = 0
18
+        self.max = 0
19
+        self.notifier = asyncio.create_task(self.notify())
18 20
 
19 21
     def exit(self):
20 22
         self.notifier.cancel()
@@ -28,14 +30,19 @@ class StateNotify:
28 30
         device, workflow, index = self.value
29 31
         count, duration = workflow["notify"]
30 32
 
33
+        async with self.lock:
34
+            self.max = count * 2
35
+
31 36
         for i in range(0, count):
32
-            print("Turning on pump")
33
-            await set_state(device, (None, True))
34 37
             await asyncio.sleep_ms(int(duration * 1000))
38
+            await set_state(device, (None, True))
39
+            async with self.lock:
40
+                self.step += 1
35 41
 
36
-            print("Turning off pump")
37
-            await set_state(device, (None, False))
38 42
             await asyncio.sleep_ms(int(duration * 1000))
43
+            await set_state(device, (None, False))
44
+            async with self.lock:
45
+                self.step += 1
39 46
 
40 47
         async with self.lock:
41 48
             self.done = True
@@ -46,11 +53,12 @@ class StateNotify:
46 53
         keys = self.lcd.buttons()
47 54
 
48 55
         if keys.once("y"):
49
-            print("user abort")
50
-            return 4 # heat off
56
+            return 4
51 57
 
52 58
         async with self.lock:
59
+            draw_graph(self.lcd, 0, self.step, self.max)
60
+
53 61
             if self.done:
54
-                return 4 # heater off
62
+                return 4
55 63
 
56
-        return -1 # stay in this state
64
+        return -1

+ 7
- 9
python-test/state_pump.py View File

@@ -13,13 +13,14 @@ class StatePump:
13 13
 
14 14
     def enter(self, val = None):
15 15
         self.value = val
16
-        self.pumper = asyncio.create_task(self.pump())
17 16
         self.done = False
18 17
 
19 18
         device, workflow, index = self.value
20 19
         self.start = None
21 20
         self.duration = workflow["steps"][index][2]
22 21
 
22
+        self.pumper = asyncio.create_task(self.pump())
23
+
23 24
     def exit(self):
24 25
         self.pumper.cancel()
25 26
 
@@ -31,14 +32,12 @@ class StatePump:
31 32
     async def pump(self):
32 33
         device, workflow, index = self.value
33 34
 
34
-        print("Turning on pump")
35 35
         await set_state(device, (None, True))
36 36
         async with self.lock:
37 37
             self.start = time.time()
38 38
 
39 39
         await asyncio.sleep_ms(int(self.duration * 1000))
40 40
 
41
-        print("Turning off pump")
42 41
         await set_state(device, (None, False))
43 42
         async with self.lock:
44 43
             self.done = True
@@ -50,8 +49,7 @@ class StatePump:
50 49
         keys = self.lcd.buttons()
51 50
 
52 51
         if keys.once("y"):
53
-            print("user abort")
54
-            return 4 # heat off
52
+            return 4
55 53
 
56 54
         async with self.lock:
57 55
             if self.start != None:
@@ -66,10 +64,10 @@ class StatePump:
66 64
             if self.done:
67 65
                 if self.value[2] >= (len(workflow["steps"]) - 1):
68 66
                     if workflow["notify"] != None:
69
-                        return 9 # notify
67
+                        return 9
70 68
                     else:
71
-                        return 4 # heater off
69
+                        return 4
72 70
                 else:
73
-                    return 6 # wait for temperature
71
+                    return 6
74 72
 
75
-        return -1 # stay in this state
73
+        return -1

+ 3
- 3
python-test/state_scan.py View File

@@ -10,9 +10,9 @@ class StateScan:
10 10
         self.lock = asyncio.Lock()
11 11
 
12 12
     def enter(self, val = None):
13
-        self.scanner = asyncio.create_task(self.scan())
14 13
         self.results = []
15 14
         self.current = None
15
+        self.scanner = asyncio.create_task(self.scan())
16 16
 
17 17
     def exit(self):
18 18
         self.scanner.cancel()
@@ -69,7 +69,7 @@ class StateScan:
69 69
         async with self.lock:
70 70
             if keys.once("enter"):
71 71
                 if self.current < len(self.results):
72
-                    return 2 # select
72
+                    return 2
73 73
             elif keys.once("up"):
74 74
                 if self.current == None:
75 75
                     self.current = len(self.results) - 1
@@ -83,4 +83,4 @@ class StateScan:
83 83
 
84 84
             self.draw_list()
85 85
 
86
-        return -1 # stay in this state
86
+        return -1

+ 3
- 4
python-test/state_select.py View File

@@ -37,8 +37,7 @@ class StateSelect:
37 37
         keys = self.lcd.buttons()
38 38
 
39 39
         if keys.once("y"):
40
-            print("user abort")
41
-            return 5 # disconnect
40
+            return 5
42 41
         elif keys.once("up"):
43 42
             if self.current > 0:
44 43
                 self.current -= 1
@@ -46,8 +45,8 @@ class StateSelect:
46 45
             if self.current < (len(workflows) - 1):
47 46
                 self.current += 1
48 47
         elif keys.once("enter"):
49
-            return 1 # connect
48
+            return 1
50 49
 
51 50
         self.draw_list()
52 51
 
53
-        return -1 # stay in this state
52
+        return -1

+ 6
- 18
python-test/state_wait_temp.py View File

@@ -8,17 +8,10 @@ def draw_graph(lcd, min, val, max):
8 8
         lcd.text("{} -> {} -> {}".format(min, val, max), 0, int(lcd.height / 2) - 5, lcd.white)
9 9
         return
10 10
 
11
-    w = lcd.width - 10
12 11
     ratio = (val - min) / (max - min)
12
+    lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width - 30, lcd.red, lcd.green, ratio)
13 13
 
14
-    #wfull = int(w * ratio)
15
-    #wempty = w - wfull
16
-    #lcd.rect(4, int(lcd.height / 2) - 5, wfull + 1, 50, lcd.green, True)
17
-    #lcd.rect(4 + wfull, int(lcd.height / 2) - 5, wempty + 2, 50, lcd.green, False)
18
-
19
-    lcd.pie(lcd.width / 2, lcd.height / 2, w, lcd.red, lcd.green, ratio)
20
-
21
-    lcd.text("{}".format(val), int(lcd.width / 2), 125, lcd.white)
14
+    lcd.text("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2) - 5, lcd.white)
22 15
 
23 16
 class StateWaitTemp:
24 17
     def __init__(self, lcd):
@@ -28,10 +21,10 @@ class StateWaitTemp:
28 21
 
29 22
     def enter(self, val = None):
30 23
         self.value = val
31
-        self.poller = asyncio.create_task(self.poll())
32 24
         self.temp = 0.0
33 25
         self.min = 0.0
34 26
         self.max = 100.0
27
+        self.poller = asyncio.create_task(self.poll())
35 28
 
36 29
     def exit(self):
37 30
         self.poller.cancel()
@@ -49,17 +42,14 @@ class StateWaitTemp:
49 42
             self.max = workflow["steps"][index][0]
50 43
 
51 44
         temp = await get_current_temp(device)
52
-        print("initial temp: {}".format(temp))
53 45
         async with self.lock:
54 46
             self.temp = temp
55 47
             self.min = temp
56 48
 
57
-        print("Setting temperature: {}".format(self.max))
58 49
         await set_target_temp(device, self.max)
59 50
 
60 51
         while temp < self.max:
61 52
             temp = await get_current_temp(device)
62
-            print("now at {}".format(temp))
63 53
             async with self.lock:
64 54
                 self.temp = temp
65 55
 
@@ -70,8 +60,7 @@ class StateWaitTemp:
70 60
         keys = self.lcd.buttons()
71 61
 
72 62
         if keys.once("y"):
73
-            print("user abort")
74
-            return 4 # heat off
63
+            return 4
75 64
 
76 65
         async with self.lock:
77 66
             if self.temp == 0.0:
@@ -80,7 +69,6 @@ class StateWaitTemp:
80 69
                 draw_graph(self.lcd, self.min, self.temp, self.max)
81 70
 
82 71
             if self.temp >= self.max:
83
-                print("switch, {} >= {}".format(self.temp, self.max))
84
-                return 7 # wait for time
72
+                return 7
85 73
 
86
-        return -1 # stay in this state
74
+        return -1

+ 3
- 5
python-test/state_wait_time.py View File

@@ -24,14 +24,12 @@ class StateWaitTime:
24 24
         keys = self.lcd.buttons()
25 25
 
26 26
         if keys.once("y"):
27
-            print("user abort")
28
-            return 4 # heat off
27
+            return 4
29 28
 
30 29
         now = time.time()
31 30
         draw_graph(self.lcd, 0.0, now - self.start, self.end - self.start)
32 31
 
33 32
         if now >= self.end:
34
-            print("switch, {} >= {}".format(now, self.end))
35
-            return 8 # pump
33
+            return 8
36 34
 
37
-        return -1 # stay in this state
35
+        return -1

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

@@ -34,7 +34,6 @@ class States:
34 34
 
35 35
         next = asyncio.run(self.draw())
36 36
         if next >= 0:
37
-            print("switch to {}".format(next))
38 37
             val = self.states[self.current].exit()
39 38
             self.current = next
40 39
             self.states[self.current].enter(val)
@@ -46,17 +45,14 @@ if True:#__name__ == "__main__":
46 45
     states = States(lcd)
47 46
 
48 47
     # 0 - Scan
49
-    # passes ScanResult to 2, select
50 48
     scan = StateScan(lcd)
51 49
     states.add(scan)
52 50
 
53 51
     # 1 - Connect
54
-    # passes device and selected workflow to 3, heater on
55 52
     conn = StateConnect(lcd, True)
56 53
     states.add(conn)
57 54
 
58 55
     # 2 - Select
59
-    # passes ScanResult and selected workflow to 1, connect
60 56
     select = StateSelect(lcd)
61 57
     states.add(select)
62 58
 

Loading…
Cancel
Save