forked from riffnshred/nhl-led-scoreboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (52 loc) · 1.88 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
from datetime import datetime, timedelta
from data.scoreboard_config import ScoreboardConfig
from renderer.main import MainRenderer
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from utils import args, led_matrix_options
from data.data import Data
import debug
from api.main import ScoreboardApi
import threading
import sys
from dimmer import Dimmer
from apscheduler.schedulers.background import BackgroundScheduler
#For remote debugging only
#import ptvsd
# Allow other computers to attach to ptvsd at this IP address and port.
#ptvsd.enable_attach(address=('0.0.0.0', 3000), redirect_output=True)
# Pause the program until a remote debugger is attached
#ptvsd.wait_for_attach()
SCRIPT_NAME = "NHL Scoreboard"
SCRIPT_VERSION = "0.1.4"
def run():
# Get supplied command line arguments
commandArgs = args()
# Check for led configuration arguments
matrixOptions = led_matrix_options(commandArgs)
matrixOptions.drop_privileges = False
# Initialize the matrix
matrix = RGBMatrix(options = matrixOptions)
# Print some basic info on startup
debug.info("{} - v{} ({}x{})".format(SCRIPT_NAME, SCRIPT_VERSION, matrix.width, matrix.height))
# Read scoreboard options from config.json if it exists
config = ScoreboardConfig("config", commandArgs)
debug.set_debug_status(config)
data = Data(config)
# Event used to sleep when rendering
# Allows API to cancel the sleep
sleepEvent = threading.Event()
# Dimmer routine to automatically dim display
scheduler = BackgroundScheduler()
dimmer = Dimmer(scheduler, sleepEvent)
scheduler.start()
# Initialize API and run on separate thread
api = ScoreboardApi(data, dimmer, sleepEvent)
apiThread = threading.Thread(target=api.run, args=())
apiThread.daemon = True
apiThread.start()
MainRenderer(matrix, data, dimmer, sleepEvent).render()
try:
run()
except KeyboardInterrupt:
debug.info('Goodbye! :)')
sys.exit(0)