S&B Volcano vaporizer remote control with Pi Pico W
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

state_heat.py 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python3
  2. # ----------------------------------------------------------------------------
  3. # Copyright (c) 2023 Thomas Buck (thomas@xythobuz.de)
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # See <http://www.gnu.org/licenses/>.
  16. # ----------------------------------------------------------------------------
  17. import uasyncio as asyncio
  18. from poll import set_state, set_target_temp
  19. class StateHeat:
  20. def __init__(self, lcd, state):
  21. self.lcd = lcd
  22. self.state = state
  23. self.lock = asyncio.Lock()
  24. def enter(self, val = None):
  25. self.value = val
  26. self.done = False
  27. self.step = False
  28. self.heater = asyncio.create_task(self.heat())
  29. def exit(self):
  30. self.heater.cancel()
  31. if self.lock.locked():
  32. self.lock.release()
  33. return (self.value[0], self.value[1], 0)
  34. async def heat(self):
  35. pump = None
  36. if self.state == False:
  37. pump = False
  38. await set_state(self.value[0], (self.state, pump))
  39. if self.state == False:
  40. async with self.lock:
  41. self.step = True
  42. temp = self.value[1]["reset_temperature"]
  43. if temp != None:
  44. await set_target_temp(self.value[0], temp)
  45. async with self.lock:
  46. self.done = True
  47. async def draw(self):
  48. self.lcd.text("Running Workflow - Heat {}".format(self.state), 0, 10, self.lcd.red)
  49. keys = self.lcd.buttons()
  50. if keys.once("y"):
  51. if self.state:
  52. async with self.lock:
  53. if self.done:
  54. return 4
  55. else:
  56. return 5
  57. else:
  58. return 5
  59. async with self.lock:
  60. if self.done:
  61. if self.state == False:
  62. return 5
  63. else:
  64. return 6
  65. else:
  66. if self.state == False:
  67. if self.state == False:
  68. self.lcd.textC("Turning heater off...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  69. else:
  70. self.lcd.textC("Resetting temperature...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  71. else:
  72. self.lcd.textC("Turning heater on...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  73. return -1