-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpanel_setup.py
executable file
·312 lines (228 loc) · 6.94 KB
/
panel_setup.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import array
import traceback
from ola.ClientWrapper import ClientWrapper
import json
universe = 0
wrapper = ClientWrapper()
client = wrapper.Client()
pixels = [255] * 512
eye_p = 0
eye_b = 0
MAX_PANEL = 90
panels = []
for i in range(0, MAX_PANEL):
panels.append( [ [], [] ] )
is_dirty = False
# When this is set to true by a handler, the "known mappings" UI display is not output
# after the handler is done. It must be reset each time.
skip_known = False
dmx_cursor = 1
def print_mapping(a):
if len(a) == 0:
print(" ", end=' ')
return
print("%3d" % (a[0]), end=' ')
if len(a) > 1:
print("\u2026", end=' ')
else:
print(" ", end=' ')
def print_known():
print(" panel number[ party dmx, business dmx]")
for i in range(1, MAX_PANEL):
if i > 1 and (i-1) % 6 == 0:
print("")
p = panels[i]
print("%2d[" % i, end=' ')
print_mapping(p[0])
print(",", end=' ')
print_mapping(p[1])
print("]", end=' ')
print("")
def callback(s):
print(s)
def go():
data = array.array('B')
data.extend(pixels)
client.SendDmx(universe, data, callback)
# print "data %s" % str(data)
def change_dmx(delta):
# Because DMX is 1 based and lists are 0, we subtract 1 from the value
# when writing to a buffer list
global dmx_cursor
pixels[dmx_cursor-1] = 255
pixels[dmx_cursor] = 255
pixels[dmx_cursor+1] = 255
dmx_cursor += delta
if dmx_cursor < 1:
dmx_cursor = 1
if dmx_cursor > 510:
dmx_cursor = 510
pixels[dmx_cursor-1] = 255
pixels[dmx_cursor] = 0
pixels[dmx_cursor+1] = 0
def goto_dmx(addr):
global dmx_cursor
pixels[dmx_cursor-1] = 255
pixels[dmx_cursor] = 255
pixels[dmx_cursor+1] = 255
dmx_cursor = addr
if dmx_cursor < 1:
dmx_cursor = 1
if dmx_cursor > 510:
dmx_cursor = 510
pixels[dmx_cursor-1] = 255
pixels[dmx_cursor] = 0
pixels[dmx_cursor+1] = 0
def clear_panel(panel):
print("Clearing panel %s" % panel)
panels[panel] = [[],[]]
def show_mapping(m):
for x in m:
print("%3d " % (x), end=' ')
def show_panel(panel):
global skip_known
skip_known = True
print("Panel %d" % panel)
print(" party: ", end=' ')
show_mapping(panels[panel][0])
print("\nbusiness: ", end=' ')
show_mapping(panels[panel][1])
def print_help():
global skip_known
skip_known = True
print("help - show this summary")
print("exit - exit if data has not changed")
print("quit - exit if data has not changed, must use quit! if the data has changed")
print("save - save the current mapping to dmx_setup.json (which is not the file loaded by default)")
print("n, no, next - Advance DMX mapping by 3")
print("p, prev - Move DMX cursor backwards by 3")
print("u - Bump DMX up by 1")
print("d - Bump DMX down by 1")
print("goto <num> - Move cursor to channel <num>")
print("clear <panel_num> - Remove all mappings for <panel_num>")
print("show <panel_num> - Show detail for <panel_num>")
def write_mapping(f, panel, m):
f.write("\t")
f.write("\"%s\": [" % panel)
started = False
for x in m:
if started:
f.write(", ")
started = True
f.write("%d" % x)
f.write("],\n")
def save():
global is_dirty
global skip_known
# Do this all by hand because we want a particular human editable ordering
with open("dmx_setup.json", "w") as f:
f.write("{\n")
for i in range(1, MAX_PANEL):
p = panels[i]
if len(p[0]) > 0:
write_mapping(f, "%dp" % i, p[0])
# f.write("\t\"%dp\": [" % (i))
# for x in p[0]:
# f.write("%d")
# if p[0] != -1:
# f.write("\t\"%dp\": %d,\n" % (i, p[0]))
f.write("\n")
for i in range(1, MAX_PANEL):
p = panels[i]
if len(p[1]) > 0:
write_mapping(f, "%db" % i, p[1])
# if p[1] != -1:
# f.write("\t\"%db\": %d,\n" % (i, p[1]))
f.write("\n")
f.write("\t\"EYEp\": %d,\n" % (eye_p))
f.write("\t\"EYEb\": %d\n" % (eye_b))
f.write("}\n")
print("\n Saved to dmx_setup.json")
is_dirty = False
skip_known = True
def handle_mapping(id):
global is_dirty
try:
num = int(id[:-1])
except ValueError:
print("Invalid id '%s' ids must be an integer followed by either p or b like 17b or 42b" % id)
s = id[-1:]
if s != "p" and s != "b":
print("Invalid id '%s' ids must be an integer followed by either p or b like 17b or 42b" % id)
return
s_ix = 0
if s == 'b':
s_ix = 1
panels[num][s_ix].append( dmx_cursor )
change_dmx(3)
is_dirty = True
def handle_command(cmd):
try:
if cmd == "help":
print_help()
elif cmd == "exit" or cmd == "quit":
if is_dirty:
print("Use quit! to exit without saving")
else:
return False
elif cmd == "quit!" or cmd == "q!":
return False
elif cmd == "save":
save()
elif cmd == "n" or cmd == "no" or cmd == "next":
change_dmx(3)
elif cmd == "p" or cmd == "prev":
change_dmx(-3)
elif cmd == "u":
change_dmx(1)
elif cmd == "d":
change_dmx(-1)
elif cmd[:4] == "goto":
goto_dmx(int(cmd[5:]))
elif cmd[:5] == "clear":
clear_panel(int(cmd[6:]))
elif cmd[:4] == "show":
show_panel(int(cmd[5:]))
elif cmd == "":
pass
else:
handle_mapping(cmd)
except Exception:
traceback.print_exc()
return True
if __name__=='__main__':
# Load existing things
with open('data/dmx_mapping.json', 'r') as f:
PANEL_MAP = json.load(f)
for key in PANEL_MAP:
try:
num = int(key[:-1])
except ValueError:
continue
if num >= MAX_PANEL:
print("Ignoring %s because max panel is %d" % (key, MAX_PANEL))
continue
v = PANEL_MAP[key]
if type(v) is int:
v = [v]
if key[-1:] == "p":
panels[num][0] = panels[num][0] + v
else:
panels[num][1] = panels[num][1] + v
eye_p = PANEL_MAP.get("EYEp") or 0
eye_b = PANEL_MAP.get("EYEb") or 0
goto_dmx(0)
while True:
if not skip_known:
print_known()
skip_known = False
print("")
print("DMX = %d What's on? (enter a panel id or 'help' for more)" % (dmx_cursor))
go()
try:
cmd = input("> ")
except KeyboardInterrupt:
cmd = "exit"
if not handle_command(cmd):
print("")
break