S&B Volcano vaporizer remote control with Pi Pico W
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

state_notify.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.done = False
  13. self.step = 0
  14. self.max = 0
  15. self.notifier = asyncio.create_task(self.notify())
  16. def exit(self):
  17. self.notifier.cancel()
  18. if self.lock.locked():
  19. self.lock.release()
  20. return (self.value[0], self.value[1], self.value[2])
  21. async def notify(self):
  22. device, workflow, index = self.value
  23. count, duration = workflow["notify"]
  24. async with self.lock:
  25. self.max = count * 2
  26. for i in range(0, count):
  27. await asyncio.sleep_ms(int(duration * 1000))
  28. await set_state(device, (None, True))
  29. async with self.lock:
  30. self.step += 1
  31. await asyncio.sleep_ms(int(duration * 1000))
  32. await set_state(device, (None, False))
  33. async with self.lock:
  34. self.step += 1
  35. async with self.lock:
  36. self.done = True
  37. async def draw(self):
  38. self.lcd.text("Running Workflow - Notify", 0, 10, self.lcd.red)
  39. keys = self.lcd.buttons()
  40. if keys.once("y"):
  41. return 4
  42. async with self.lock:
  43. draw_graph(self.lcd, 0, self.step, self.max)
  44. if self.done:
  45. return 4
  46. return -1