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.

state_wait_temp.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python
  2. import uasyncio as asyncio
  3. from poll import set_target_temp, get_current_temp
  4. def draw_graph(lcd, min, val, max):
  5. if max == min:
  6. lcd.textC("{} -> {} -> {}".format(min, val, max), int(self.lcd.width / 2), int(lcd.height / 2), lcd.white)
  7. return
  8. ratio = (val - min) / (max - min)
  9. lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width - 30, lcd.red, lcd.green, ratio)
  10. lcd.textC("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
  11. class StateWaitTemp:
  12. def __init__(self, lcd):
  13. self.lcd = lcd
  14. self.lock = asyncio.Lock()
  15. def enter(self, val = None):
  16. self.value = val
  17. self.temp = 0.0
  18. self.min = 0.0
  19. self.max = 100.0
  20. self.poller = asyncio.create_task(self.poll())
  21. def exit(self):
  22. self.poller.cancel()
  23. if self.lock.locked():
  24. self.lock.release()
  25. return (self.value[0], self.value[1], self.value[2])
  26. async def poll(self):
  27. device, workflow, index = self.value
  28. async with self.lock:
  29. self.temp = 0.0
  30. self.min = 0.0
  31. self.max = workflow["steps"][index][0]
  32. temp = await get_current_temp(device)
  33. async with self.lock:
  34. self.temp = temp
  35. self.min = temp
  36. await set_target_temp(device, self.max)
  37. while temp < self.max:
  38. temp = await get_current_temp(device)
  39. async with self.lock:
  40. self.temp = temp
  41. async def draw(self):
  42. device, workflow, index = self.value
  43. self.lcd.text("Running Workflow - Heat {}".format(workflow["steps"][index][0]), 0, 10, self.lcd.red)
  44. keys = self.lcd.buttons()
  45. if keys.once("y"):
  46. return 4
  47. async with self.lock:
  48. if self.temp == 0.0:
  49. self.lcd.textC("Setting temperature...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
  50. else:
  51. draw_graph(self.lcd, self.min, self.temp, self.max)
  52. if self.temp >= self.max:
  53. return 7
  54. return -1