-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledflinger.py
55 lines (43 loc) · 1.63 KB
/
ledflinger.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
import time, argparse, signal
import ping
from compositor import Compositor
from event_handler import EventHandler
parser = argparse.ArgumentParser(description='LEDFlinger arguments',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--fakeping', type=bool, default=False, help='Instead of actually checking the wifi status, ' \
'check for the existence of a file called ping/phone')
parser.add_argument('--minsec', type=bool, default=False, help='Show minutes/seconds instead of hours/minutes')
args = parser.parse_args()
screen_width = 32
screen_height = 8
size = (screen_width, screen_height)
comp = Compositor(size)
handler = EventHandler(comp, args.minsec)
def shutdown(signum, frame):
#comp.stop()
handler.stop(wait_for_finish=False)
signal.signal(signal.SIGTERM, shutdown)
def test(handler):
pingfunc = ping.is_phone_available_fake if args.fakeping else ping.is_phone_available
if args.fakeping:
open("ping/phone", "a").close()
connected = False
connected_previous = False
try:
while True:
connected = pingfunc()
#print("ping")
if connected and not connected_previous:
print("Starting composition")
handler.start()
handler.clock_start()
elif connected_previous and not connected:
print("Stopping composition")
handler.clock_stop()
handler.stop()
connected_previous = connected
time.sleep(1.)
except KeyboardInterrupt:
print("KeyboardInterrupt")
comp.save_debug_image()
test(handler)