Browse Source

scroll for workflow selection. color gradient for graph.

Thomas Buck 8 months ago
parent
commit
4fe004406a

+ 3
- 2
python-test/state_connect.py View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 import uasyncio as asyncio
4 4
 from poll import cache_services_characteristics
5
+from state_wait_temp import draw_graph
5 6
 import machine
6 7
 
7 8
 class StateConnect:
@@ -75,7 +76,7 @@ class StateConnect:
75 76
                     if self.step == False:
76 77
                         self.lcd.textC("Connecting...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
77 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 82
         return -1

+ 2
- 2
python-test/state_scan.py View File

@@ -59,7 +59,7 @@ class StateScan:
59 59
                 continue
60 60
 
61 61
             off = (i - self.menuOff) * 25 + 30
62
-            if off >= self.lcd.height:
62
+            if off >= (self.lcd.height - 10):
63 63
                 break
64 64
 
65 65
             selection = "  "
@@ -114,7 +114,7 @@ class StateScan:
114 114
                     self.current -= len(self.results)
115 115
                 while self.current < self.menuOff:
116 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 118
                     self.menuOff += 1
119 119
 
120 120
             # remove entries after timeout

+ 19
- 8
python-test/state_select.py View File

@@ -10,19 +10,23 @@ class StateSelect:
10 10
     def enter(self, val = None):
11 11
         self.client = val
12 12
         self.current = 0
13
+        self.menuOff = 0
13 14
 
14 15
     def exit(self):
15 16
         return self.client, workflows[self.current]
16 17
 
17 18
     def draw_list(self):
18 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 25
                 break
25 26
 
27
+            s1 = "{}".format(wf["name"])
28
+            s2 = "by: {}".format(wf["author"])
29
+
26 30
             c = self.lcd.white
27 31
             if self.current == i:
28 32
                 c = self.lcd.red
@@ -39,14 +43,21 @@ class StateSelect:
39 43
         if keys.once("y"):
40 44
             return 5
41 45
         elif keys.once("up"):
42
-            if self.current > 0:
43
-                self.current -= 1
46
+            self.current -= 1
44 47
         elif keys.once("down"):
45
-            if self.current < (len(workflows) - 1):
46
-                self.current += 1
48
+            self.current += 1
47 49
         elif keys.once("enter") or keys.once("a"):
48 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 61
         self.draw_list()
51 62
 
52 63
         return -1

+ 36
- 1
python-test/state_wait_temp.py View File

@@ -2,14 +2,49 @@
2 2
 
3 3
 import uasyncio as asyncio
4 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 37
 def draw_graph(lcd, min, val, max):
7 38
     if max == min:
8 39
         lcd.textC("{} -> {} -> {}".format(min, val, max), int(self.lcd.width / 2), int(lcd.height / 2), lcd.white)
9 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 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 49
     lcd.textC("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
15 50
 

Loading…
Cancel
Save