forked from nebhead/PiFire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_st7789_240x320.py
572 lines (502 loc) · 20 KB
/
display_st7789_240x320.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
#!/usr/bin/env python3
'''
*****************************************
PiFire Display Interface Library
*****************************************
Description:
This library supports using
the ST7789 display with resolution.
This module utilizes the Pimoroni libraries
to interface this display.
*****************************************
'''
'''
Imported Libraries
'''
import time
import socket
import qrcode
import threading
import ST7789 as ST7789
from PIL import Image, ImageDraw, ImageFont
'''
Display class definition
'''
class Display:
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.rotation = rotation
self.units = units
self.displayactive = False
self.in_data = None
self.status_data = None
self.displaytimeout = None
self.displaycommand = 'splash'
# Init Display Device, Input Device, Assets
self._init_globals()
self._init_assets()
self._init_display_device()
def _init_globals(self):
# Init constants and variables
self.WIDTH = 320
self.HEIGHT = 240
self.inc_pulse_color = True
self.icon_color = 100
self.fan_rotation = 0
self.auger_step = 0
def _init_display_device(self):
# Init Device
self.device = ST7789.ST7789(
port=0,
cs=0,
dc=24,
backlight=5,
rst=25,
rotation=self.rotation,
width=320,
height=240,
spi_speed_hz=60 * 1000 * 1000
)
self.WIDTH = self.device.width
self.HEIGHT = self.device.height
# Setup & Start Display Loop Thread
display_thread = threading.Thread(target=self._display_loop)
display_thread.start()
def _display_loop(self):
'''
Main display loop
'''
while True:
if self.displaytimeout:
if time.time() > self.displaytimeout:
self.displaycommand = 'clear'
if self.displaycommand == 'clear':
self.displayactive = False
self.displaytimeout = None
self.displaycommand = None
self._display_clear()
if self.displaycommand == 'splash':
self.displayactive = True
self._display_splash()
self.displaytimeout = time.time() + 3
self.displaycommand = None
time.sleep(3) # Hold splash screen for 3 seconds
if self.displaycommand == 'text':
self.displayactive = True
self._display_text()
self.displaycommand = None
self.displaytimeout = time.time() + 10
if self.displaycommand == 'network':
self.displayactive = True
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
networkip = s.getsockname()[0]
if (networkip != ''):
self._display_network(networkip)
self.displaytimeout = time.time() + 30
self.displaycommand = None
else:
self.display_text("No IP Found")
if self.displayactive:
if not self.displaytimeout:
if (self.in_data is not None) and (self.status_data is not None):
self._display_current(self.in_data, self.status_data)
time.sleep(0.1)
'''
============== Graphics / Display / Draw Methods =============
'''
def _init_assets(self):
self._init_background()
self._init_splash()
def _init_background(self):
self.background = Image.open('background.jpg')
self.background = self.background.resize((self.WIDTH, self.HEIGHT))
def _init_splash(self):
self.splash = Image.open('color-boot-splash.png')
(self.splash_width, self.splash_height) = self.splash.size
self.splash_width *= 2
self.splash_height *= 2
self.splash = self.splash.resize((self.splash_width, self.splash_height))
def _rounded_rectangle(self, draw, xy, rad, fill=None):
x0, y0, x1, y1 = xy
draw.rectangle([(x0, y0 + rad), (x1, y1 - rad)], fill=fill)
draw.rectangle([(x0 + rad, y0), (x1 - rad, y1)], fill=fill)
draw.pieslice([(x0, y0), (x0 + rad * 2, y0 + rad * 2)], 180, 270, fill=fill)
draw.pieslice([(x1 - rad * 2, y1 - rad * 2), (x1, y1)], 0, 90, fill=fill)
draw.pieslice([(x0, y1 - rad * 2), (x0 + rad * 2, y1)], 90, 180, fill=fill)
draw.pieslice([(x1 - rad * 2, y0), (x1, y0 + rad * 2)], 270, 360, fill=fill)
return (draw)
def _create_icon(self, charid, size, color):
# Get font and character size
font = ImageFont.truetype("FA-Free-Solid.otf", size)
# Create canvas
iconcanvas = Image.new('RGBa', font.getsize(charid))
# Create drawing object
draw = ImageDraw.Draw(iconcanvas)
draw.text((0, 0), charid, font=font, fill=color)
iconcanvas = iconcanvas.crop(iconcanvas.getbbox())
return (iconcanvas)
def _paste_icon(self, icon, canvas, position, rotation, bgcolor):
# First fill the background
bgfill = ImageDraw.Draw(canvas)
# Rotate the icon
icon = icon.rotate(rotation)
(icon_width, icon_height) = icon.size
# bgfill.rectangle([(position[0], position[1]), (position[0] + icon_width, position[1] + icon_height)], fill=bgcolor)
# Set the position & paste the icon onto the canvas
canvas.paste(icon, position, icon)
return (canvas)
def _draw_fan_icon(self, canvas):
# F = Fan (Upper Left)
icon_char = '\uf863'
icon_color = (0, self.icon_color, 255)
drawing = ImageDraw.Draw(canvas)
# Draw Rounded Rectangle Border
drawing = self._rounded_rectangle(drawing, (
self.WIDTH // 8 - 22, self.HEIGHT // 6 - 22, self.WIDTH // 8 + 22, self.HEIGHT // 6 + 22), 5,
icon_color)
# Fill Rectangle with Black
drawing = self._rounded_rectangle(drawing, (
self.WIDTH // 8 - 20, self.HEIGHT // 6 - 20, self.WIDTH // 8 + 20, self.HEIGHT // 6 + 20), 5,
(0, 0, 0))
# Create Icon Image
icon = self._create_icon(icon_char, 36, icon_color)
position = (self.WIDTH // 8 - 18, self.HEIGHT // 6 - 18)
canvas = self._paste_icon(icon, canvas, position, self.fan_rotation, (0, 0, 0))
return (canvas)
def _draw_auger_icon(self, canvas):
# A = Auger (Center Left)
icon_char = '\uf101'
icon_color_tuple = (0, self.icon_color, 0)
# Create a drawing object
drawing = ImageDraw.Draw(canvas)
# Draw Rounded Rectangle Border
drawing = self._rounded_rectangle(drawing, (
self.WIDTH // 8 - 22, self.HEIGHT // 2.5 - 22, self.WIDTH // 8 + 22, self.HEIGHT // 2.5 + 22), 5,
icon_color_tuple)
# Fill Rectangle with Black
drawing = self._rounded_rectangle(drawing, (
self.WIDTH // 8 - 20, self.HEIGHT // 2.5 - 20, self.WIDTH // 8 + 20, self.HEIGHT // 2.5 + 20), 5,
(0, 0, 0))
# Create Icon Image
icon = self._create_icon(icon_char, 36, icon_color_tuple)
(icon_width, icon_height) = icon.size
position = ((self.WIDTH // 8 - 18) + (icon_width // 8) + self.auger_step,
(int(self.HEIGHT // 2.5) - 18) + (icon_height // 3))
canvas = self._paste_icon(icon, canvas, position, 0, (0, 0, 0))
return (canvas)
def _display_clear(self):
# Create blank canvas
img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(0, 0, 0))
self.device.display(img)
# Kill the backlight to the display
self.device.set_backlight(0)
def _display_canvas(self, canvas):
# Display canvas to screen for ST7789
# Turn on Backlight (just in case it was off)
self.device.set_backlight(1)
self.device.display(canvas)
def _display_splash(self):
# Create canvas
img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(0, 0, 0))
# Set the position
position = ((self.WIDTH - self.splash_width) // 2, (self.HEIGHT - self.splash_height) // 2)
# Paste the splash screen onto the canvas
img.paste(self.splash, position)
self._display_canvas(img)
def _display_text(self):
# Create canvas
img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(0, 0, 0))
# Create drawing object
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("impact.ttf", 42)
(font_width, font_height) = font.getsize(self.displaydata)
draw.text((self.WIDTH // 2 - font_width // 2, self.HEIGHT // 2 - font_height // 2), self.displaydata, font=font,
fill=255)
self._display_canvas(img)
def _display_network(self, networkip):
# Create canvas
img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(255, 255, 255))
img_qr = qrcode.make('http://' + networkip)
img_qr_width, img_qr_height = img_qr.size
img_qr_width *= 2
img_qr_height *= 2
w = min(self.WIDTH, self.HEIGHT)
new_image = img_qr.resize((w, w))
position = (int((self.WIDTH / 2) - (w / 2)), 0)
img.paste(new_image, position)
self._display_canvas(img)
def _display_current(self, in_data, status_data):
# Create canvas
img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(0, 0, 0))
# Set the position and paste the background image onto the canvas
position = (0, 0)
img.paste(self.background, position)
# Create drawing object
draw = ImageDraw.Draw(img)
# Grill Temp Circle
draw.ellipse((80, 10, 240, 170), fill=(50, 50, 50)) # Grey Background Circle
if in_data['GrillTemp'] < 0:
endpoint = 0
elif self.units == 'F':
endpoint = ((360 * in_data['GrillTemp']) // 600) + 90
else:
endpoint = ((360 * in_data['GrillTemp']) // 300) + 90
draw.pieslice((80, 10, 240, 170), start=90, end=endpoint, fill=(200, 0, 0)) # Red Arc for Temperature
if (in_data['GrillSetPoint'] > 0) and (status_data['mode'] == 'Hold'):
if self.units == 'F':
setpoint = ((360 * in_data['GrillSetPoint']) // 600) + 90
else:
setpoint = ((360 * in_data['GrillSetPoint']) // 300) + 90
draw.pieslice((80, 10, 240, 170), start=setpoint - 2, end=setpoint + 2,
fill=(0, 200, 255)) # Blue Arc for SetPoint
if (in_data['GrillNotifyPoint'] > 0) and (status_data['notify_req']['grill']):
if self.units == 'F':
setpoint = ((360 * in_data['GrillNotifyPoint']) // 600) + 90
else:
setpoint = ((360 * in_data['GrillNotifyPoint']) // 300) + 90
draw.pieslice((80, 10, 240, 170), start=setpoint - 2, end=setpoint + 2,
fill=(255, 255, 0)) # Yellow Arc for Notify Point
draw.ellipse((90, 20, 230, 160), fill=(0, 0, 0)) # Black Circle for Center
# Grill Temp Label
font = ImageFont.truetype("trebucbd.ttf", 16)
text = "Grill"
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH // 2 - font_width // 2, 25), text, font=font, fill=(255, 255, 255))
# Grill Temperature (Large Centered)
if (self.units == 'F'):
font = ImageFont.truetype("trebucbd.ttf", 76)
text = str(in_data['GrillTemp'])[:5]
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH // 2 - font_width // 2, 40), text, font=font, fill=(255, 255, 255))
else:
font = ImageFont.truetype("trebucbd.ttf", 51)
text = str(in_data['GrillTemp'])[:5]
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH // 2 - font_width // 2, 56), text, font=font, fill=(255, 255, 255))
# Grill Set Point (Small Centered Bottom)
if (in_data['GrillSetPoint'] > 0) and (status_data['mode'] == 'Hold'):
font = ImageFont.truetype("trebuc.ttf", 18)
text = ">" + str(in_data['GrillSetPoint'])[:5] + "<"
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH // 2 - font_width // 2, 118), text, font=font, fill=(0, 200, 255))
# PROBE1 Temp Circle
draw.ellipse((10, self.HEIGHT // 2 + 10, 110, self.HEIGHT // 2 + 110), fill=(50, 50, 50))
if in_data['Probe1Temp'] < 0:
endpoint = 0
elif self.units == 'F':
endpoint = ((360 * in_data['Probe1Temp']) // 300) + 90
else:
endpoint = ((360 * in_data['Probe1Temp']) // 150) + 90
draw.pieslice((10, self.HEIGHT // 2 + 10, 110, self.HEIGHT // 2 + 110), start=90, end=endpoint,
fill=(3, 161, 252))
if (in_data['Probe1SetPoint'] > 0):
if self.units == 'F':
setpoint = ((360 * in_data['Probe1SetPoint']) // 300) + 90
else:
setpoint = ((360 * in_data['Probe1SetPoint']) // 150) + 90
draw.pieslice((10, self.HEIGHT // 2 + 10, 110, self.HEIGHT // 2 + 110), start=setpoint - 2,
end=setpoint + 2, fill=(255, 255, 0)) # Yellow Arc for SetPoint
draw.ellipse((20, self.HEIGHT // 2 + 20, 100, self.HEIGHT // 2 + 100), fill=(0, 0, 0))
# PROBE1 Temp Label
font = ImageFont.truetype("trebucbd.ttf", 16)
text = "P1"
(font_width, font_height) = font.getsize(text)
draw.text((60 - font_width // 2, self.HEIGHT // 2 + 28 - font_height // 2), text, font=font,
fill=(255, 255, 255))
# PROBE1 Temperature (Large Centered)
if (self.units == 'F'):
font = ImageFont.truetype("trebucbd.ttf", 38)
else:
font = ImageFont.truetype("trebucbd.ttf", 32)
text = str(in_data['Probe1Temp'])[:5]
(font_width, font_height) = font.getsize(text)
draw.text((60 - font_width // 2, self.HEIGHT // 2 + 56 - font_height // 2), text, font=font,
fill=(255, 255, 255))
# PROBE1 Set Point (Small Centered Bottom)
if (in_data['Probe1SetPoint'] > 0):
font = ImageFont.truetype("trebuc.ttf", 16)
text = ">" + str(in_data['Probe1SetPoint'])[:5] + "<"
(font_width, font_height) = font.getsize(text)
draw.text((60 - font_width // 2, self.HEIGHT // 2 + 80 - font_height // 2), text, font=font,
fill=(0, 200, 255))
# PROBE2 Temp Circle
draw.ellipse((self.WIDTH - 110, self.HEIGHT // 2 + 10, self.WIDTH - 10, self.HEIGHT // 2 + 110),
fill=(50, 50, 50))
if in_data['Probe2Temp'] < 0:
endpoint = 0
elif self.units == 'F':
endpoint = ((360 * in_data['Probe2Temp']) // 300) + 90
else:
endpoint = ((360 * in_data['Probe2Temp']) // 150) + 90
draw.pieslice((self.WIDTH - 110, self.HEIGHT // 2 + 10, self.WIDTH - 10, self.HEIGHT // 2 + 110), start=90,
end=endpoint, fill=(3, 161, 252))
if (in_data['Probe2SetPoint'] > 0):
if self.units == 'F':
setpoint = ((360 * in_data['Probe2SetPoint']) // 300) + 90
else:
setpoint = ((360 * in_data['Probe2SetPoint']) // 150) + 90
draw.pieslice((self.WIDTH - 110, self.HEIGHT // 2 + 10, self.WIDTH - 10, self.HEIGHT // 2 + 110),
start=setpoint - 2, end=setpoint + 2, fill=(255, 255, 0)) # Yellow Arc for SetPoint
draw.ellipse((self.WIDTH - 100, self.HEIGHT // 2 + 20, self.WIDTH - 20, self.HEIGHT // 2 + 100),
fill=(0, 0, 0))
# PROBE2 Temp Label
font = ImageFont.truetype("trebucbd.ttf", 16)
text = "P2"
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH - 60 - font_width // 2, self.HEIGHT // 2 + 28 - font_height // 2), text, font=font,
fill=(255, 255, 255))
# PROBE2 Temperature (Large Centered)
if (self.units == 'F'):
font = ImageFont.truetype("trebucbd.ttf", 38)
else:
font = ImageFont.truetype("trebucbd.ttf", 32)
text = str(in_data['Probe2Temp'])[:5]
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH - 60 - font_width // 2, self.HEIGHT // 2 + 56 - font_height // 2), text, font=font,
fill=(255, 255, 255))
# PROBE2 Set Point (Small Centered Bottom)
if (in_data['Probe2SetPoint'] > 0):
font = ImageFont.truetype("trebuc.ttf", 16)
text = ">" + str(in_data['Probe2SetPoint'])[:5] + "<"
(font_width, font_height) = font.getsize(text)
draw.text((self.WIDTH - 60 - font_width // 2, self.HEIGHT // 2 + 80 - font_height // 2), text,
font=font, fill=(0, 200, 255))
# Active Outputs
''' Test of pulsing color '''
if self.inc_pulse_color == True:
if self.icon_color < 200:
self.icon_color += 20
else:
self.inc_pulse_color = False
self.icon_color -= 20
else:
if self.icon_color < 100:
self.inc_pulse_color = True
self.icon_color += 20
else:
self.icon_color -= 20
font = ImageFont.truetype("FA-Free-Solid.otf", 36)
if (status_data['outpins']['fan'] == 0):
# F = Fan (Upper Left), 40x40, origin 10,10
self._draw_fan_icon(img)
self.fan_rotation += 30
if self.fan_rotation >= 360:
self.fan_rotation = 0
if (status_data['outpins']['igniter'] == 0):
# I = Igniter(Center Right)
text = '\uf46a'
(font_width, font_height) = font.getsize(text)
draw = self._rounded_rectangle(draw, (
7 * (self.WIDTH // 8) - 22, self.HEIGHT // 2.5 - 22, 7 * (self.WIDTH // 8) + 22,
self.HEIGHT // 2.5 + 22), 5, (255, self.icon_color, 0))
draw = self._rounded_rectangle(draw, (
7 * (self.WIDTH // 8) - 20, self.HEIGHT // 2.5 - 20, 7 * (self.WIDTH // 8) + 20,
self.HEIGHT // 2.5 + 20), 5, (0, 0, 0))
draw.text((7 * (self.WIDTH // 8) - font_width // 2, self.HEIGHT // 2.5 - font_height // 2), text,
font=font, fill=(255, self.icon_color, 0))
if (status_data['outpins']['auger'] == 0):
# A = Auger (Center Left)
self._draw_auger_icon(img)
self.auger_step += 1
if self.auger_step >= 3:
self.auger_step = 0
# Notification Indicator (Right)
show_notify_indicator = False
for item in status_data['notify_req']:
if status_data['notify_req'][item] == True:
show_notify_indicator = True
if (show_notify_indicator == True):
font = ImageFont.truetype("FA-Free-Solid.otf", 36)
text = '\uf0f3'
(font_width, font_height) = font.getsize(text)
draw = self._rounded_rectangle(draw, (
7 * (self.WIDTH // 8) - 22, self.HEIGHT // 6 - 22, 7 * (self.WIDTH // 8) + 22,
self.HEIGHT // 6 + 22), 5, (255, 255, 0))
draw = self._rounded_rectangle(draw, (
7 * (self.WIDTH // 8) - 20, self.HEIGHT // 6 - 20, 7 * (self.WIDTH // 8) + 20,
self.HEIGHT // 6 + 20), 5, (0, 0, 0))
draw.text((7 * (self.WIDTH // 8) - font_width // 2 + 1, self.HEIGHT // 6 - font_height // 2), text,
font=font, fill=(255, 255, 0))
# Smoke Plus Indicator
if (status_data['s_plus'] == True) and (
(status_data['mode'] == 'Smoke') or (status_data['mode'] == 'Hold')):
draw = self._rounded_rectangle(draw, (
7 * (self.WIDTH // 8) - 22, self.HEIGHT // 2.5 - 22, 7 * (self.WIDTH // 8) + 22,
self.HEIGHT // 2.5 + 22), 5, (150, 0, 255))
draw = self._rounded_rectangle(draw, (
7 * (self.WIDTH // 8) - 20, self.HEIGHT // 2.5 - 20, 7 * (self.WIDTH // 8) + 20,
self.HEIGHT // 2.5 + 20), 5, (0, 0, 0))
font = ImageFont.truetype("FA-Free-Solid.otf", 32)
text = '\uf0c2' # FontAwesome Icon for Cloud (Smoke)
(font_width, font_height) = font.getsize(text)
draw.text((7 * (self.WIDTH // 8) - font_width // 2, self.HEIGHT // 2.5 - font_height // 2), text,
font=font, fill=(100, 0, 255))
font = ImageFont.truetype("FA-Free-Solid.otf", 24)
text = '\uf067' # FontAwesome Icon for PLUS
(font_width, font_height) = font.getsize(text)
draw.text((7 * (self.WIDTH // 8) - font_width // 2, self.HEIGHT // 2.5 - font_height // 2 + 3), text,
font=font, fill=(0, 0, 0))
# Grill Hopper Level (Lower Center)
font = ImageFont.truetype("trebucbd.ttf", 16)
text = "Hopper:" + str(status_data['hopper_level']) + "%"
(font_width, font_height) = font.getsize(text)
if (status_data['hopper_level'] > 70):
hopper_color = (0, 255, 0)
elif (status_data['hopper_level'] > 30):
hopper_color = (255, 150, 0)
else:
hopper_color = (255, 0, 0)
draw = self._rounded_rectangle(draw, (
self.WIDTH // 2 - font_width // 2 - 7, 156 - font_height // 2, self.WIDTH // 2 + font_width // 2 + 7,
166 + font_height // 2), 5, hopper_color)
draw = self._rounded_rectangle(draw, (
self.WIDTH // 2 - font_width // 2 - 5, 158 - font_height // 2, self.WIDTH // 2 + font_width // 2 + 5,
164 + font_height // 2), 5, (0, 0, 0))
draw.text((self.WIDTH // 2 - font_width // 2, 160 - font_height // 2), text, font=font, fill=hopper_color)
# Current Mode (Bottom Center)
font = ImageFont.truetype("trebuc.ttf", 36)
text = status_data['mode'] # + ' Mode'
(font_width, font_height) = font.getsize(text)
draw = self._rounded_rectangle(draw, (
self.WIDTH // 2 - font_width // 2 - 7, self.HEIGHT - font_height - 2,
self.WIDTH // 2 + font_width // 2 + 7,
self.HEIGHT - 2), 5, (3, 161, 252))
draw = self._rounded_rectangle(draw, (
self.WIDTH // 2 - font_width // 2 - 5, self.HEIGHT - font_height, self.WIDTH // 2 + font_width // 2 + 5,
self.HEIGHT - 4), 5, (255, 255, 255))
draw.text((self.WIDTH // 2 - font_width // 2, self.HEIGHT - font_height - 6), text, font=font,
fill=(0, 0, 0))
self._display_canvas(img)
'''
================ Externally Available Methods ================
'''
def display_status(self, in_data, status_data):
'''
- Updates the current data for the display loop, if in a work mode
'''
self.units = status_data['units']
self.displayactive = True
self.in_data = in_data
self.status_data = status_data
def display_splash(self):
'''
- Calls Splash Screen
'''
self.displaycommand = 'splash'
def clear_display(self):
'''
- Clear display and turn off backlight
'''
self.displaycommand = 'clear'
def display_text(self, text):
'''
- Display some text
'''
self.displaycommand = 'text'
self.displaydata = text
def display_network(self):
'''
- Display Network IP QR Code
'''
self.displaycommand = 'network'