-
Notifications
You must be signed in to change notification settings - Fork 0
/
displayserver_service.py
59 lines (42 loc) · 1.38 KB
/
displayserver_service.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
"""
This service script starts the display server. It is run by a systemd
startup script. The server shows a clock display until a request is
detected. In this case the server handle the request and updates the
display according to the content of the request. If there is are
no further request, the clock will be shown again.
"""
import net
import displayprovider
import binclock
import threading
# dimension of the display
WIDTH, HEIGHT = 28, 13
# list of GPIO-pins connected to the modules
MODULES = [14]
# time to wait for request before clock should be turned on again
REQUEST_TIMEOUT = 5 # seconds
def on_request():
"""Turn off the clock on a request and wait for some time."""
global clock, timer
clock.visible = False
timer.cancel()
timer = threading.Timer(REQUEST_TIMEOUT, time_over)
timer.start()
def time_over():
"""Time has exceeded without request. Turn the clock on again."""
print("long time no request, restarting clock")
clock.visible = True
clock = None
timer = threading.Timer(0, time_over)
def main():
fdd = displayprovider.get_display()
print("starting display", fdd)
displayserver = net.DisplayServer(fdd)
displayserver.on_request = on_request
global clock
clock = binclock.BinClock(fdd)
th = threading.Thread(target=clock.run)
th.start()
displayserver.start()
if __name__ == "__main__":
main()