-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMatrixEmulator.py
More file actions
executable file
·95 lines (74 loc) · 1.95 KB
/
MatrixEmulator.py
File metadata and controls
executable file
·95 lines (74 loc) · 1.95 KB
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
#!/usr/bin/env python3
#
# emulator for led ceiling
#
# (c) 2018 Chaospott Essen
import os
import signal
import time
import sys
from MatrixThread import MatrixThread
from SerialThread import SerialThread
#---------------#
# Configuration #
#---------------#
PIXEL_WIDTH = 8
PIXEL_MARGIN = 2
CHUNK_WIDTH = 8
CHUNK_HEIGHT = 8
CHUNK_MARGIN = 2
GRID_WIDTH = 10
GRID_HEIGHT = 5
def sighandler(signum, frame):
"""
Callback for the signal handler.
It removes the symlink for the
pts to /dev/ttyUSB99.
"""
# remove the symlink
os.remove('/dev/ttyUSB99')
# print the status
print('==> Removed symlink')
# exit gracefully
sys.exit(0)
def main():
"""
Main function and entrypoint of the script.
"""
# calculate window width and window height from the configuration
windowWidth = (((PIXEL_WIDTH + PIXEL_MARGIN) * CHUNK_WIDTH) + CHUNK_MARGIN) \
* GRID_WIDTH
windowHeight = (((PIXEL_WIDTH + PIXEL_MARGIN) * CHUNK_HEIGHT) + CHUNK_MARGIN) \
* GRID_HEIGHT
# register the callback to be called on SIGINT
signal.signal(signal.SIGINT, sighandler)
# initialize the ui thread with configured parameters
matrix_thread = MatrixThread(
windowWidth,
windowHeight,
PIXEL_WIDTH,
PIXEL_MARGIN,
CHUNK_WIDTH,
CHUNK_HEIGHT,
CHUNK_MARGIN,
GRID_WIDTH,
GRID_HEIGHT
)
# initialize the serial communicator
serial_thread = SerialThread(
matrix_thread,
CHUNK_WIDTH,
CHUNK_HEIGHT,
GRID_WIDTH,
GRID_HEIGHT
)
# run the serial thread to fetch data to draw
serial_thread.run()
# run while true with timeout of 60 seconds in order
# to save cpu time, but not exit the script
while True:
time.sleep(60)
# call the main function if this script isn't
# loaded as module
if __name__ == '__main__':
main()