S&B Volcano vaporizer remote control with Pi Pico W
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

state_notify.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 * 6
  26. for i in range(0, count):
  27. await asyncio.sleep_ms(int(duration * 500))
  28. async with self.lock:
  29. self.step += 1
  30. await asyncio.sleep_ms(int(duration * 500))
  31. async with self.lock:
  32. self.step += 1
  33. await set_state(device, (None, True))
  34. async with self.lock:
  35. self.step += 1
  36. await asyncio.sleep_ms(int(duration * 500))
  37. async with self.lock:
  38. self.step += 1
  39. await asyncio.sleep_ms(int(duration * 500))
  40. async with self.lock:
  41. self.step += 1
  42. await set_state(device, (None, False))
  43. async with self.lock:
  44. self.step += 1
  45. async with self.lock:
  46. self.done = True
  47. async def draw(self):
  48. self.lcd.text("Running Workflow - Notify", 0, 10, self.lcd.red)
  49. keys = self.lcd.buttons()
  50. if keys.once("y"):
  51. return 4
  52. async with self.lock:
  53. draw_graph(self.lcd, 0, self.step, self.max)
  54. if self.done:
  55. return 4
  56. return -1