-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplayserver_service.py
63 lines (46 loc) · 1.6 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
60
61
62
63
"""
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 will handle the request and updates the
display according to the content of the request. If there is are
no further request wihtin a specified time period, the clock will be shown again.
"""
import net
import time
import displayprovider
import binclock
import threading
# 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():
print("starting display service. Request timeout is", REQUEST_TIMEOUT, "seconds")
fdd = None
while fdd is None:
try:
fdd = displayprovider.get_display(fallback=None)
except Exception as e:
print("Unable to create display:", e)
time.sleep(5)
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()