forked from Dinosauriel/led-proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (47 loc) · 1.79 KB
/
main.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
import argparse
import time
import config
import neopixel
import board
import util
import importlib
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--pattern", help="name of the pattern to be displayed")
parser.add_argument("-c", "--calibrate", choices=["server", "client"], help="mode to use for calibration. e.g. 'server' for raspberry pi, 'client' for laptop taking photos")
parser.add_argument("-g", "--gencoords", help="generate the coords.csv file from image folder")
return parser.parse_args()
def main():
args = get_args()
if args.calibrate == "server":
import calibrate_server
print(f"running calibration as {args.calibrate}")
calibrate_server.calibrate_server()
return
elif args.calibrate == "client":
import calibrate_client
print(f"running calibration as {args.calibrate}")
calibrate_client.calibrate_client()
return
if args.pattern != None:
print(f"running pattern {args.pattern}")
pixels = neopixel.NeoPixel(board.D18, config.NUM_LEDS, auto_write=False, pixel_order=neopixel.RGB, brightness=1.0)
try:
mod = importlib.import_module("patterns." + args.pattern)
except:
print(f"couln't find pattern \"{args.pattern}\". make sure \"patterns/{args.pattern}.py\" exists")
return
pattern = mod.Pattern(config.NUM_LEDS)
last_frame = 0
while not pattern.should_finish:
t = int(time.time() * 1000)
if t - last_frame >= pattern.interval:
last_frame = t
pixels[:] = pattern.draw(t)
pixels.show()
time.sleep(0.0005)
return
print("no command issued. exiting")
return
if __name__ == "__main__":
main()