S&B Volcano vaporizer remote control with Pi Pico W
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. import uasyncio as asyncio
  3. from poll import set_state, set_target_temp
  4. class StateHeat:
  5. def __init__(self, lcd, state):
  6. self.lcd = lcd
  7. self.state = state
  8. self.lock = asyncio.Lock()
  9. def enter(self, val = None):
  10. self.value = val
  11. self.done = False
  12. self.step = False
  13. self.heater = asyncio.create_task(self.heat())
  14. def exit(self):
  15. self.heater.cancel()
  16. if self.lock.locked():
  17. self.lock.release()
  18. return (self.value[0], self.value[1], 0)
  19. async def heat(self):
  20. pump = None
  21. if self.state == False:
  22. pump = False
  23. await set_state(self.value[0], (self.state, pump))
  24. if self.state == False:
  25. async with self.lock:
  26. self.step = True
  27. temp = self.value[1]["reset_temperature"]
  28. if temp != None:
  29. await set_target_temp(self.value[0], temp)
  30. async with self.lock:
  31. self.done = True
  32. async def draw(self):
  33. self.lcd.text("Running Workflow - Heat {}".format(self.state), 0, 10, self.lcd.red)
  34. keys = self.lcd.buttons()
  35. if keys.once("y"):
  36. if self.state:
  37. async with self.lock:
  38. if self.done:
  39. return 4
  40. else:
  41. return 5
  42. else:
  43. return 5
  44. async with self.lock:
  45. if self.done:
  46. if self.state == False:
  47. return 5
  48. else:
  49. return 6
  50. else:
  51. if self.state == False:
  52. if self.state == False:
  53. self.lcd.textC("Turning heater off...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  54. else:
  55. self.lcd.textC("Resetting temperature...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  56. else:
  57. self.lcd.textC("Turning heater on...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  58. return -1