S&B Volcano vaporizer remote control with Pi Pico W
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

state_wait_temp.py 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.text("{} -> {} -> {}".format(min, val, max), 0, 100, lcd.white)
  7. return
  8. w = lcd.width - 10
  9. ratio = (val - min) / (max - min)
  10. wfull = int(w * ratio)
  11. wempty = w - wfull
  12. lcd.rect(4, 100, wfull + 1, 50, lcd.green, True)
  13. lcd.rect(4 + wfull, 100, wempty + 2, 50, lcd.green, False)
  14. lcd.text("{}".format(val), int(lcd.width / 2), 125, lcd.white)
  15. class StateWaitTemp:
  16. def __init__(self, lcd):
  17. self.lcd = lcd
  18. self.lock = asyncio.Lock()
  19. def enter(self, val = None):
  20. self.value = val
  21. self.poller = asyncio.create_task(self.poll())
  22. self.temp = 0.0
  23. self.min = 0.0
  24. self.max = 100.0
  25. def exit(self):
  26. self.poller.cancel()
  27. if self.lock.locked():
  28. self.lock.release()
  29. return (self.value[0], self.value[1], self.value[2])
  30. async def poll(self):
  31. device, workflow, index = self.value
  32. async with self.lock:
  33. self.temp = 0.0
  34. self.min = 0.0
  35. self.max = workflow["steps"][index][0]
  36. temp = await get_current_temp(device)
  37. print("initial temp: {}".format(temp))
  38. async with self.lock:
  39. self.temp = temp
  40. self.min = temp
  41. print("Setting temperature: {}".format(self.max))
  42. await set_target_temp(device, self.max)
  43. while temp < self.max:
  44. temp = await get_current_temp(device)
  45. print("now at {}".format(temp))
  46. async with self.lock:
  47. self.temp = temp
  48. async def draw(self):
  49. self.lcd.fill(self.lcd.black)
  50. device, workflow, index = self.value
  51. self.lcd.text("Volcano Remote Control App", 0, 0, self.lcd.green)
  52. self.lcd.text("Running Workflow - Heat {}".format(workflow["steps"][index][0]), 0, 10, self.lcd.red)
  53. keys = self.lcd.buttons()
  54. if keys.once("y"):
  55. print("user abort")
  56. return 4 # heat off
  57. async with self.lock:
  58. if self.temp == 0.0:
  59. self.lcd.text("Setting temperature...", 0, 100, self.lcd.white)
  60. else:
  61. draw_graph(self.lcd, self.min, self.temp, self.max)
  62. if self.temp >= self.max:
  63. print("switch, {} >= {}".format(self.temp, self.max))
  64. return 7 # wait for time
  65. self.lcd.show()
  66. return -1 # stay in this state