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_select.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env python
  2. import uasyncio as asyncio
  3. from workflows import workflows
  4. class StateSelect:
  5. def __init__(self, lcd):
  6. self.lcd = lcd
  7. def enter(self, val = None):
  8. self.client = val
  9. self.current = 0
  10. def exit(self):
  11. return self.client, workflows[self.current]
  12. def draw_list(self):
  13. for i, wf in enumerate(workflows):
  14. s1 = "{}".format(wf["name"])
  15. s2 = "by: {}".format(wf["author"])
  16. off = i * 25 + 30
  17. if off >= self.lcd.height:
  18. break
  19. c = self.lcd.white
  20. if self.current == i:
  21. c = self.lcd.red
  22. self.lcd.hline(0, off, self.lcd.width, self.lcd.blue)
  23. self.lcd.text(s1, 0, off + 2, c)
  24. self.lcd.text(s2, 0, off + 12, c)
  25. async def draw(self):
  26. self.lcd.text("Please select your Workflow", 0, 10, self.lcd.red)
  27. keys = self.lcd.buttons()
  28. if keys.once("y"):
  29. print("user abort")
  30. return 5 # disconnect
  31. elif keys.once("up"):
  32. if self.current > 0:
  33. self.current -= 1
  34. elif keys.once("down"):
  35. if self.current < (len(workflows) - 1):
  36. self.current += 1
  37. elif keys.once("enter"):
  38. return 1 # connect
  39. self.draw_list()
  40. return -1 # stay in this state