-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlcdlog.py
79 lines (67 loc) · 1.74 KB
/
lcdlog.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
import time
import os
import errno
#import Adafruit_GPIO.SPI as SPI
#import Adafruit_SSD1306
import board
import busio
import adafruit_ssd1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
# Raspberry Pi pin configuration:
RST = 24
# only used with SPI
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0
# Use for I2C
i2c = busio.I2C(board.SCL, board.SDA)
# 128x32 display with hardware I2C:
disp = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c)
#disp = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
#disp.begin()
#disp.clear()
#disp.display()
disp.fill(0)
disp.show()
width = disp.width
height = disp.height
# create object to draw on. '1' specifices 1 bit color
canvas = Image.new('1', (width, height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(canvas)
padding = 2
top = padding
bottom = height - padding
x = padding
FIFO = "bc6-printlog"
if os.path.isfile(FIFO):
os.remove(FIFO)
try:
os.mkfifo(FIFO)
except OSError as oe:
if oe.errno != errno.EEXIST:
raise
index = [x, top] # x, y
font = ImageFont.load_default()
last_line = ""
while True:
print("Opening FIFO")
with open(FIFO) as print_queue:
time.sleep(0.1)
line = print_queue.read()
if len(line) == 0:
print("FIFO closed")
continue
print(f"Read line: {line}")
if index[1] >= bottom: # reset the screen
index[1] = top
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((index[0], index[1]), last_line, font=font, fill=255)
index[1] += 10
draw.text((index[0], index[1]), line, font=font, fill=255)
index[1] += 10
disp.image(canvas)
disp.show()
last_line = line