S&B Volcano vaporizer remote control with Pi Pico W
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

state_pump.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.done = False
  13. device, workflow, index = self.value
  14. self.start = None
  15. self.duration = workflow["steps"][index][2]
  16. self.pumper = asyncio.create_task(self.pump())
  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. await set_state(device, (None, True))
  25. async with self.lock:
  26. self.start = time.time()
  27. await asyncio.sleep_ms(int(self.duration * 1000))
  28. await set_state(device, (None, False))
  29. async with self.lock:
  30. self.done = True
  31. async def draw(self):
  32. device, workflow, index = self.value
  33. self.lcd.text("Running Workflow - Pump {}".format(workflow["steps"][index][2]), 0, 10, self.lcd.red)
  34. keys = self.lcd.buttons()
  35. if keys.once("y"):
  36. return 4
  37. async with self.lock:
  38. if self.start != None:
  39. now = time.time()
  40. if now - self.start <= self.duration:
  41. draw_graph(self.lcd, 0.0, now - self.start, self.duration)
  42. else:
  43. self.lcd.textC("Turning off pump...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  44. else:
  45. self.lcd.textC("Turning on pump...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  46. if self.done:
  47. if self.value[2] >= (len(workflow["steps"]) - 1):
  48. if workflow["notify"] != None:
  49. return 9
  50. else:
  51. return 4
  52. else:
  53. return 6
  54. return -1