Browse Source

center text

Thomas Buck 1 year ago
parent
commit
3db027bc17

+ 3
- 0
python-test/lcd.py View File

243
         if v > 0.0:
243
         if v > 0.0:
244
             self.arc(int(x0), int(y0), int(w), int(w), c_circle, -90, int(v * 360) - 90)
244
             self.arc(int(x0), int(y0), int(w), int(w), c_circle, -90, int(v * 360) - 90)
245
         self.ring(int(x0), int(y0), int(w / 2), c_border)
245
         self.ring(int(x0), int(y0), int(w / 2), c_border)
246
+
247
+    def textC(self, s, x, y, c):
248
+        self.text(s, x - int(len(s) * 8 / 2), y - 5, c)

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

66
                     return 0
66
                     return 0
67
             else:
67
             else:
68
                 if self.state == False:
68
                 if self.state == False:
69
-                    self.lcd.text("Disconnecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
69
+                    self.lcd.textC("Disconnecting...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
70
                 else:
70
                 else:
71
                     if self.step == False:
71
                     if self.step == False:
72
-                        self.lcd.text("Connecting...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
72
+                        self.lcd.textC("Connecting...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
73
                     else:
73
                     else:
74
                         self.lcd.pie(self.lcd.width / 2, self.lcd.height / 2, self.lcd.width - 30, self.lcd.red, self.lcd.green, self.iteration)
74
                         self.lcd.pie(self.lcd.width / 2, self.lcd.height / 2, self.lcd.width - 30, self.lcd.red, self.lcd.green, self.iteration)
75
-                        self.lcd.text("Fetching parameters...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
75
+                        self.lcd.textC("Fetching parameters...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
76
 
76
 
77
         return -1
77
         return -1

+ 3
- 3
python-test/state_heat.py View File

66
             else:
66
             else:
67
                 if self.state == False:
67
                 if self.state == False:
68
                     if self.state == False:
68
                     if self.state == False:
69
-                        self.lcd.text("Turning heater off...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
69
+                        self.lcd.textC("Turning heater off...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
70
                     else:
70
                     else:
71
-                        self.lcd.text("Resetting temperature...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
71
+                        self.lcd.textC("Resetting temperature...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
72
                 else:
72
                 else:
73
-                    self.lcd.text("Turning heater on...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
73
+                    self.lcd.textC("Turning heater on...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
74
 
74
 
75
         return -1
75
         return -1

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

57
                 if now - self.start <= self.duration:
57
                 if now - self.start <= self.duration:
58
                     draw_graph(self.lcd, 0.0, now - self.start, self.duration)
58
                     draw_graph(self.lcd, 0.0, now - self.start, self.duration)
59
                 else:
59
                 else:
60
-                    self.lcd.text("Turning off pump...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
60
+                    self.lcd.textC("Turning off pump...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
61
             else:
61
             else:
62
-                self.lcd.text("Turning on pump...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
62
+                self.lcd.textC("Turning on pump...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
63
 
63
 
64
             if self.done:
64
             if self.done:
65
                 if self.value[2] >= (len(workflow["steps"]) - 1):
65
                 if self.value[2] >= (len(workflow["steps"]) - 1):

+ 3
- 3
python-test/state_wait_temp.py View File

5
 
5
 
6
 def draw_graph(lcd, min, val, max):
6
 def draw_graph(lcd, min, val, max):
7
     if max == min:
7
     if max == min:
8
-        lcd.text("{} -> {} -> {}".format(min, val, max), 0, int(lcd.height / 2) - 5, lcd.white)
8
+        lcd.textC("{} -> {} -> {}".format(min, val, max), int(self.lcd.width / 2), int(lcd.height / 2), lcd.white)
9
         return
9
         return
10
 
10
 
11
     ratio = (val - min) / (max - min)
11
     ratio = (val - min) / (max - min)
12
     lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width - 30, lcd.red, lcd.green, ratio)
12
     lcd.pie(lcd.width / 2, lcd.height / 2, lcd.width - 30, lcd.red, lcd.green, ratio)
13
 
13
 
14
-    lcd.text("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2) - 5, lcd.white)
14
+    lcd.textC("{} / {}".format(val, max), int(lcd.width / 2), int(lcd.height / 2), lcd.white)
15
 
15
 
16
 class StateWaitTemp:
16
 class StateWaitTemp:
17
     def __init__(self, lcd):
17
     def __init__(self, lcd):
64
 
64
 
65
         async with self.lock:
65
         async with self.lock:
66
             if self.temp == 0.0:
66
             if self.temp == 0.0:
67
-                self.lcd.text("Setting temperature...", 0, int(self.lcd.height / 2) - 5, self.lcd.white)
67
+                self.lcd.textC("Setting temperature...", int(self.lcd.width / 2), int(self.lcd.height / 2), self.lcd.white)
68
             else:
68
             else:
69
                 draw_graph(self.lcd, self.min, self.temp, self.max)
69
                 draw_graph(self.lcd, self.min, self.temp, self.max)
70
 
70
 

Loading…
Cancel
Save