浏览代码

menu scrolling and other tweaks

Thomas Buck 1年前
父节点
当前提交
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
         super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
41
         super().__init__(self.buffer, self.width, self.height, framebuf.RGB565)
42
         self.init_display()
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
         self.fill(self.black)
51
         self.fill(self.black)
51
         self.show()
52
         self.show()
54
         self.pwm.freq(1000)
55
         self.pwm.freq(1000)
55
         self.brightness(0.0)
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
         self.keys_old = {
68
         self.keys_old = {
69
             "a": False,
69
             "a": False,
93
         self.keys_old = keys.copy()
93
         self.keys_old = keys.copy()
94
         return kc
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
     def brightness(self, v):
100
     def brightness(self, v):
97
         self.pwm.duty_u16(int(v * 65535))
101
         self.pwm.duty_u16(int(v * 65535))
98
 
102
 

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

11
         self.lock = asyncio.Lock()
11
         self.lock = asyncio.Lock()
12
 
12
 
13
     def enter(self, val = None):
13
     def enter(self, val = None):
14
+        n = None
14
         self.results = []
15
         self.results = []
15
         self.current = None
16
         self.current = None
17
+        self.menuOff = 0
16
         self.scanner = asyncio.create_task(self.scan())
18
         self.scanner = asyncio.create_task(self.scan())
17
 
19
 
18
     def exit(self):
20
     def exit(self):
48
                         self.results.append(value)
50
                         self.results.append(value)
49
 
51
 
50
     def draw_list(self):
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
         for i, d in enumerate(self.results):
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
             if off >= self.lcd.height:
62
             if off >= self.lcd.height:
58
                 break
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
             c1 = self.lcd.white
73
             c1 = self.lcd.white
61
             if name == "S&B VOLCANO H":
74
             if name == "S&B VOLCANO H":
62
                 c1 = self.lcd.green
75
                 c1 = self.lcd.green
63
                 if self.current == None:
76
                 if self.current == None:
64
                     self.current = i
77
                     self.current = i
78
+            elif name == "STORZ&BICKEL":
79
+                c1 = self.lcd.yellow
65
             elif self.current == i:
80
             elif self.current == i:
66
                 c1 = self.lcd.red
81
                 c1 = self.lcd.red
67
             c2 = self.lcd.white
82
             c2 = self.lcd.white
78
         keys = self.lcd.buttons()
93
         keys = self.lcd.buttons()
79
 
94
 
80
         async with self.lock:
95
         async with self.lock:
81
-            if keys.once("enter"):
96
+            if keys.once("enter") or keys.once("a"):
82
                 if self.current < len(self.results):
97
                 if self.current < len(self.results):
83
                     return 2
98
                     return 2
84
             elif keys.once("up"):
99
             elif keys.once("up"):
85
                 if self.current == None:
100
                 if self.current == None:
86
                     self.current = len(self.results) - 1
101
                     self.current = len(self.results) - 1
87
-                elif self.current > 0:
102
+                else:
88
                     self.current -= 1
103
                     self.current -= 1
89
             elif keys.once("down"):
104
             elif keys.once("down"):
90
                 if self.current == None:
105
                 if self.current == None:
91
                     self.current = 0
106
                     self.current = 0
92
-                elif self.current < (len(self.results) - 1):
107
+                else:
93
                     self.current += 1
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
             # remove entries after timeout
120
             # remove entries after timeout
96
             self.results = [x for x in self.results if (time.time() - x[3]) < 10.0]
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
             if self.current != None:
126
             if self.current != None:
98
                 if self.current >= len(self.results):
127
                 if self.current >= len(self.results):
99
                     self.current = len(self.results) - 1
128
                     self.current = len(self.results) - 1

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

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

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

1
 #!/usr/bin/env python
1
 #!/usr/bin/env python
2
 
2
 
3
 import uasyncio as asyncio
3
 import uasyncio as asyncio
4
+import io
5
+import sys
4
 
6
 
5
 class States:
7
 class States:
6
     def __init__(self, lcd):
8
     def __init__(self, lcd):
85
 
87
 
86
 from lcd import LCD
88
 from lcd import LCD
87
 lcd = LCD()
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
 lcd.brightness(1.0)
95
 lcd.brightness(1.0)
89
 
96
 
90
 try:
97
 try:
91
     state_machine(lcd)
98
     state_machine(lcd)
92
 except Exception as e:
99
 except Exception as e:
93
-    import io
94
-    import sys
95
     os = io.StringIO()
100
     os = io.StringIO()
96
     sys.print_exception(e, os)
101
     sys.print_exception(e, os)
97
     s = os.getvalue()
102
     s = os.getvalue()

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

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

正在加载...
取消
保存