-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdp.py
54 lines (41 loc) · 971 Bytes
/
cdp.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
PORT = "/dev/ttyS3"
dev = open(PORT, "w")
EMPTY = " "
top_buffer = EMPTY
bottom_buffer = EMPTY
def left(text):
while len(text) < 20:
text += " "
return text
def center(text):
while len(text) < 20:
if len(text) % 2 == 0:
text = " " + text
else:
text += " "
return text
def right(text):
while len(text) < 20:
text = " " + text
return text
def merge(a, b):
a = list(a)
b = list(b)
if len(a) > len(b):
for i in range(len(b)):
if a[i] == " ":
a[i] = b[i]
return "".join(a)
else:
for i in range(len(a)):
if b[i] == " ":
b[i] = a[i]
return "".join(b)
def show(top, bottom):
if top is None:
top = EMPTY
if bottom is None:
bottom = EMPTY
top = center(top)[:20]
bottom = center(bottom)[:20]
dev.write(("\f" + top + bottom + "\n"))