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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 workflows import workflows
  19. class StateSelect:
  20. def __init__(self, lcd):
  21. self.lcd = lcd
  22. def enter(self, val = None):
  23. self.client = val
  24. self.current = 0
  25. self.menuOff = 0
  26. def exit(self):
  27. return self.client, workflows[self.current]
  28. def draw_list(self):
  29. for i, wf in enumerate(workflows):
  30. if i < self.menuOff:
  31. continue
  32. off = (i - self.menuOff) * 25 + 30
  33. if off >= (self.lcd.height - 10):
  34. break
  35. s1 = "{}".format(wf["name"])
  36. s2 = "by: {}".format(wf["author"])
  37. c = self.lcd.white
  38. if self.current == i:
  39. c = self.lcd.red
  40. self.lcd.hline(0, off, self.lcd.width, self.lcd.blue)
  41. self.lcd.text(s1, 0, off + 2, c)
  42. self.lcd.text(s2, 0, off + 12, c)
  43. async def draw(self):
  44. self.lcd.text("Please select your Workflow", 0, 10, self.lcd.red)
  45. keys = self.lcd.buttons()
  46. if keys.once("y"):
  47. return 0
  48. elif keys.once("up"):
  49. self.current -= 1
  50. elif keys.once("down"):
  51. self.current += 1
  52. elif keys.once("enter") or keys.once("a"):
  53. return 1
  54. while self.current < 0:
  55. self.current += len(workflows)
  56. while self.current >= len(workflows):
  57. self.current -= len(workflows)
  58. while self.current < self.menuOff:
  59. self.menuOff -= 1
  60. while self.current >= (self.menuOff + int((self.lcd.height - 30 - 10) / 25)):
  61. self.menuOff += 1
  62. self.draw_list()
  63. return -1