-
Notifications
You must be signed in to change notification settings - Fork 1
/
dmxfs.py
executable file
·140 lines (116 loc) · 3.76 KB
/
dmxfs.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# dmx_followspot.py
# Copyright (C) 2018 Branson Matheson
from __future__ import print_function
import argparse
import array
import atexit
import io
import os
import pprint
import signal
import sys
import textwrap
from ola.ClientWrapper import ClientWrapper
import yaml
sys.path.append('lib')
from config import DFSConfig
from handler import DmxHandler
import logging as log
from show import Show
from stage import Stage
import xbox
__author__ = 'branson@sandsite.org'
def killall():
''' cleanup subprocesses .. needed for joystick'''
os.killpg(os.getpgrp(), signal.SIGHUP)
def setup_logging(args):
'''setup global logging and send a start entry'''
global debug, verbose
if args.debug:
log.basicConfig(
format="%(levelname)s: %(message)s",
level=log.DEBUG)
log.debug("Debugging enabled.")
debug = True
elif args.verbose:
log.basicConfig(
format="%(levelname)s: %(message)s",
level=log.INFO)
log.info("Verbose output.")
verbose = True
else:
log.basicConfig(format="%(levelname)s: %(message)s")
def parse_args():
'''
read in command-line arguments
'''
parser = argparse.ArgumentParser(
description="DMX Followspot")
# defaults
parser.set_defaults(debug=False)
parser.set_defaults(verbose=False)
parser.set_defaults(show_errors=False)
parser.set_defaults(check_mode=False)
parser.add_argument("-v", "--verbose", action="store_true",
help="Set verbose output.")
parser.add_argument("-d", "--debug", action="store_true",
help="Show debugging output.")
parser.add_argument("-c", "--check-mode", action="store_true",
help="check config files for readability")
parser.add_argument("-l", "--stage-name",
default='default',
help="load configured location")
parser.add_argument("-s", "--show-name",
default='default',
help="load specific show")
return parser.parse_args()
def main():
atexit.register(killall)
args = parse_args()
setup_logging(args)
# read tool config
config = DFSConfig()
# setup show
show = Show(config, args.show_name)
if not show:
print('no such show %s', args.show_name)
sys.exit(1)
# setup stage
stage = Stage(show, args.stage_name)
if not stage:
print('could not load or create stage %s', args.stage_name)
sys.exit(1)
# setup joystick
joy = xbox.Joystick(
debug=args.debug,
config=config.joystick
)
if args.check_mode:
sys.exit(0)
handler = DmxHandler(config, show, stage, joy)
# setup data handler, this is our callback loop
# as DMX data comes in constantly
wrapper = ClientWrapper()
rx = wrapper.Client()
rx.RegisterUniverse(
config.input.universe,
rx.REGISTER,
handler.handle)
wrapper.Run()
if __name__ == "__main__":
main()