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.

states.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env python
  2. import uasyncio as asyncio
  3. class States:
  4. def __init__(self, lcd):
  5. self.lcd = lcd
  6. self.states = []
  7. self.current = None
  8. def add(self, s):
  9. self.states.append(s)
  10. async def draw(self):
  11. self.lcd.fill(self.lcd.black)
  12. self.lcd.text("Volcano Remote Control App", 0, 0, self.lcd.green)
  13. r = await self.states[self.current].draw()
  14. self.lcd.show()
  15. return r
  16. def run(self):
  17. if self.current == None:
  18. self.current = 0
  19. self.states[self.current].enter()
  20. next = asyncio.run(self.draw())
  21. if next >= 0:
  22. val = self.states[self.current].exit()
  23. self.current = next
  24. self.states[self.current].enter(val)
  25. from lcd import LCD
  26. lcd = LCD()
  27. lcd.brightness(1.0)
  28. try:
  29. states = States(lcd)
  30. # 0 - Scan
  31. from state_scan import StateScan
  32. scan = StateScan(lcd)
  33. states.add(scan)
  34. # 1 - Connect
  35. from state_connect import StateConnect
  36. conn = StateConnect(lcd, True)
  37. states.add(conn)
  38. # 2 - Select
  39. from state_select import StateSelect
  40. select = StateSelect(lcd)
  41. states.add(select)
  42. # 3 - Heater On
  43. from state_heat import StateHeat
  44. heatOn = StateHeat(lcd, True)
  45. states.add(heatOn)
  46. # 4 - Heater Off
  47. heatOff = StateHeat(lcd, False)
  48. states.add(heatOff)
  49. # 5 - Disconnect
  50. disconn = StateConnect(lcd, False)
  51. states.add(disconn)
  52. # 6 - Wait for temperature
  53. from state_wait_temp import StateWaitTemp
  54. waitTemp = StateWaitTemp(lcd)
  55. states.add(waitTemp)
  56. # 7 - Wait for time
  57. from state_wait_time import StateWaitTime
  58. waitTime = StateWaitTime(lcd)
  59. states.add(waitTime)
  60. # 8 - Pump
  61. from state_pump import StatePump
  62. pump = StatePump(lcd)
  63. states.add(pump)
  64. # 9 - Notify
  65. from state_notify import StateNotify
  66. notify = StateNotify(lcd)
  67. states.add(notify)
  68. while True:
  69. states.run()
  70. except Exception as e:
  71. lcd.fill(self.lcd.black)
  72. lcd.text(str(e), 0, int(lcd.height / 2) - 5, lcd.white)
  73. lcd.show()