-
Notifications
You must be signed in to change notification settings - Fork 0
/
infosys.py
102 lines (75 loc) · 2.56 KB
/
infosys.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
from pyfis.ibis import SerialIBISMaster
import time
from threading import Lock
MAX_DISPLAY_LENGTH = 24
class display:
def __init__(self):
self.master = SerialIBISMaster("/dev/ttyUSB0", debug=False)
self.lock = Lock()
def write_text(self, text: str, effect: str = 'split', wipe: bool = False):
"""
Write text to the IBIS device
"""
if(len(text) > 48):
raise ValueError("Text too long")
return
if(self.lock.locked()):
raise ConnectionError("Display is locked")
return
self.lock.acquire(1)
if wipe:
self._wipe_display()
if effect == "chase":
self._do_chase(text)
elif effect == "split":
self._do_split(text)
self.lock.release()
def print_time(self):
"""
Print the current time to the IBIS device
"""
if(self.lock.locked()):
raise ConnectionError("Display is locked")
return
self.lock.acquire(1)
self.master.DS009(f'{time.strftime("%H:%M")}')
self.lock.release()
def _do_split(self, text: str):
"""
Write text to the IBIS device with a timestamp
"""
split = [text[i:i+MAX_DISPLAY_LENGTH] for i in range(0, len(text), MAX_DISPLAY_LENGTH)]
for i in split:
self.master.DS009(self._pad_string(f'{time.strftime("%H:%M")} {self._pad_string(i)}'))
time.sleep(5)
return
def _do_chase(self, text: str):
"""
Write text to the IBIS device with a timestamp
"""
self.master.DS009(f'{time.strftime("%H:%M")} {self._pad_string(text)}')
time.sleep(5)
loops = len(text) + 1
for i in range(0, loops):
self.master.DS009(f'{time.strftime("%H:%M")} {self._pad_string(text, True)}')
text = text[1:]
time.sleep(1)
return
def _wipe_display(self):
"""
Wipe the display
"""
for i in range(0, 30):
self.master.DS009(f'{" " * i}#{" " * (MAX_DISPLAY_LENGTH + 4 - i)}.')
time.sleep(.1)
def _pad_string(self, text: str, suffix: bool = False):
"""
Pad the string to the correct length
"""
if len(text) < MAX_DISPLAY_LENGTH:
pad = " " * (MAX_DISPLAY_LENGTH - len(text) -1)
if suffix:
text = text + pad + '.'
else:
text = pad + text
return text