-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·91 lines (80 loc) · 2.36 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import argparse
import time
import sys
from data import Data
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from views.controllers.main import MainController
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--led-rows",
action="store",
help="Display rows. 16 for 16x32, 32 for 32x32. (Default: 16)",
default=16,
type=int,
)
parser.add_argument(
"--led-cols",
action="store",
help="Panel columns. Typically 32 or 64. (Default: 32)",
default=32,
type=int,
)
parser.add_argument(
"--led-brightness",
action="store",
help="Sets brightness level. Range: 1..100. (Default: 100)",
default=100,
type=int,
)
parser.add_argument(
"--led-scan-mode",
action="store",
help="Progressive or interlaced scan. 0 = Progressive, 1 = Interlaced. (Default: 1)",
default=1,
choices=range(2),
type=int,
)
parser.add_argument(
"--led-show-refresh",
action="store_true",
help="Shows the current refresh rate of the LED panel.",
)
parser.add_argument(
"--led-slowdown-gpio",
action="store",
help="Slow down writing to GPIO. Range: 0..4. (Default: 2)",
default=2,
choices=range(5),
type=int,
)
return parser.parse_args()
def get_rgb_matrix_options(args: object) -> RGBMatrixOptions:
options = RGBMatrixOptions()
options.rows = args.led_rows
options.cols = args.led_cols
options.brightness = args.led_brightness
if args.led_show_refresh:
options.show_refresh_rate = 1
if args.led_slowdown_gpio != None:
options.gpio_slowdown = args.led_slowdown_gpio
return options
# Parse arguments
args = parse_args()
# Start fetching data
Data.start_all_data_threads()
# Initialize the RGB matrix
options = get_rgb_matrix_options(args=args)
rgb_matrix = RGBMatrix(options=options)
# Start the main controller - CTRL-C to exit
print(f"Running sunrise-alarm-clock-({rgb_matrix.height}x{rgb_matrix.width})")
main_controller = MainController(rgb_matrix=rgb_matrix)
main_controller.start()
try:
print("Press CTRL-C to stop running.")
main_controller.join()
except KeyboardInterrupt:
print("\nExiting.\n")
main_controller.stop()
main_controller.join()
sys.exit(0)