S&B Volcano vaporizer remote control with Pi Pico W
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

state_select.py 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. self.lcd.store_brightness()
  28. return self.client, workflows[self.current]
  29. def draw_list(self):
  30. for i, wf in enumerate(workflows):
  31. if i < self.menuOff:
  32. continue
  33. off = (i - self.menuOff) * 25 + 30
  34. if off >= (self.lcd.height - 10):
  35. break
  36. s1 = "{}".format(wf["name"])
  37. s2 = "by: {}".format(wf["author"])
  38. c = self.lcd.white
  39. if self.current == i:
  40. c = self.lcd.red
  41. self.lcd.hline(0, off - 3, self.lcd.width, self.lcd.blue)
  42. self.lcd.text(s1, 0, off + 2, c)
  43. self.lcd.text(s2, 0, off + 12, c)
  44. async def draw(self):
  45. self.lcd.text("Please select your Workflow", 0, 10, self.lcd.red)
  46. keys = self.lcd.buttons()
  47. if keys.once("y"):
  48. return 0
  49. elif keys.once("up"):
  50. self.current -= 1
  51. elif keys.once("down"):
  52. self.current += 1
  53. elif keys.once("enter") or keys.once("a"):
  54. return 1
  55. elif keys.held("left"):
  56. v = self.lcd.curr_brightness - 0.05
  57. if v < 0.05:
  58. v = 0.05
  59. self.lcd.brightness(v)
  60. elif keys.held("right"):
  61. self.lcd.brightness(self.lcd.curr_brightness + 0.05)
  62. while self.current < 0:
  63. self.current += len(workflows)
  64. while self.current >= len(workflows):
  65. self.current -= len(workflows)
  66. while self.current < self.menuOff:
  67. self.menuOff -= 1
  68. while self.current >= (self.menuOff + int((self.lcd.height - 30 - 10) / 25)):
  69. self.menuOff += 1
  70. self.draw_list()
  71. w = int(self.lcd.width * self.lcd.curr_brightness)
  72. self.lcd.hline(0, 24, w, self.lcd.white)
  73. return -1