Browse Source

tweak rp2040 mvp, now mostly usable but with timing issues

Thomas Buck 8 months ago
parent
commit
fd75860c07
2 changed files with 32 additions and 24 deletions
  1. 17
    18
      python-test/flow.py
  2. 15
    6
      python-test/poll.py

+ 17
- 18
python-test/flow.py View File

@@ -16,14 +16,10 @@ def print_bar(value, start, end, unit):
16 16
     print("{}{} -> {}{} -> {}{}".format(start, unit, value, unit, end, unit))
17 17
 
18 18
 def sleep(t):
19
-    w = terminal_width
20
-    if t < w:
21
-        w = int(t)
22
-    print_bar(0, 0, w, "s")
23
-    for i in range(0, w):
24
-        time.sleep(t / w)
25
-        print_bar(i + 1, 0, w, "s")
26
-    print()
19
+    print_bar(0, 0, t, "s")
20
+    for i in range(0, t):
21
+        time.sleep(1.0)
22
+        print_bar(i + 1, 0, t, "s")
27 23
 
28 24
 async def wait_for_temp(client, temp):
29 25
     print("Setting temperature {}".format(temp))
@@ -56,21 +52,24 @@ async def flow(client):
56 52
     print("Turning on heater")
57 53
     await set_state(client, (True, False))
58 54
 
59
-    await flow_step(client, 190.0, 20.0, 5.0)
60
-    await flow_step(client, 205.0, 10.0, 20.0)
61
-    await flow_step(client, 220.0, 10.0, 20.0)
55
+    await flow_step(client, 190.0, 20.0, 5.0 - 4.9)
56
+    await flow_step(client, 205.0, 10.0, 20.0 - 7)
57
+    await flow_step(client, 220.0, 10.0, 20.0 - 7)
62 58
 
63
-    print("Notification by pumping three times...")
64
-    for i in range(0, 3):
65
-        time.sleep(1.0)
66
-        await set_state(client, (True, True)) # turn on pump
67
-        time.sleep(1.0)
68
-        await set_state(client, (True, False)) # turn off pump
59
+    #print("Notification by pumping three times...")
60
+    #for i in range(0, 3):
61
+    #    time.sleep(1.0 / 3)
62
+    #    await set_state(client, (True, True)) # turn on pump
63
+    #    time.sleep(1.0 / 3)
64
+    #    await set_state(client, (True, False)) # turn off pump
69 65
 
70 66
     print("Turning heater off")
71 67
     await set_state(client, (False, False)) # turn off heater and pump
72 68
 
73
-if __name__ == "__main__":
69
+    print("Setting temperature back to 190")
70
+    await set_target_temp(client, 190.0)
71
+
72
+if True:#__name__ == "__main__":
74 73
     async def main(address):
75 74
         client = await ble_conn(address)
76 75
 

+ 15
- 6
python-test/poll.py View File

@@ -37,12 +37,21 @@ async def get_target_temp(device):
37 37
     return num / 10.0
38 38
 
39 39
 async def set_target_temp(device, temp):
40
-    val = int(temp * 10.0)
41
-    d = val.to_bytes(4, "little")
42
-    service = await device.service(serviceUuidVolcano4)
43
-    uuid = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
44
-    characteristic = await service.characteristic(uuid)
45
-    await characteristic.write(d)
40
+    attempts = 3
41
+    while attempts > 0:
42
+        val = int(temp * 10.0)
43
+        d = val.to_bytes(4, "little")
44
+        service = await device.service(serviceUuidVolcano4)
45
+        uuid = bluetooth.UUID("10110003-5354-4f52-5a26-4249434b454c")
46
+        characteristic = await service.characteristic(uuid)
47
+        await characteristic.write(d)
48
+
49
+        attempts -= 1
50
+
51
+        target = await get_target_temp(device)
52
+        if abs(target - temp) < 0.5:
53
+            return
54
+    raise RuntimeError("Could not set target temperature")
46 55
 
47 56
 async def get_unit_is_fahrenheit(device):
48 57
     service = await device.service(serviceUuidVolcano3)

Loading…
Cancel
Save