def DMXsent(self, IP, universe, Brightness): #universe = self.m_spinCtrlUniverse.GetValue() #startaddress = self.m_spinCtrlStartAddress.GetValue() #channel = self.m_textCtrlChannel.GetValue() #IP = self.m_textCtrlIP.GetValue() #judge procesing platform while not self.m_radioBox1.GetSelection(): #Brompton selected sender = sacn.sACNsender() sender.start() sender.activate_output(universe) sender[universe].destination = IP sender[universe].dmx_data = (255, 255, 255, Brightness) time.sleep(0.5) sender.stop() break else: #MVR selcted sender = sacn.sACNsender() sender.start() sender.activate_output(universe) sender[universe].destination = IP sender[universe].dmx_data = (0, 0, Brightness) time.sleep(0.5) sender.stop() print(sender[universe].destination) print(Brightness)
def test_constructor(): cid = tuple(range(0, 16)) source_name = 'test' socket = SenderSocketTest() # test default values for constructor sender = sacn.sACNsender(socket=socket) assert sender._sender_handler._source_name == 'default source name' assert len(sender._sender_handler._CID) == 16 assert sender.universeDiscovery is True assert sender._sync_universe == 63999 assert sender.manual_flush is False # test explicit values for constructor bind_address = 'test_address' bind_port = 1234 fps = 40 universe_discovery = False sync_universe = 4567 sender = sacn.sACNsender(bind_address, bind_port, source_name, cid, fps, universe_discovery, sync_universe, socket) assert sender._sender_handler._source_name == source_name assert sender._sender_handler._CID == cid assert sender.universeDiscovery == universe_discovery assert sender._sync_universe == sync_universe assert sender.manual_flush is False
def test_getitem(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) assert sender[1] is None sender.activate_output(1) assert sender[1] == sender._outputs[1]
def __init__(self, config=[], cache=False, quiet=False, debug=False): self.running = False if quiet: verbose_level = logging.CRITICAL else: verbose_level = logging.DEBUG if debug else logging.INFO self.__quiet = quiet self.__debug = debug self.__config = config self.__should_cache = cache self.__logger = logging.getLogger(__class__.__name__) self.__logger.setLevel(verbose_level) self.__animation = None self.__step = 0 self.__decay = 0 self.__sonoff = Sonoff(broker=MQTT_BROKER_HOST, device="desktop", quiet=self.__quiet, debug=self.__debug) self.__cache_path = join(dirname(dirname(abspath(__file__))), "cache") self.__placeholder = np.array([0] * 512) self.__holiday_checker = HolidayChecker(quiet=quiet, debug=debug) for x in range(0, len(self.__config)): if not self.__config[x]['sync']: continue self.__config[x]['universes'] = ceil(self.__config[x]['channels'] / DEFAULT_STRIP_PIXELS) self.__config[x]['sender'] = sacn.sACNsender(fps=1500) self.__config[x]['queue'] = None self.__config[x]['thread'] = None # Effect cache self.__config[x]['matrix'] = None
def __setup_devices(self): for x in range(0, len(self.__config)): if not self.__config[x]['sync']: continue self.__config[x]['sender'] = sacn.sACNsender(fps=800) self.__config[x]['sender'].start() self.__config[x]['sender'].manual_flush = True self.__config[x]['queue'] = queue.Queue() self.__restart_worker(x) first_send = False while not first_send: try: for u in range(1, self.__config[x]['universes'] + 1): self.__config[x]['sender'].activate_output(u) self.__config[x]['sender'][u].multicast = False self.__config[x]['sender'][ u].destination = self.__config[x]['ip'] self.__config[x]['sender'][u].dmx_data = bytearray( [0] * 512) self.__config[x]['sender'].flush() first_send = True except: pass sleep(0.1) self.__logger.debug( f"Detected: LedStrip<ip: {self.__config[x]['ip']}, universes: {self.__config[x]['universes']}, leds: {self.__config[x]['channels']}, name: {self.__config[x]['name']}>" )
def test_universe_discovery_setting(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) assert sender.universeDiscovery is True assert sender._sender_handler.universe_discovery is True sender.universeDiscovery = False assert sender.universeDiscovery is False assert sender._sender_handler.universe_discovery is False
def __init__(self, bind_address: str, brightness: float = 1.0): self.brightness = brightness self.sender = sacn.sACNsender( bind_address=bind_address, universeDiscovery=False, ) # dict of DMX universe to a list of DMX channels self.universes = {}
def test_manual_flush_setting(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) assert sender.manual_flush is False assert sender._sender_handler.manual_flush is False sender.manual_flush = True assert sender.manual_flush is True assert sender._sender_handler.manual_flush is True
def __init__(self): self.sender = sacn.sACNsender() self.sender.start(bind_address=config.bind_address) self.queue = [] self.devices = {} self.thread_running = True self.thread = threading.Thread(target=self.process_queue_loop, args=(config.mspt, ))
def __init__(self, bind_address, num_hexes, brightness=1.0): self.num_hexes = num_hexes self.brightness = brightness self.sender = sacn.sACNsender( bind_address=bind_address, universeDiscovery=True, ) self.leds = {} # { h: 512 ints (3 for each LED) }
def reconnect(self): """ Recreate and set up the sender """ self.sender = sacn.sACNsender() self.sender.start() self.sender.activate_output(self.universe) self.sender[self.universe].destination = self.ip self.is_connected = True
def test_output_preview_data(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) # test default assert sender[1].preview_data is False # test setting and retriving the value test = True sender[1].preview_data = test assert sender[1].preview_data == test
def test_output_priority(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) # test default assert sender[1].priority == 100 # test setting and retriving the value test = 200 sender[1].priority = test assert sender[1].priority == test
def test_output_multicast(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) # test default assert sender[1].multicast is False # test setting and retriving the value test = True sender[1].multicast = test assert sender[1].multicast == test
def test_output_destination(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) # test default assert sender[1].destination == '127.0.0.1' # test setting and retriving the value test = 'test' sender[1].destination = test assert sender[1].destination == test
def test_move_universe(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) output = sender._outputs[1] assert list(sender._outputs.keys()) == [1] assert sender._outputs[1] == output sender.move_universe(1, 2) assert list(sender._outputs.keys()) == [2] assert sender._outputs[2] == output
def __init__(self, max_dmx, model_json=None): # XXX any way to check if this is a valid connection? self.sender = sacn.sACNsender( bind_address="192.168.1.210", universeDiscovery=False ) # Must supply an IP address to bind to that is in the same subnet as the devices routiung the universes. Might haave to assign a second IP to the eth adapter to get this to work (this is what I had to do on my mac) self.sender.start() self.PIXEL_MAP = None self.leds = { } # dictionary which will hold an array of 512 int's for each universe, universes are keys to the arrays. self._map_leds(model_json)
def test_output_ttl(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) # test default assert sender[1].ttl == 8 # test setting and retriving the value test = 16 sender[1].ttl = test assert sender[1].ttl == test
def test_output_dmx_data(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) sender.activate_output(1) # test default assert sender[1].dmx_data == tuple([0] * 512) # test setting and retriving the value test = tuple([x % 256 for x in range(0, 512)]) sender[1].dmx_data = test assert sender[1].dmx_data == test
def create_sender(pixel_strips: List[PixelStrip], **kwargs): sender = sacn.sACNsender(**kwargs) # provide an IP-Address to bind to if you are using Windows and want to use multicast sender.start() # start the sending thread for i, pixel_strip in enumerate(pixel_strips): universe = pixel_strip.universe sender.activate_output(universe) # multicast is not working for whatever reason sender[universe].multicast = False sender[universe].destination = pixel_strip.strip_addr return sender
def test_stop(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) assert socket.stop_called is False sender.stop() assert socket.stop_called is True # a second time is not allowed to throw an exception assert socket.stop_called is True sender.stop() assert socket.stop_called is True
def startsACN(universeModel, pixelModel, maxUniverses, consoleEnableChannel, unicastIP, priority): global receiver, sender, running, consoleEnableCh, unicastdest consoleEnableCh = consoleEnableChannel unicastdest = unicastIP receiver = sacn.sACNreceiver() sender = sacn.sACNsender() receiver.start() sender.start() createUniverses(universeModel, maxUniverses, priority) createMap(pixelModel) running = True
def __init__(self, config): super().__init__(config) self.outputs.append(ledStrip('flag', '10.10.10.71', 50, 2)) self.outputs.append(ledStrip('shelves', '10.10.10.72', 46, 3)) self.outputs.append(ledStrip('backwall', '10.10.10.73', 50, 4)) self.sacn = sacn.sACNsender() self.sacn.start() self.pink = True self.sacn.manual_flush = True for ls in self.outputs: print("Activating led strip named {}".format(ls.name)) self.sacn.activate_output(ls.universe) self.sacn[ls.universe].destination = ls.ip
def test_get_active_outputs(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) # none active assert sender.get_active_outputs() == tuple([]) # one active sender.activate_output(1) assert sender.get_active_outputs() == tuple([1]) # two active sender.activate_output(2) assert sender.get_active_outputs() == tuple([1, 2])
def stable(color): sender = sacn.sACNsender() sender.start() if color == "white": dmxcolor = (255,147,41) singlecolor = 1 elif color == "green": dmxcolor = (0,255,0) singlecolor = 1 elif color == "red": dmxcolor = (255,0,0) singlecolor = 1 elif color == "blue": dmxcolor = (0,0,255) singlecolor = 1 elif color == "redgreen": dmxcolor = (0,255,0,255,0,0) singlecolor = 0 else: usage() sender.stop() sys.exit() for universe in range(startuniverse,(enduniverse)+1): sender.activate_output(universe) sender[universe].destination = dmxreceiver for pixel in range(0, len(pixels)): pixeltype = pixels[pixel][0] universe = pixels[pixel][1] numpixels = pixels[pixel][2] if singlecolor == 1: dmxdata = (dmxcolor * int(numpixels)) else: dmxdata = (dmxcolor * int(numpixels/2)) if debug == 1: print('Pixeltype: %s, Universe: %s, Numpixels: %s, Color: %s, DMXColor: %s' % (pixeltype,universe,numpixels,color, dmxcolor)) sender[universe].dmx_data = dmxdata sender.manual_flush = False time.sleep(1) sender.stop() sys.exit()
def __init__(self, start_universe=1, start_channel=1, channel_count=3, universe_size=512, fps=30, ip='192.168.1.180'): """Initialize object for communicating with as E1.31 capable device. Parameters ---------- start_universe: int, optional The start universe for the strip start_channel: int, optional The state channel offset within the universe channel_count: int, optional The total number of channels for the device. Typically this will be 3 * N_PIXELS as you need a sperate channel for the red, green, and blue components universe_size: int, optional The number of channels in each universe. This should pretty much never be changed unless using a controller that only support 510 channels. ip: str, optional The IP address of a E1.31 capable device on the network. fps: int, optional The frequency in which to flush the DMX buffer out. This does not need to align with the actually processing rate. Running the processing at 60fps and flusing at 30fps provides a pretty good balance. """ import sacn self._ip = ip self._start_universe = start_universe self._start_channel = start_channel self._channel_count = channel_count self._universe_size = universe_size self._sender = sacn.sACNsender() self._sender._fps = fps self._sender.start() self._stop_universe = start_universe + round(0.5 + ( (start_channel + channel_count) / universe_size)) for universe in range(self._start_universe, self._stop_universe): self._sender.activate_output(universe) self._sender[universe].destination = ip self._sender[universe].multicast = False
def test_activate_output(): socket = SenderSocketTest() sender = sacn.sACNsender(socket=socket) # start with no universes active assert list(sender._outputs.keys()) == [] # activate one universe sender.activate_output(1) assert list(sender._outputs.keys()) == [1] # activate another universe sender.activate_output(63999) assert list(sender._outputs.keys()) == [1, 63999] # check that a universe can not be enabled twice sender.activate_output(1) assert list(sender._outputs.keys()) == [1, 63999]
def start_sequence(**kwargs): """ Main sequence """ dmx = BuildDMX(pixels=kwargs['pixels'], fps=kwargs['fps'], brightness=kwargs['brightness'], multi=kwargs['multi'], rr=kwargs['rr'], rl=kwargs['rl'], ip=kwargs['ip']) previous_dmx: dict = {} recording_device = sc.get_microphone(kwargs['deviceid'], include_loopback=True) sender = sacn.sACNsender() try: i = 0 while True: data = recording_device.record(samplerate=kwargs['sampleRate'], numframes=kwargs['defaultframes'], blocksize=256) if data is not None: (dmx_data, previous_dmx) = dmx.output(data, previous_dmx) if not sender.get_active_outputs(): if any(map(lambda ele: ele != 0, dmx_data)): sender.activate_output(1) sender[1].destination = kwargs['ip'] sender.start() else: sender[1].dmx_data = dmx_data if not any(map(lambda ele: ele != 0, dmx_data)): # Don't deactivate too quickly. Wait a few seconds. if i >= 500: sender.deactivate_output(1) sender.stop() i = 0 i += 1 terminal_led(dmx_data) time.sleep(0.01) except KeyboardInterrupt: sender.stop() cursor.show()
def activate(self): if self._config["ip_address"].lower() == "multicast": multicast = True else: multicast = False if self._sacn: raise Exception("sACN sender already started.") if multicast is False: self.device_ip = resolve_destination(self._config["ip_address"]) if not self.device_ip: _LOGGER.warning( f"Cannot resolve destination {self._config['ip_address']}, aborting device {self.name} activation. Make sure the IP/hostname is correct and device is online." ) return if wled_identifier(self.device_ip, self.name): self.WLEDReceiver = True self.wled_state = wled_power_state(self.device_ip, self.name) if self.wled_state is False: turn_wled_on(self.device_ip, self.name) # Configure sACN and start the dedicated thread to flush the buffer # Some variables are immutable and must be called here self._sacn = sacn.sACNsender(source_name=self.name) for universe in range(self._config["universe"], self._config["universe_end"] + 1): _LOGGER.info(f"sACN activating universe {universe}") self._sacn.activate_output(universe) self._sacn[universe].priority = self._config[ "e131_Packet_Priority"] if self._config["ip_address"] == "multicast": self._sacn[universe].multicast = True else: self._sacn[universe].destination = self.device_ip self._sacn[universe].multicast = False self._sacn._fps = self._config["refresh_rate"] self._sacn.start() self._sacn.manual_flush = True _LOGGER.info("sACN sender started.") super().activate()
def activate(self): if self._sacn: raise Exception('sACN sender already started.') # Configure sACN and start the dedicated thread to flush the buffer self._sacn = sacn.sACNsender() for universe in range(self._config['universe'], self._config['universe_end'] + 1): _LOGGER.info("sACN activating universe {}".format(universe)) self._sacn.activate_output(universe) if (self._config['ip_address'] == None): self._sacn[universe].multicast = True else: self._sacn[universe].destination = self._config['ip_address'] self._sacn[universe].multicast = False #self._sacn.fps = 60 self._sacn.start() _LOGGER.info("sACN sender started.") super().activate()
#!/usr/bin/env python3 # From https://github.com/Hundemeier/sacn import sacn import time import sys color = [0, 0, 0] # Black by default if len(sys.argv) == 4: color[0] = int(sys.argv[1]) color[1] = int(sys.argv[2]) color[2] = int(sys.argv[3]) print("Color: ", color[0], " ", color[1], " ", color[2]) channels = 510 # number of channels per universe maxUniv = 74 # Total numbers of universes sender = sacn.sACNsender() # provide an IP-Address to bind to if you are using Windows and want to use multicast sender.start() # start the sending thread # sender[univ].multicast = False # set multicast to True # Keep in mind that if multicast is on, unicast is not used for univ in range(1, maxUniv): sender.activate_output(univ) # start sending out data in the 1st universe sender[univ].destination = "fpp" # or provide unicast information. for count in range(1, 10): for univ in range(1, maxUniv): # sender[univ].dmx_data = (0, 255, 0, 255, 0, 0, 255, 255, 255) # some test DMX data row = [] for i in range(0, 510, 3): row.append(color[0]) row.append(color[1])