Browse Source

remove unneeded stuff

Thomas Buck 1 year ago
parent
commit
34b99d09db

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

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

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

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
 import time
8
 import time
9
 import os
9
 import os
10
 import math
10
 import math
11
+import gc
11
 
12
 
12
 class KeyCheck:
13
 class KeyCheck:
13
     def __init__(self, new, old):
14
     def __init__(self, new, old):
34
         self.dc = Pin(8, Pin.OUT)
35
         self.dc = Pin(8, Pin.OUT)
35
         self.dc(1)
36
         self.dc(1)
36
 
37
 
38
+        gc.collect()
37
         self.buffer = bytearray(self.height * self.width * 2)
39
         self.buffer = bytearray(self.height * self.width * 2)
38
 
40
 
39
         super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
41
         super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
112
         self.rst(1)
114
         self.rst(1)
113
         self.rst(0)
115
         self.rst(0)
114
         self.rst(1)
116
         self.rst(1)
115
-
116
         self.write_cmd(0x36)
117
         self.write_cmd(0x36)
117
         self.write_data(0x70)
118
         self.write_data(0x70)
118
-
119
-        self.write_cmd(0x3A) 
119
+        self.write_cmd(0x3A)
120
         self.write_data(0x05)
120
         self.write_data(0x05)
121
-
122
         self.write_cmd(0xB2)
121
         self.write_cmd(0xB2)
123
         self.write_data(0x0C)
122
         self.write_data(0x0C)
124
         self.write_data(0x0C)
123
         self.write_data(0x0C)
125
         self.write_data(0x00)
124
         self.write_data(0x00)
126
         self.write_data(0x33)
125
         self.write_data(0x33)
127
         self.write_data(0x33)
126
         self.write_data(0x33)
128
-
129
         self.write_cmd(0xB7)
127
         self.write_cmd(0xB7)
130
-        self.write_data(0x35) 
131
-
128
+        self.write_data(0x35)
132
         self.write_cmd(0xBB)
129
         self.write_cmd(0xBB)
133
         self.write_data(0x19)
130
         self.write_data(0x19)
134
-
135
         self.write_cmd(0xC0)
131
         self.write_cmd(0xC0)
136
         self.write_data(0x2C)
132
         self.write_data(0x2C)
137
-
138
         self.write_cmd(0xC2)
133
         self.write_cmd(0xC2)
139
         self.write_data(0x01)
134
         self.write_data(0x01)
140
-
141
         self.write_cmd(0xC3)
135
         self.write_cmd(0xC3)
142
-        self.write_data(0x12)   
143
-
136
+        self.write_data(0x12)
144
         self.write_cmd(0xC4)
137
         self.write_cmd(0xC4)
145
         self.write_data(0x20)
138
         self.write_data(0x20)
146
-
147
         self.write_cmd(0xC6)
139
         self.write_cmd(0xC6)
148
-        self.write_data(0x0F) 
149
-
140
+        self.write_data(0x0F)
150
         self.write_cmd(0xD0)
141
         self.write_cmd(0xD0)
151
         self.write_data(0xA4)
142
         self.write_data(0xA4)
152
         self.write_data(0xA1)
143
         self.write_data(0xA1)
153
-
154
         self.write_cmd(0xE0)
144
         self.write_cmd(0xE0)
155
         self.write_data(0xD0)
145
         self.write_data(0xD0)
156
         self.write_data(0x04)
146
         self.write_data(0x04)
166
         self.write_data(0x0B)
156
         self.write_data(0x0B)
167
         self.write_data(0x1F)
157
         self.write_data(0x1F)
168
         self.write_data(0x23)
158
         self.write_data(0x23)
169
-
170
         self.write_cmd(0xE1)
159
         self.write_cmd(0xE1)
171
         self.write_data(0xD0)
160
         self.write_data(0xD0)
172
         self.write_data(0x04)
161
         self.write_data(0x04)
182
         self.write_data(0x1F)
171
         self.write_data(0x1F)
183
         self.write_data(0x20)
172
         self.write_data(0x20)
184
         self.write_data(0x23)
173
         self.write_data(0x23)
185
-        
186
         self.write_cmd(0x21)
174
         self.write_cmd(0x21)
187
-
188
         self.write_cmd(0x11)
175
         self.write_cmd(0x11)
189
-
190
         self.write_cmd(0x29)
176
         self.write_cmd(0x29)
191
 
177
 
192
     def show(self):
178
     def show(self):
195
         self.write_data(0x00)
181
         self.write_data(0x00)
196
         self.write_data(0x00)
182
         self.write_data(0x00)
197
         self.write_data(0xef)
183
         self.write_data(0xef)
198
-        
199
         self.write_cmd(0x2B)
184
         self.write_cmd(0x2B)
200
         self.write_data(0x00)
185
         self.write_data(0x00)
201
         self.write_data(0x00)
186
         self.write_data(0x00)
202
         self.write_data(0x00)
187
         self.write_data(0x00)
203
         self.write_data(0xEF)
188
         self.write_data(0xEF)
204
-
205
         self.write_cmd(0x2C)
189
         self.write_cmd(0x2C)
206
-
207
         self.cs(1)
190
         self.cs(1)
208
         self.dc(1)
191
         self.dc(1)
209
         self.cs(0)
192
         self.cs(0)
237
                    start_angle, end_angle,
220
                    start_angle, end_angle,
238
                    filled = True,
221
                    filled = True,
239
                    num_segments = 128):
222
                    num_segments = 128):
240
-        point_list = [0, 0]
241
-
242
         start_segment = int(start_angle / 360 * num_segments)
223
         start_segment = int(start_angle / 360 * num_segments)
243
         end_segment = int(end_angle / 360 * num_segments)
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
         for segment in range(start_segment, end_segment + 1):
231
         for segment in range(start_segment, end_segment + 1):
246
             theta = 2.0 * 3.1415926 * segment / num_segments
232
             theta = 2.0 * 3.1415926 * segment / num_segments
247
             x = w * math.cos(theta) / 2
233
             x = w * math.cos(theta) / 2
248
             y = h * math.sin(theta) / 2
234
             y = h * math.sin(theta) / 2
235
+
236
+            i = (segment - start_segment + 1) * 2
249
             point_list.append(int(x))
237
             point_list.append(int(x))
250
             point_list.append(int(y))
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
     def pie(self, x0, y0, w, c_border, c_circle, v):
242
     def pie(self, x0, y0, w, c_border, c_circle, v):
255
         if v > 0.0:
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
 characteristic13 = None
20
 characteristic13 = None
21
 characteristic14 = None
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
     global service3, service4
24
     global service3, service4
37
     global characteristic1, characteristic3
25
     global characteristic1, characteristic3
38
     global characteristicd, characteristicc
26
     global characteristicd, characteristicc
40
     global characteristic13, characteristic14
28
     global characteristic13, characteristic14
41
 
29
 
42
     service3 = await device.service(serviceUuidVolcano3)
30
     service3 = await device.service(serviceUuidVolcano3)
31
+    if cb != None:
32
+        await cb(0.1)
33
+
43
     service4 = await device.service(serviceUuidVolcano4)
34
     service4 = await device.service(serviceUuidVolcano4)
35
+    if cb != None:
36
+        await cb(0.2)
44
 
37
 
45
     uuid1 = bluetooth.UUID("10110001-5354-4f52-5a26-4249434b454c")
38
     uuid1 = bluetooth.UUID("10110001-5354-4f52-5a26-4249434b454c")
46
     characteristic1 = await service4.characteristic(uuid1)
39
     characteristic1 = await service4.characteristic(uuid1)
40
+    if cb != None:
41
+        await cb(0.3)
47
 
42
 
48
     uuid3 = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
43
     uuid3 = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
49
     characteristic3 = await service4.characteristic(uuid3)
44
     characteristic3 = await service4.characteristic(uuid3)
45
+    if cb != None:
46
+        await cb(0.4)
50
 
47
 
51
     uuidd = bluetooth.UUID("1010000d-5354-4f52-5a26-4249434b454c")
48
     uuidd = bluetooth.UUID("1010000d-5354-4f52-5a26-4249434b454c")
52
     characteristicd = await service3.characteristic(uuidd)
49
     characteristicd = await service3.characteristic(uuidd)
50
+    if cb != None:
51
+        await cb(0.5)
53
 
52
 
54
     uuidc = bluetooth.UUID("1010000c-5354-4f52-5a26-4249434b454c")
53
     uuidc = bluetooth.UUID("1010000c-5354-4f52-5a26-4249434b454c")
55
     characteristicc = await service3.characteristic(uuidc)
54
     characteristicc = await service3.characteristic(uuidc)
55
+    if cb != None:
56
+        await cb(0.6)
56
 
57
 
57
     uuidf = bluetooth.UUID("1011000f-5354-4f52-5a26-4249434b454c")
58
     uuidf = bluetooth.UUID("1011000f-5354-4f52-5a26-4249434b454c")
58
     characteristicf = await service4.characteristic(uuidf)
59
     characteristicf = await service4.characteristic(uuidf)
60
+    if cb != None:
61
+        await cb(0.7)
59
 
62
 
60
     uuid10 = bluetooth.UUID("10110010-5354-4f52-5a26-4249434b454c")
63
     uuid10 = bluetooth.UUID("10110010-5354-4f52-5a26-4249434b454c")
61
     characteristic10 = await service4.characteristic(uuid10)
64
     characteristic10 = await service4.characteristic(uuid10)
65
+    if cb != None:
66
+        await cb(0.8)
62
 
67
 
63
     uuid13 = bluetooth.UUID("10110013-5354-4f52-5a26-4249434b454c")
68
     uuid13 = bluetooth.UUID("10110013-5354-4f52-5a26-4249434b454c")
64
     characteristic13 = await service4.characteristic(uuid13)
69
     characteristic13 = await service4.characteristic(uuid13)
70
+    if cb != None:
71
+        await cb(0.9)
65
 
72
 
66
     uuid14 = bluetooth.UUID("10110014-5354-4f52-5a26-4249434b454c")
73
     uuid14 = bluetooth.UUID("10110014-5354-4f52-5a26-4249434b454c")
67
     characteristic14 = await service4.characteristic(uuid14)
74
     characteristic14 = await service4.characteristic(uuid14)
75
+    if cb != None:
76
+        await cb(1.0)
68
 
77
 
69
 async def get_current_temp(device):
78
 async def get_current_temp(device):
70
     val = await characteristic1.read()
79
     val = await characteristic1.read()
103
     return (heater, pump)
112
     return (heater, pump)
104
 
113
 
105
 async def set_state(device, state):
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
 import sys
6
 import sys
7
 
7
 
8
 async def ble_scan(addr = None, name = "S&B VOLCANO H", timeout = 0.5):
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
     scanner = aioble.scan(int(timeout * 1000.0), interval_us=30000, window_us=30000, active=True)
9
     scanner = aioble.scan(int(timeout * 1000.0), interval_us=30000, window_us=30000, active=True)
11
     async with scanner as s:
10
     async with scanner as s:
12
         results = []
11
         results = []
13
         async for d in s:
12
         async for d in s:
14
-            #print("Scan: '{}' [{}]".format(d.name(), d.device.addr_hex()))
15
             if addr != None:
13
             if addr != None:
16
                 if addr == d.device.addr_hex():
14
                 if addr == d.device.addr_hex():
17
                     return d
15
                     return d
22
                 results.append(d)
20
                 results.append(d)
23
         return results
21
         return results
24
 
22
 
25
-    print("No device found")
26
     return None
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
 
12
 
13
     def enter(self, val = None):
13
     def enter(self, val = None):
14
         self.step = False
14
         self.step = False
15
+        self.iteration = 0.0
15
         self.done = False
16
         self.done = False
16
         self.client = None
17
         self.client = None
17
         self.connector = asyncio.create_task(self.connect(val))
18
         self.connector = asyncio.create_task(self.connect(val))
24
 
25
 
25
         return self.client
26
         return self.client
26
 
27
 
28
+    async def progress(self, n):
29
+        async with self.lock:
30
+            self.iteration = n
31
+
27
     async def connect(self, d):
32
     async def connect(self, d):
28
         async with self.lock:
33
         async with self.lock:
29
             self.done = False
34
             self.done = False
32
             client = await d[0].device.connect()
37
             client = await d[0].device.connect()
33
             async with self.lock:
38
             async with self.lock:
34
                 self.step = True
39
                 self.step = True
35
-            await cache_services_characteristics(client)
40
+
41
+            await cache_services_characteristics(client, self.progress)
36
         else:
42
         else:
37
             await d[0].disconnect()
43
             await d[0].disconnect()
38
             client = None
44
             client = None
47
         keys = self.lcd.buttons()
53
         keys = self.lcd.buttons()
48
 
54
 
49
         if keys.once("y"):
55
         if keys.once("y"):
50
-            print("user abort")
51
             if self.state:
56
             if self.state:
52
-                return 5 # disconnect
57
+                return 5
53
             else:
58
             else:
54
-                return 0 # scan
59
+                return 0
55
 
60
 
56
         async with self.lock:
61
         async with self.lock:
57
             if self.done:
62
             if self.done:
58
                 if self.state:
63
                 if self.state:
59
-                    return 3 # heater on
64
+                    return 3
60
                 else:
65
                 else:
61
-                    return 0 # scan
66
+                    return 0
62
             else:
67
             else:
63
                 if self.state == False:
68
                 if self.state == False:
64
                     self.lcd.text("Disconnecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
69
                     self.lcd.text("Disconnecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
66
                     if self.step == False:
71
                     if self.step == False:
67
                         self.lcd.text("Connecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
72
                         self.lcd.text("Connecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
68
                     else:
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
                         self.lcd.text("Fetching parameters...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
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
 
12
 
13
     def enter(self, val = None):
13
     def enter(self, val = None):
14
         self.value = val
14
         self.value = val
15
-        self.heater = asyncio.create_task(self.heat())
16
         self.done = False
15
         self.done = False
17
         self.step = False
16
         self.step = False
17
+        self.heater = asyncio.create_task(self.heat())
18
 
18
 
19
     def exit(self):
19
     def exit(self):
20
         self.heater.cancel()
20
         self.heater.cancel()
29
         if self.state == False:
29
         if self.state == False:
30
             pump = False
30
             pump = False
31
 
31
 
32
-        print("Setting heater: {}".format(self.state))
33
         await set_state(self.value[0], (self.state, pump))
32
         await set_state(self.value[0], (self.state, pump))
34
 
33
 
35
         if self.state == False:
34
         if self.state == False:
38
 
37
 
39
             temp = self.value[1]["reset_temperature"]
38
             temp = self.value[1]["reset_temperature"]
40
             if temp != None:
39
             if temp != None:
41
-                print("Reset temperature to default value")
42
                 await set_target_temp(self.value[0], temp)
40
                 await set_target_temp(self.value[0], temp)
43
 
41
 
44
         async with self.lock:
42
         async with self.lock:
50
         keys = self.lcd.buttons()
48
         keys = self.lcd.buttons()
51
 
49
 
52
         if keys.once("y"):
50
         if keys.once("y"):
53
-            print("user abort")
54
             if self.state:
51
             if self.state:
55
                 async with self.lock:
52
                 async with self.lock:
56
                     if self.done:
53
                     if self.done:
57
-                        return 4 # heat off
54
+                        return 4
58
                     else:
55
                     else:
59
-                        return 5 # disconnect
56
+                        return 5
60
             else:
57
             else:
61
-                return 5 # disconnect
58
+                return 5
62
 
59
 
63
         async with self.lock:
60
         async with self.lock:
64
             if self.done:
61
             if self.done:
65
                 if self.state == False:
62
                 if self.state == False:
66
-                    return 5 # disconnect
63
+                    return 5
67
                 else:
64
                 else:
68
-                    return 6 # wait for temperature
65
+                    return 6
69
             else:
66
             else:
70
                 if self.state == False:
67
                 if self.state == False:
71
                     if self.state == False:
68
                     if self.state == False:
75
                 else:
72
                 else:
76
                     self.lcd.text("Turning heater on...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
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
 
13
 
14
     def enter(self, val = None):
14
     def enter(self, val = None):
15
         self.value = val
15
         self.value = val
16
-        self.notifier = asyncio.create_task(self.notify())
17
         self.done = False
16
         self.done = False
17
+        self.step = 0
18
+        self.max = 0
19
+        self.notifier = asyncio.create_task(self.notify())
18
 
20
 
19
     def exit(self):
21
     def exit(self):
20
         self.notifier.cancel()
22
         self.notifier.cancel()
28
         device, workflow, index = self.value
30
         device, workflow, index = self.value
29
         count, duration = workflow["notify"]
31
         count, duration = workflow["notify"]
30
 
32
 
33
+        async with self.lock:
34
+            self.max = count * 2
35
+
31
         for i in range(0, count):
36
         for i in range(0, count):
32
-            print("Turning on pump")
33
-            await set_state(device, (None, True))
34
             await asyncio.sleep_ms(int(duration * 1000))
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
             await asyncio.sleep_ms(int(duration * 1000))
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
         async with self.lock:
47
         async with self.lock:
41
             self.done = True
48
             self.done = True
46
         keys = self.lcd.buttons()
53
         keys = self.lcd.buttons()
47
 
54
 
48
         if keys.once("y"):
55
         if keys.once("y"):
49
-            print("user abort")
50
-            return 4 # heat off
56
+            return 4
51
 
57
 
52
         async with self.lock:
58
         async with self.lock:
59
+            draw_graph(self.lcd, 0, self.step, self.max)
60
+
53
             if self.done:
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
 
14
     def enter(self, val = None):
14
     def enter(self, val = None):
15
         self.value = val
15
         self.value = val
16
-        self.pumper = asyncio.create_task(self.pump())
17
         self.done = False
16
         self.done = False
18
 
17
 
19
         device, workflow, index = self.value
18
         device, workflow, index = self.value
20
         self.start = None
19
         self.start = None
21
         self.duration = workflow["steps"][index][2]
20
         self.duration = workflow["steps"][index][2]
22
 
21
 
22
+        self.pumper = asyncio.create_task(self.pump())
23
+
23
     def exit(self):
24
     def exit(self):
24
         self.pumper.cancel()
25
         self.pumper.cancel()
25
 
26
 
31
     async def pump(self):
32
     async def pump(self):
32
         device, workflow, index = self.value
33
         device, workflow, index = self.value
33
 
34
 
34
-        print("Turning on pump")
35
         await set_state(device, (None, True))
35
         await set_state(device, (None, True))
36
         async with self.lock:
36
         async with self.lock:
37
             self.start = time.time()
37
             self.start = time.time()
38
 
38
 
39
         await asyncio.sleep_ms(int(self.duration * 1000))
39
         await asyncio.sleep_ms(int(self.duration * 1000))
40
 
40
 
41
-        print("Turning off pump")
42
         await set_state(device, (None, False))
41
         await set_state(device, (None, False))
43
         async with self.lock:
42
         async with self.lock:
44
             self.done = True
43
             self.done = True
50
         keys = self.lcd.buttons()
49
         keys = self.lcd.buttons()
51
 
50
 
52
         if keys.once("y"):
51
         if keys.once("y"):
53
-            print("user abort")
54
-            return 4 # heat off
52
+            return 4
55
 
53
 
56
         async with self.lock:
54
         async with self.lock:
57
             if self.start != None:
55
             if self.start != None:
66
             if self.done:
64
             if self.done:
67
                 if self.value[2] >= (len(workflow["steps"]) - 1):
65
                 if self.value[2] >= (len(workflow["steps"]) - 1):
68
                     if workflow["notify"] != None:
66
                     if workflow["notify"] != None:
69
-                        return 9 # notify
67
+                        return 9
70
                     else:
68
                     else:
71
-                        return 4 # heater off
69
+                        return 4
72
                 else:
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
         self.lock = asyncio.Lock()
10
         self.lock = asyncio.Lock()
11
 
11
 
12
     def enter(self, val = None):
12
     def enter(self, val = None):
13
-        self.scanner = asyncio.create_task(self.scan())
14
         self.results = []
13
         self.results = []
15
         self.current = None
14
         self.current = None
15
+        self.scanner = asyncio.create_task(self.scan())
16
 
16
 
17
     def exit(self):
17
     def exit(self):
18
         self.scanner.cancel()
18
         self.scanner.cancel()
69
         async with self.lock:
69
         async with self.lock:
70
             if keys.once("enter"):
70
             if keys.once("enter"):
71
                 if self.current < len(self.results):
71
                 if self.current < len(self.results):
72
-                    return 2 # select
72
+                    return 2
73
             elif keys.once("up"):
73
             elif keys.once("up"):
74
                 if self.current == None:
74
                 if self.current == None:
75
                     self.current = len(self.results) - 1
75
                     self.current = len(self.results) - 1
83
 
83
 
84
             self.draw_list()
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
         keys = self.lcd.buttons()
37
         keys = self.lcd.buttons()
38
 
38
 
39
         if keys.once("y"):
39
         if keys.once("y"):
40
-            print("user abort")
41
-            return 5 # disconnect
40
+            return 5
42
         elif keys.once("up"):
41
         elif keys.once("up"):
43
             if self.current > 0:
42
             if self.current > 0:
44
                 self.current -= 1
43
                 self.current -= 1
46
             if self.current < (len(workflows) - 1):
45
             if self.current < (len(workflows) - 1):
47
                 self.current += 1
46
                 self.current += 1
48
         elif keys.once("enter"):
47
         elif keys.once("enter"):
49
-            return 1 # connect
48
+            return 1
50
 
49
 
51
         self.draw_list()
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
         lcd.text("{} -> {} -> {}".format(min, val, max), 0, int(lcd.height / 2) - 5, lcd.white)
8
         lcd.text("{} -> {} -> {}".format(min, val, max), 0, int(lcd.height / 2) - 5, lcd.white)
9
         return
9
         return
10
 
10
 
11
-    w = lcd.width - 10
12
     ratio = (val - min) / (max - min)
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
 class StateWaitTemp:
16
 class StateWaitTemp:
24
     def __init__(self, lcd):
17
     def __init__(self, lcd):
28
 
21
 
29
     def enter(self, val = None):
22
     def enter(self, val = None):
30
         self.value = val
23
         self.value = val
31
-        self.poller = asyncio.create_task(self.poll())
32
         self.temp = 0.0
24
         self.temp = 0.0
33
         self.min = 0.0
25
         self.min = 0.0
34
         self.max = 100.0
26
         self.max = 100.0
27
+        self.poller = asyncio.create_task(self.poll())
35
 
28
 
36
     def exit(self):
29
     def exit(self):
37
         self.poller.cancel()
30
         self.poller.cancel()
49
             self.max = workflow["steps"][index][0]
42
             self.max = workflow["steps"][index][0]
50
 
43
 
51
         temp = await get_current_temp(device)
44
         temp = await get_current_temp(device)
52
-        print("initial temp: {}".format(temp))
53
         async with self.lock:
45
         async with self.lock:
54
             self.temp = temp
46
             self.temp = temp
55
             self.min = temp
47
             self.min = temp
56
 
48
 
57
-        print("Setting temperature: {}".format(self.max))
58
         await set_target_temp(device, self.max)
49
         await set_target_temp(device, self.max)
59
 
50
 
60
         while temp < self.max:
51
         while temp < self.max:
61
             temp = await get_current_temp(device)
52
             temp = await get_current_temp(device)
62
-            print("now at {}".format(temp))
63
             async with self.lock:
53
             async with self.lock:
64
                 self.temp = temp
54
                 self.temp = temp
65
 
55
 
70
         keys = self.lcd.buttons()
60
         keys = self.lcd.buttons()
71
 
61
 
72
         if keys.once("y"):
62
         if keys.once("y"):
73
-            print("user abort")
74
-            return 4 # heat off
63
+            return 4
75
 
64
 
76
         async with self.lock:
65
         async with self.lock:
77
             if self.temp == 0.0:
66
             if self.temp == 0.0:
80
                 draw_graph(self.lcd, self.min, self.temp, self.max)
69
                 draw_graph(self.lcd, self.min, self.temp, self.max)
81
 
70
 
82
             if self.temp >= self.max:
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
         keys = self.lcd.buttons()
24
         keys = self.lcd.buttons()
25
 
25
 
26
         if keys.once("y"):
26
         if keys.once("y"):
27
-            print("user abort")
28
-            return 4 # heat off
27
+            return 4
29
 
28
 
30
         now = time.time()
29
         now = time.time()
31
         draw_graph(self.lcd, 0.0, now - self.start, self.end - self.start)
30
         draw_graph(self.lcd, 0.0, now - self.start, self.end - self.start)
32
 
31
 
33
         if now >= self.end:
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
 
34
 
35
         next = asyncio.run(self.draw())
35
         next = asyncio.run(self.draw())
36
         if next >= 0:
36
         if next >= 0:
37
-            print("switch to {}".format(next))
38
             val = self.states[self.current].exit()
37
             val = self.states[self.current].exit()
39
             self.current = next
38
             self.current = next
40
             self.states[self.current].enter(val)
39
             self.states[self.current].enter(val)
46
     states = States(lcd)
45
     states = States(lcd)
47
 
46
 
48
     # 0 - Scan
47
     # 0 - Scan
49
-    # passes ScanResult to 2, select
50
     scan = StateScan(lcd)
48
     scan = StateScan(lcd)
51
     states.add(scan)
49
     states.add(scan)
52
 
50
 
53
     # 1 - Connect
51
     # 1 - Connect
54
-    # passes device and selected workflow to 3, heater on
55
     conn = StateConnect(lcd, True)
52
     conn = StateConnect(lcd, True)
56
     states.add(conn)
53
     states.add(conn)
57
 
54
 
58
     # 2 - Select
55
     # 2 - Select
59
-    # passes ScanResult and selected workflow to 1, connect
60
     select = StateSelect(lcd)
56
     select = StateSelect(lcd)
61
     states.add(select)
57
     states.add(select)
62
 
58
 

Loading…
Cancel
Save