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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. self.menuOff = 0
  11. def exit(self):
  12. return self.client, workflows[self.current]
  13. def draw_list(self):
  14. for i, wf in enumerate(workflows):
  15. if i < self.menuOff:
  16. continue
  17. off = (i - self.menuOff) * 25 + 30
  18. if off >= (self.lcd.height - 10):
  19. break
  20. s1 = "{}".format(wf["name"])
  21. s2 = "by: {}".format(wf["author"])
  22. c = self.lcd.white
  23. if self.current == i:
  24. c = self.lcd.red
  25. self.lcd.hline(0, off, self.lcd.width, self.lcd.blue)
  26. self.lcd.text(s1, 0, off + 2, c)
  27. self.lcd.text(s2, 0, off + 12, c)
  28. async def draw(self):
  29. self.lcd.text("Please select your Workflow", 0, 10, self.lcd.red)
  30. keys = self.lcd.buttons()
  31. if keys.once("y"):
  32. return 0
  33. elif keys.once("up"):
  34. self.current -= 1
  35. elif keys.once("down"):
  36. self.current += 1
  37. elif keys.once("enter") or keys.once("a"):
  38. return 1
  39. while self.current < 0:
  40. self.current += len(workflows)
  41. while self.current >= len(workflows):
  42. self.current -= len(workflows)
  43. while self.current < self.menuOff:
  44. self.menuOff -= 1
  45. while self.current >= (self.menuOff + int((self.lcd.height - 30 - 10) / 25)):
  46. self.menuOff += 1
  47. self.draw_list()
  48. return -1