-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmx.py
57 lines (41 loc) · 1.26 KB
/
dmx.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
import sacn
import time
import pyudmx
dev = pyudmx.uDMXDevice()
dev.open()
receiver = sacn.sACNreceiver()
receiver.start() # start the receiving thread
class lamp():
def __init__(self, lamptype):
self.lamptype = lamptype
self.dmx_packet = []
def rgb_to_dmx(self, r, g, b):
self.dmx_packet[r, g, b]
if self.lamptype == 'showtec':
self.dmx_packet += [0, 0, 0]
elif self.lamptype == 'ledrain':
self.dmx_packet += [0, 0, 0, 255]
return self.dmx_packet.
lamp_array = [
lamp('showtec'), # 0
lamp('showtec'), # 7
lamp('ledrain') # 13
]
# define a callback function
@receiver.listen_on('universe', universe=1) # listens on universe 1
def callback(packet): # packet type: sacn.DataPacket
dmx_packet = []
light_pos = 0
data = list(packet.dmxData)
for pos in range(0, len(data)):
if light_pos > len(lamp_array):
break
if pos + 1 % 3 == 0:
r = data[pos]
g = data[pos + 1]
b = data[pos + 2]
lamp = lamp_array[light_pos]
dmx_packet += lamp.rgb_to_dmx(r, g, b)
light_pos += 1
print(dmx_packet)
dev.send_multi_value(1, dmx_packet)