S&B Volcano vaporizer remote control with Pi Pico W
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

states.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. def state_machine(lcd):
  26. states = States(lcd)
  27. # 0 - Scan
  28. from state_scan import StateScan
  29. scan = StateScan(lcd)
  30. states.add(scan)
  31. # 1 - Connect
  32. from state_connect import StateConnect
  33. conn = StateConnect(lcd, True)
  34. states.add(conn)
  35. # 2 - Select
  36. from state_select import StateSelect
  37. select = StateSelect(lcd)
  38. states.add(select)
  39. # 3 - Heater On
  40. from state_heat import StateHeat
  41. heatOn = StateHeat(lcd, True)
  42. states.add(heatOn)
  43. # 4 - Heater Off
  44. heatOff = StateHeat(lcd, False)
  45. states.add(heatOff)
  46. # 5 - Disconnect
  47. disconn = StateConnect(lcd, False)
  48. states.add(disconn)
  49. # 6 - Wait for temperature
  50. from state_wait_temp import StateWaitTemp
  51. waitTemp = StateWaitTemp(lcd)
  52. states.add(waitTemp)
  53. # 7 - Wait for time
  54. from state_wait_time import StateWaitTime
  55. waitTime = StateWaitTime(lcd)
  56. states.add(waitTime)
  57. # 8 - Pump
  58. from state_pump import StatePump
  59. pump = StatePump(lcd)
  60. states.add(pump)
  61. # 9 - Notify
  62. from state_notify import StateNotify
  63. notify = StateNotify(lcd)
  64. states.add(notify)
  65. while True:
  66. states.run()
  67. from lcd import LCD
  68. lcd = LCD()
  69. lcd.brightness(1.0)
  70. try:
  71. state_machine(lcd)
  72. except Exception as e:
  73. lcd.fill(lcd.black)
  74. lcd.textC(str(e), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
  75. lcd.show()
  76. raise e