S&B Volcano vaporizer remote control with Pi Pico W
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

state_notify.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. import time
  3. import uasyncio as asyncio
  4. from poll import set_state
  5. from state_wait_temp import draw_graph
  6. class StateNotify:
  7. def __init__(self, lcd):
  8. self.lcd = lcd
  9. self.lock = asyncio.Lock()
  10. def enter(self, val = None):
  11. self.value = val
  12. self.notifier = asyncio.create_task(self.notify())
  13. self.done = False
  14. def exit(self):
  15. self.notifier.cancel()
  16. if self.lock.locked():
  17. self.lock.release()
  18. return (self.value[0], self.value[1], self.value[2])
  19. async def notify(self):
  20. device, workflow, index = self.value
  21. count, duration = workflow["notify"]
  22. for i in range(0, count):
  23. print("Turning on pump")
  24. await set_state(device, (None, True))
  25. await asyncio.sleep_ms(int(duration * 1000))
  26. print("Turning off pump")
  27. await set_state(device, (None, False))
  28. await asyncio.sleep_ms(int(duration * 1000))
  29. async with self.lock:
  30. self.done = True
  31. async def draw(self):
  32. self.lcd.text("Running Workflow - Notify", 0, 10, self.lcd.red)
  33. keys = self.lcd.buttons()
  34. if keys.once("y"):
  35. print("user abort")
  36. return 4 # heat off
  37. async with self.lock:
  38. if self.done:
  39. return 4 # heater off
  40. return -1 # stay in this state