-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (65 loc) · 2.56 KB
/
main.py
File metadata and controls
77 lines (65 loc) · 2.56 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
import sys
from os import getenv
from modules.controller import AnimationController
from pyghthouse.ph import Pyghthouse
from modules.lh_display import Display
from animations.a_bounce import BounceAnimation
ANIMATION_COLLECTIONS = {
"standard": [
BounceAnimation()
],
}
def main(gui: bool, remote: bool, fps: int, time_per_anim: int, collection: str | None):
user = getenv("LIGHTHOUSE_USER", None)
token = getenv("LIGHTHOUSE_TOKEN", None)
if remote and not (user and token):
# TODO: Load user and token from file if not present as environment variables
pass
animations = ANIMATION_COLLECTIONS.get(collection or "standard", [])
if not animations:
print(f"Error: Animation collection {collection} was not found!")
exit(1)
display = None
if gui:
display = Display(fps)
display.start()
pyghthouse = None
if remote and user and token:
pyghthouse = Pyghthouse(user, token, frame_rate=fps)
pyghthouse.start()
controller = AnimationController(animations=animations,
target_duration=time_per_anim,
speed_multiplier=1.0,
fallback_framerate=fps,
local_display=display,
pyghthouse_adapter=pyghthouse)
controller.run()
if pyghthouse:
pyghthouse.stop()
if display:
display.stop()
def print_usage():
print(f"Usage:\n{sys.argv[0]} [TIME] [OPTIONS]")
print("Whereas [TIME] = time in seconds and possible options are:")
print("--local\tRuns with local GUI only\n--gui\tRuns with both local GUI and remove connection")
print("--fps=x\tRuns with x fps (default=60)")
if __name__ == "__main__":
if len(sys.argv) > 1:
time_per_anim = int(sys.argv[1])
gui = False
remote = True
fps = 60
collection = None
for argument in sys.argv:
if '--local' in argument:
gui = True
remote = False
elif '--gui' in argument:
gui = True
elif '--fps=' in argument and len(argument) > 6 and str(argument).split('=')[1].isnumeric():
fps = int(str(argument).split('=')[1])
elif '--collection=' in argument and len(argument) > 13:
collection = str(argument).split('=')[1]
main(gui, remote, fps, time_per_anim, collection)
else:
print_usage()