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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 StatePump:
  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.pumper = asyncio.create_task(self.pump())
  13. self.done = False
  14. device, workflow, index = self.value
  15. self.start = None
  16. self.duration = workflow["steps"][index][2]
  17. def exit(self):
  18. self.pumper.cancel()
  19. if self.lock.locked():
  20. self.lock.release()
  21. return (self.value[0], self.value[1], self.value[2] + 1)
  22. async def pump(self):
  23. device, workflow, index = self.value
  24. print("Turning on pump")
  25. await set_state(device, (None, True))
  26. async with self.lock:
  27. self.start = time.time()
  28. await asyncio.sleep_ms(int(self.duration * 1000))
  29. print("Turning off pump")
  30. await set_state(device, (None, False))
  31. async with self.lock:
  32. self.done = True
  33. async def draw(self):
  34. self.lcd.fill(self.lcd.black)
  35. device, workflow, index = self.value
  36. self.lcd.text("Volcano Remote Control App", 0, 0, self.lcd.green)
  37. self.lcd.text("Running Workflow - Pump {}".format(workflow["steps"][index][2]), 0, 10, self.lcd.red)
  38. keys = self.lcd.buttons()
  39. if keys.once("y"):
  40. print("user abort")
  41. return 4 # heat off
  42. async with self.lock:
  43. if self.start != None:
  44. draw_graph(self.lcd, 0.0, time.time() - self.start, self.duration)
  45. else:
  46. self.lcd.text("Turning on pump...", 0, 100, self.lcd.white)
  47. if self.done:
  48. if self.value[2] >= (len(workflow["steps"]) - 1):
  49. # TODO notify
  50. return 4 # heater off
  51. else:
  52. return 6 # wait for temperature
  53. self.lcd.show()
  54. return -1 # stay in this state