class LumosNetwork(BaseNetwork): def __init__(self, universe): super(LumosNetwork, self).__init__() self.universe = universe self.client = DMXSource(universe=universe) def send_data(self): # TODO this doesn't seem the most efficient # but the only way to get "brightest element wins" # rendering that I could come up with self.reset() self.update_data() # format data values for DMX # TODO see update_data on BaseLightElement # the shift from float to 0-255 should happen here # but bytearray is being used with updatedata - so convertion # to byte has to happen earlier # self.data = [int(x * 255) for x in self.data] self.client.send_data(self.data)
import socket import struct # 239.256.0.1:5568 UDP_IP = "239.255.0.1" # UDP_IP = "127.0.0.1" UDP_PORT = 5568 multicast_group = ("239.255.0.1", 5568) sock = socket.socket( socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP # Set the time-to-live for messages to 1 so they do not go past the # local network segment. ttl = struct.pack('b', 1) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl) # Set a timeout so the socket does not block indefinitely when trying # to receive data. sock.settimeout(0.2) # sent = sock.sendto(p.packet, (UDP_IP, UDP_PORT)) src = DMXSource(UDP_IP, UDP_PORT, 1) import time for i in range(500): src.send_data(data) time.sleep(0.1)