-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcdlog.py
56 lines (41 loc) · 1.15 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
_screen = None
_buffer = []
def init(device):
global _screen, DEVICE, INFO, ERROR, WARN, BLACK
DEVICE = device
INFO = DEVICE.rgb(192, 192, 192)
ERROR = DEVICE.rgb(192, 0, 0)
WARN = DEVICE.rgb(192, 128, 0)
BLACK = DEVICE.rgb(0, 0, 0)
_screen = device.Screen()
_screen.fill(BLACK)
_screen.display()
def info(text):
_append(text, INFO)
def warn(text):
_append(text, WARN)
def error(text):
_append(text, ERROR)
def _append(text, colour):
global _buffer
if _screen is None:
return
if not isinstance(text, str):
text = str(text)
while True:
overflow = text[DEVICE.WIDTH:]
text = text[:DEVICE.WIDTH]
if (len(_buffer) == DEVICE.HEIGHT):
_buffer = _buffer[1:]
_buffer.append((colour, text))
if not overflow:
break
text = overflow
_render()
def _render():
y = DEVICE.LINE_OFFSET_Y
_screen.fill(BLACK)
for line in _buffer:
_screen.text(line[1], 0, y, line[0])
y += DEVICE.LINE_HEIGHT
_screen.display()