瀏覽代碼

menu scrolling and other tweaks

Thomas Buck 8 月之前
父節點
當前提交
f3e6315157
共有 5 個檔案被更改,包括 64 行新增26 行删除
  1. 19
    15
      python-test/lcd.py
  2. 36
    7
      python-test/state_scan.py
  3. 1
    1
      python-test/state_select.py
  4. 7
    2
      python-test/states.py
  5. 1
    1
      python-test/workflows.py

+ 19
- 15
python-test/lcd.py 查看文件

@@ -41,11 +41,12 @@ class LCD(framebuf.FrameBuffer):
41 41
         super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
42 42
         self.init_display()
43 43
 
44
-        self.red   = 0x07E0
45
-        self.green = 0x001f
46
-        self.blue  = 0xf800
47
-        self.white = 0xffff
48
-        self.black = 0x0000
44
+        self.red    = self.color(0xFF, 0x00, 0x00)
45
+        self.green  = self.color(0x00, 0xFF, 0x00)
46
+        self.blue   = self.color(0x00, 0x00, 0xFF)
47
+        self.yellow = self.color(0xFF, 0xFF, 0x00)
48
+        self.white  = self.color(0xFF, 0xFF, 0xFF)
49
+        self.black  = self.color(0x00, 0x00, 0x00)
49 50
 
50 51
         self.fill(self.black)
51 52
         self.show()
@@ -54,16 +55,15 @@ class LCD(framebuf.FrameBuffer):
54 55
         self.pwm.freq(1000)
55 56
         self.brightness(0.0)
56 57
 
57
-        self.keyA = Pin(15,Pin.IN,Pin.PULL_UP)
58
-        self.keyB = Pin(17,Pin.IN,Pin.PULL_UP)
59
-        self.keyX = Pin(19 ,Pin.IN,Pin.PULL_UP)
60
-        self.keyY= Pin(21 ,Pin.IN,Pin.PULL_UP)
61
-
62
-        self.up = Pin(2,Pin.IN,Pin.PULL_UP)
63
-        self.down = Pin(18,Pin.IN,Pin.PULL_UP)
64
-        self.left = Pin(16,Pin.IN,Pin.PULL_UP)
65
-        self.right = Pin(20,Pin.IN,Pin.PULL_UP)
66
-        self.ctrl = Pin(3,Pin.IN,Pin.PULL_UP)
58
+        self.keyA  = Pin(15, Pin.IN, Pin.PULL_UP)
59
+        self.keyB  = Pin(17, Pin.IN, Pin.PULL_UP)
60
+        self.keyX  = Pin(19, Pin.IN, Pin.PULL_UP)
61
+        self.keyY  = Pin(21, Pin.IN, Pin.PULL_UP)
62
+        self.up    = Pin( 2, Pin.IN, Pin.PULL_UP)
63
+        self.down  = Pin(18, Pin.IN, Pin.PULL_UP)
64
+        self.left  = Pin(16, Pin.IN, Pin.PULL_UP)
65
+        self.right = Pin(20, Pin.IN, Pin.PULL_UP)
66
+        self.ctrl  = Pin( 3, Pin.IN, Pin.PULL_UP)
67 67
 
68 68
         self.keys_old = {
69 69
             "a": False,
@@ -93,6 +93,10 @@ class LCD(framebuf.FrameBuffer):
93 93
         self.keys_old = keys.copy()
94 94
         return kc
95 95
 
96
+    # Convert RGB888 to RGB565
97
+    def color(self, R, G, B):
98
+        return (((G & 0b00011100) << 3) + ((B & 0b11111000) >> 3) << 8) + (R & 0b11111000) + ((G & 0b11100000) >> 5)
99
+
96 100
     def brightness(self, v):
97 101
         self.pwm.duty_u16(int(v * 65535))
98 102
 

+ 36
- 7
python-test/state_scan.py 查看文件

@@ -11,8 +11,10 @@ class StateScan:
11 11
         self.lock = asyncio.Lock()
12 12
 
13 13
     def enter(self, val = None):
14
+        n = None
14 15
         self.results = []
15 16
         self.current = None
17
+        self.menuOff = 0
16 18
         self.scanner = asyncio.create_task(self.scan())
17 19
 
18 20
     def exit(self):
@@ -48,20 +50,33 @@ class StateScan:
48 50
                         self.results.append(value)
49 51
 
50 52
     def draw_list(self):
53
+        if len(self.results) <= 0:
54
+            self.lcd.textC("No devices found yet", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
55
+            return
56
+
51 57
         for i, d in enumerate(self.results):
52
-            name, mac, rssi, timeout, device = self.results[i]
53
-            s1 = "{}: {}".format(i + 1, name)
54
-            s2 = "[{}] {}".format(mac, rssi)
58
+            if i < self.menuOff:
59
+                continue
55 60
 
56
-            off = i * 25 + 30
61
+            off = (i - self.menuOff) * 25 + 30
57 62
             if off >= self.lcd.height:
58 63
                 break
59 64
 
65
+            selection = "  "
66
+            if self.current == i:
67
+                selection = "->"
68
+            name, mac, rssi, timeout, device = self.results[i]
69
+            age = int(time.time() - timeout)
70
+            s1 = "{}: {}".format(i + 1, name)
71
+            s2 = "{} [{}] {} {}".format(selection, mac, rssi, age)
72
+
60 73
             c1 = self.lcd.white
61 74
             if name == "S&B VOLCANO H":
62 75
                 c1 = self.lcd.green
63 76
                 if self.current == None:
64 77
                     self.current = i
78
+            elif name == "STORZ&BICKEL":
79
+                c1 = self.lcd.yellow
65 80
             elif self.current == i:
66 81
                 c1 = self.lcd.red
67 82
             c2 = self.lcd.white
@@ -78,22 +93,36 @@ class StateScan:
78 93
         keys = self.lcd.buttons()
79 94
 
80 95
         async with self.lock:
81
-            if keys.once("enter"):
96
+            if keys.once("enter") or keys.once("a"):
82 97
                 if self.current < len(self.results):
83 98
                     return 2
84 99
             elif keys.once("up"):
85 100
                 if self.current == None:
86 101
                     self.current = len(self.results) - 1
87
-                elif self.current > 0:
102
+                else:
88 103
                     self.current -= 1
89 104
             elif keys.once("down"):
90 105
                 if self.current == None:
91 106
                     self.current = 0
92
-                elif self.current < (len(self.results) - 1):
107
+                else:
93 108
                     self.current += 1
94 109
 
110
+            if self.current != None:
111
+                while self.current < 0:
112
+                    self.current += len(self.results)
113
+                while self.current >= len(self.results):
114
+                    self.current -= len(self.results)
115
+                while self.current < self.menuOff:
116
+                    self.menuOff -= 1
117
+                while self.current >= (self.menuOff + int((self.lcd.height - 30) / 25)):
118
+                    self.menuOff += 1
119
+
95 120
             # remove entries after timeout
96 121
             self.results = [x for x in self.results if (time.time() - x[3]) < 10.0]
122
+
123
+            # filter out incompatible devices
124
+            #self.results = [x for x in self.results if (x[0] != None) and (("S&B" in x[0]) or ("STORZ&BICKEL" == x[0]))]
125
+
97 126
             if self.current != None:
98 127
                 if self.current >= len(self.results):
99 128
                     self.current = len(self.results) - 1

+ 1
- 1
python-test/state_select.py 查看文件

@@ -44,7 +44,7 @@ class StateSelect:
44 44
         elif keys.once("down"):
45 45
             if self.current < (len(workflows) - 1):
46 46
                 self.current += 1
47
-        elif keys.once("enter"):
47
+        elif keys.once("enter") or keys.once("a"):
48 48
             return 1
49 49
 
50 50
         self.draw_list()

+ 7
- 2
python-test/states.py 查看文件

@@ -1,6 +1,8 @@
1 1
 #!/usr/bin/env python
2 2
 
3 3
 import uasyncio as asyncio
4
+import io
5
+import sys
4 6
 
5 7
 class States:
6 8
     def __init__(self, lcd):
@@ -85,13 +87,16 @@ def state_machine(lcd):
85 87
 
86 88
 from lcd import LCD
87 89
 lcd = LCD()
90
+
91
+lcd.fill(lcd.black)
92
+lcd.textC("S&B Volcano Remote", int(lcd.width / 2), int(lcd.height / 2) - 5, lcd.green)
93
+lcd.textC("by xythobuz", int(lcd.width / 2), int(lcd.height / 2) + 5, lcd.yellow)
94
+lcd.show()
88 95
 lcd.brightness(1.0)
89 96
 
90 97
 try:
91 98
     state_machine(lcd)
92 99
 except Exception as e:
93
-    import io
94
-    import sys
95 100
     os = io.StringIO()
96 101
     sys.print_exception(e, os)
97 102
     s = os.getvalue()

+ 1
- 1
python-test/workflows.py 查看文件

@@ -9,7 +9,7 @@ workflows = [
9 9
             (205.0, 10.0, 20.0),
10 10
             (220.0, 10.0, 20.0),
11 11
         ],
12
-        "notify": (3, 1.0),
12
+        "notify": (4, 1.0),
13 13
         "reset_temperature": 190.0,
14 14
     },
15 15
     {

Loading…
取消
儲存