浏览代码

scroll for workflow selection. color gradient for graph.

Thomas Buck 1年前
父节点
当前提交
4fe004406a
共有 4 个文件被更改,包括 60 次插入13 次删除
  1. 3
    2
      python-test/state_connect.py
  2. 2
    2
      python-test/state_scan.py
  3. 19
    8
      python-test/state_select.py
  4. 36
    1
      python-test/state_wait_temp.py

+ 3
- 2
python-test/state_connect.py 查看文件

2
 
2
 
3
 import uasyncio as asyncio
3
 import uasyncio as asyncio
4
 from poll import cache_services_characteristics
4
 from poll import cache_services_characteristics
5
+from state_wait_temp import draw_graph
5
 import machine
6
 import machine
6
 
7
 
7
 class StateConnect:
8
 class StateConnect:
75
                     if self.step == False:
76
                     if self.step == False:
76
                         self.lcd.textC("Connecting...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
77
                         self.lcd.textC("Connecting...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
77
                     else:
78
                     else:
78
-                        self.lcd.pie(self.lcd.width / 2, self.lcd.height / 2, self.lcd.width - 30, self.lcd.red, self.lcd.green, self.iteration)
79
-                        self.lcd.textC("Fetching parameters...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
79
+                        draw_graph(self.lcd, 0, int(self.iteration * 10), 10)
80
+                        self.lcd.textC("Fetching parameters...", int(self.lcd.width / 2), int(self.lcd.height / 2) - 10, self.lcd.white)
80
 
81
 
81
         return -1
82
         return -1

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

59
                 continue
59
                 continue
60
 
60
 
61
             off = (i - self.menuOff) * 25 + 30
61
             off = (i - self.menuOff) * 25 + 30
62
-            if off >= self.lcd.height:
62
+            if off >= (self.lcd.height - 10):
63
                 break
63
                 break
64
 
64
 
65
             selection = "  "
65
             selection = "  "
114
                     self.current -= len(self.results)
114
                     self.current -= len(self.results)
115
                 while self.current < self.menuOff:
115
                 while self.current < self.menuOff:
116
                     self.menuOff -= 1
116
                     self.menuOff -= 1
117
-                while self.current >= (self.menuOff + int((self.lcd.height - 30) / 25)):
117
+                while self.current >= (self.menuOff + int((self.lcd.height - 30 - 10) / 25)):
118
                     self.menuOff += 1
118
                     self.menuOff += 1
119
 
119
 
120
             # remove entries after timeout
120
             # remove entries after timeout

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

10
     def enter(self, val = None):
10
     def enter(self, val = None):
11
         self.client = val
11
         self.client = val
12
         self.current = 0
12
         self.current = 0
13
+        self.menuOff = 0
13
 
14
 
14
     def exit(self):
15
     def exit(self):
15
         return self.client, workflows[self.current]
16
         return self.client, workflows[self.current]
16
 
17
 
17
     def draw_list(self):
18
     def draw_list(self):
18
         for i, wf in enumerate(workflows):
19
         for i, wf in enumerate(workflows):
19
-            s1 = "{}".format(wf["name"])
20
-            s2 = "by: {}".format(wf["author"])
20
+            if i < self.menuOff:
21
+                continue
21
 
22
 
22
-            off = i * 25 + 30
23
-            if off >= self.lcd.height:
23
+            off = (i - self.menuOff) * 25 + 30
24
+            if off >= (self.lcd.height - 10):
24
                 break
25
                 break
25
 
26
 
27
+            s1 = "{}".format(wf["name"])
28
+            s2 = "by: {}".format(wf["author"])
29
+
26
             c = self.lcd.white
30
             c = self.lcd.white
27
             if self.current == i:
31
             if self.current == i:
28
                 c = self.lcd.red
32
                 c = self.lcd.red
39
         if keys.once("y"):
43
         if keys.once("y"):
40
             return 5
44
             return 5
41
         elif keys.once("up"):
45
         elif keys.once("up"):
42
-            if self.current > 0:
43
-                self.current -= 1
46
+            self.current -= 1
44
         elif keys.once("down"):
47
         elif keys.once("down"):
45
-            if self.current < (len(workflows) - 1):
46
-                self.current += 1
48
+            self.current += 1
47
         elif keys.once("enter") or keys.once("a"):
49
         elif keys.once("enter") or keys.once("a"):
48
             return 1
50
             return 1
49
 
51
 
52
+        while self.current < 0:
53
+            self.current += len(workflows)
54
+        while self.current >= len(workflows):
55
+            self.current -= len(workflows)
56
+        while self.current < self.menuOff:
57
+            self.menuOff -= 1
58
+        while self.current >= (self.menuOff + int((self.lcd.height - 30 - 10) / 25)):
59
+            self.menuOff += 1
60
+
50
         self.draw_list()
61
         self.draw_list()
51
 
62
 
52
         return -1
63
         return -1

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

2
 
2
 
3
 import uasyncio as asyncio
3
 import uasyncio as asyncio
4
 from poll import set_target_temp, get_current_temp
4
 from poll import set_target_temp, get_current_temp
5
+import math
6
+
7
+# https://github.com/pimoroni/pimoroni-pico
8
+def from_hsv(h, s, v):
9
+    i = math.floor(h * 6.0)
10
+    f = h * 6.0 - i
11
+    v *= 255.0
12
+    p = v * (1.0 - s)
13
+    q = v * (1.0 - f * s)
14
+    t = v * (1.0 - (1.0 - f) * s)
15
+
16
+    i = int(i) % 6
17
+    if i == 0:
18
+        return int(v), int(t), int(p)
19
+    if i == 1:
20
+        return int(q), int(v), int(p)
21
+    if i == 2:
22
+        return int(p), int(v), int(t)
23
+    if i == 3:
24
+        return int(p), int(q), int(v)
25
+    if i == 4:
26
+        return int(t), int(p), int(v)
27
+    if i == 5:
28
+        return int(v), int(p), int(q)
29
+
30
+# https://stackoverflow.com/a/1969274
31
+def translate(value, leftMin, leftMax, rightMin, rightMax):
32
+    leftSpan = leftMax - leftMin
33
+    rightSpan = rightMax - rightMin
34
+    valueScaled = float(value - leftMin) / float(leftSpan)
35
+    return rightMin + (valueScaled * rightSpan)
5
 
36
 
6
 def draw_graph(lcd, min, val, max):
37
 def draw_graph(lcd, min, val, max):
7
     if max == min:
38
     if max == min:
8
         lcd.textC("{} -> {} -> {}".format(min, val, max), int(self.lcd.width / 2), int(lcd.height / 2), lcd.white)
39
         lcd.textC("{} -> {} -> {}".format(min, val, max), int(self.lcd.width / 2), int(lcd.height / 2), lcd.white)
9
         return
40
         return
10
 
41
 
42
+    hue = translate(val, min, max, 0.0, 0.333)
43
+    r, g, b = from_hsv(hue, 1.0, 1.0)
44
+    c = lcd.color(r, g, b)
45
+
11
     ratio = (val - min) / (max - min)
46
     ratio = (val - min) / (max - min)
12
-    lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width - 30, lcd.red, lcd.green, ratio)
47
+    lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width - 42, lcd.white, c, ratio)
13
 
48
 
14
     lcd.textC("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
49
     lcd.textC("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
15
 
50
 

正在加载...
取消
保存