def main(): def Plugins(state, plugins): for plugin in plugins: print('%d %s' % (plugin.id, plugin.name)) wrapper.Stop() def PluginDescription(state, description): print(description) wrapper.Stop() try: opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help", "plugin="]) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) plugin = None for o, a in opts: if o in ("-h", "--help"): Usage() sys.exit() elif o in ("-p", "--plugin"): plugin = int(a) wrapper = ClientWrapper() client = wrapper.Client() if plugin is not None: client.PluginDescription(PluginDescription, plugin) else: client.FetchPlugins(Plugins) wrapper.Run()
def start_wrapper(): global wrapper global client wrapper = ClientWrapper() client = wrapper.Client() wrapper.AddEvent(0, main_loop) wrapper.Run()
def processOLA(flag): global wrapper global universe global data wrapper = ClientWrapper() client = wrapper.Client() if (flag == 1): data = [] data = array.array('B') data.append(125) #Intencity data.append(255) #R data.append(255) #G data.append(255) #B print(data) ledON = 0 while (ledON < 10): # 10 == 10 SECONDS """ # THIS IS THE AMOUNT OF TIME WE SHOULD WAIT WHEN WE GET MOTION # THIS VALUE WILL BE THE VALUE THE LIGHT SHOULD REMAIN ON AFTER # MOTION HAS BEEN DETECTED. """ sleep(1) client.SendDmx(universe, data, DmxSent) wrapper.Run() ledON += 1 return return
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help", "plugin="]) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) plugin = None for o, a in opts: if o in ("-h", "--help"): Usage() sys.exit() elif o in ("-p", "--plugin"): plugin = int(a) global wrapper wrapper = ClientWrapper() client = wrapper.Client() if plugin is not None: client.PluginDescription(PluginDescription, plugin) else: client.FetchPlugins(Plugins) wrapper.Run()
class OlaThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.data = None def run(self): def onData(data): # TODO check on status before assigning data self.data = data #print(data) self.wrapper = ClientWrapper() self.client = self.wrapper.Client() universe = 1 self.client.RegisterUniverse(universe, self.client.REGISTER, onData) print('running thread') self.wrapper.Run() def exit(self): try: self.wrapper.Terminate() except: self.wrapper.Stop() def getData(self): # return or print? print(self.data)
def testSend(self): """tests that data goes out on the wire with SendDMX""" sockets = socket.socketpair() wrapper = ClientWrapper(sockets[0]) class results: gotdata = False def DataCallback(self): data = sockets[1].recv(4096) expected = binascii.unhexlify( "7d000010080110001a0d557064617465446d784461746122680801126400000" "000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000" "000000000000000000000000000000000000000000000000000000000000000" "000000") self.assertEqual(data, expected, msg="Regression check failed. If protocol change " "was intended set expected to: " + str(binascii.hexlify(data))) results.gotdata = True wrapper.AddEvent(0, wrapper.Stop) wrapper._ss.AddReadDescriptor(sockets[1], lambda: DataCallback(self)) self.assertTrue(wrapper.Client().SendDmx(1, array.array('B', [0] * 100), None)) wrapper.Run() self.assertTrue(results.gotdata)
def rec(ar): if ar.dev: serial_device = Serial(ar.dev, 115200, timeout=1) else: serial_device = Serial(detect_serial_device(), 115200, timeout=1) clip_name = ar.clip if not clip_name.endswith('.clip'): clip_name += '.clip' clip = open(os.path.join(CLIPS_DIR, clip_name), 'w') def dmxdata(data): global last if last == 0: td = 0 else: td = int((datetime.now() - last).total_seconds() * 1000) last = datetime.now() pickle.dump({'td': td, 'frm': data}, clip) send(data, serial_device) universe = 1 try: wrapper = ClientWrapper() except OLADNotRunningException: print("Start olad first") sys.exit(1) client = wrapper.Client() client.RegisterUniverse(universe, client.REGISTER, dmxdata) wrapper.Run()
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()
class OLAModel(object): def __init__(self, max_dmx, universe=0): # XXX any way to check if this is a valid connection? self.universe = universe self.wrapper = ClientWrapper() self.client = self.wrapper.Client() self.pixels = [0] * max_dmx def __repr__(self): return "OLAModel(universe=%d)" % self.universe # Model basics def cell_ids(self): # return PANEL_IDS return PANEL_MAP.keys() def set_pixel(self, ix, color): # dmx is 1-based, python lists are 0-based # I don't whole-heartedly believe in this anymore, but for consistency we're # keeping it for now ix = ix - 1 self.pixels[ix] = color.r self.pixels[ix + 1] = color.g self.pixels[ix + 2] = color.b def set_cell(self, cell, color): # cell is a string like "14b" # ignore unmapped cells if cell in PANEL_MAP: v = PANEL_MAP[cell] if type(v) is int: self.set_pixel(v, color) elif type(v) is list: for x in v: self.set_pixel(x, color) def set_cells(self, cells, color): for cell in cells: self.set_cell(cell, color) def set_eye_dmx(self, isParty, channel, value): "A direct access to the dmx control for the eyes. Party eye is before business eye" offset = PANEL_MAP["EYEp"] if not isParty: offset = PANEL_MAP["EYEb"] # Subtract 1 here so that the channels are always expressed in 1 indexed order as # is shown in the manual offset += channel - 1 self.pixels[offset] = value def go(self): data = array.array('B') data.extend(self.pixels) self.client.SendDmx(self.universe, data, callback)
class DMXServerThread(threading.Thread): wrapper = None TICK_INTERVAL = 1 # in ms SPEED = 3 # speed multiplier targetValues = [0, 0, 0, 0, 0, 0, 0, 0, 0] currentValues = [0, 0, 0, 0, 0, 0, 0, 0, 0] def __init__(self): print "DMXServerThread Init" threading.Thread.__init__(self) self.wrapper = ClientWrapper() def DmxSent(self, state): if not state.Succeeded(): print "DMX Sending Failed for some reason" self.wrapper.Stop() def SendDMXFrame(self): # continuously schedule the next function call self.wrapper.AddEvent(self.TICK_INTERVAL, self.SendDMXFrame) # if current values are within range of target, set to target; prevent target oscillation for i, v in enumerate(self.currentValues): diff = abs(self.targetValues[i] - v) if diff > 0 and diff <= self.SPEED: #print "Forcing channel %s to %s" % (i, v) self.currentValues[i] = v # Don't flood the dmx controller with unnecessary messages if self.currentValues == self.targetValues: return # compute next current value for each channel & add to frame data = array.array('B') for i, v in enumerate(self.targetValues): newVal = self.currentValues[i] + (cmp( self.targetValues[i] - self.currentValues[i], 0) * self.SPEED) #print newVal if (newVal > 255): newVal = 255 if (newVal < 0): newVal = 0 self.currentValues[i] = newVal data.append(self.currentValues[i]) self.wrapper.Client().SendDmx(1, data, self.DmxSent) def setTargets(self, _targetValues={}): for k, v in _targetValues.iteritems(): if not isinstance(k, int) or k > 10: print "Target channel is not an int or is out of range" return self.targetValues[k] = v def stop(self): self.wrapper.Stop() def run(self): self.wrapper.AddEvent(self.TICK_INTERVAL, self.SendDMXFrame) self.wrapper.Run()
def senddmx(data_in): universe = 1 global wrapper wrapper = ClientWrapper() client = wrapper.Client() # send 1 dmx frame with values for channels 1-6 client.SendDmx(universe, data_in, dmxsent) wrapper.Run()
class Main: def __init__(self): self.settings = yaml.load(open('settings.yaml', 'r')) self.serv = sockethandler.server( self.settings.get('address') or 'localhost', self.settings.get('port') or 25500) self.clients = [] self.switches = [] for switch in self.settings['switches'].items(): self.switches.append(Switch(switch[0], switch[1])) self.current_dmx = array.array('B', [0] * 512) self.wrapper = ClientWrapper() self.wrapper.AddEvent(100, self.loop) def loop(self): self.wrapper.AddEvent(100, self.loop) for msg, addr in self.serv.recv(): print(msg, addr) if not addr in self.clients: self.clients.append(addr) print('client ' + str(addr) + ' connected') if msg[0] == 'hi': self.serv.send(['hi'] + [s.name for s in self.switches], addr) elif msg[0] == 'on': self.switches[msg[1]].on() elif msg[0] == 'off': self.switches[msg[1]].off() elif msg[0] == 'bye': print('client ' + str(addr) + ' disconnected') self.clients.remove(addr) dmx = array.array('B', [0] * 512) msg = ['sw'] for switch in self.switches: addrs, val = switch.tick() for addr in addrs: dmx[addr - 1] = val msg.append(switch.active) for client in self.clients: self.serv.send(msg, client) if not dmx == self.current_dmx: self.wrapper.Client().SendDmx(self.settings['universe'], dmx, self.DmxSent) self.current_dmx = dmx def DmxSent(self, state): if not state.Succeeded(): wrapper.Stop()
def run(self, Universe, Count): global wrapper wrapper = None wrapper = ClientWrapper() self.client = wrapper.Client() while self._RunOK: Stride() self.client.SendDmx(Universe, DMXData, DmxSent) wrapper.Run() # send 1 dmx frame # print(DMXData[:50]) time.sleep(StrideLength)
def olaThread(adc, dest): try: opts, args = getopt.getopt(sys.argv[1:], "hu:", ["help", "universe="]) except getopt.GetoptError as err: print(str(err)) Usage() sys.exit(2) universe = 0 wrapper = ClientWrapper() client = wrapper.Client() client.RegisterUniverse(universe, client.REGISTER, NewData) wrapper.Run()
def senddmx(rgb_in): universe = 1 data = array.array('B') # first fixture data.append(rgb_in['rot']) # channel 1 rot data.append(rgb_in['gruen']) # channel 2 gruen data.append(rgb_in['blau']) # channel 3 blau data.append(0) # channel 4 weiss data.append(255) # channel 5 dimmer data.append(0) # channel 6 strobe # second fixture data.append(rgb_in['rot']) # channel 7 rot data.append(rgb_in['gruen']) # channel 8 gruen data.append(rgb_in['blau']) # channel 9 blau data.append(0) # channel 10 weiss data.append(255) # channel 11 dimmer data.append(0) # channel 12 strobe # third fixture data.append(rgb_in['rot']) # channel 13 rot data.append(rgb_in['gruen']) # channel 14 gruen data.append(rgb_in['blau']) # channel 15 blau data.append(0) # channel 16 weiss data.append(255) # channel 17 dimmer data.append(0) # channel 18 strobe # fourth fixture data.append(rgb_in['rot']) # channel 19 rot data.append(rgb_in['gruen']) # channel 20 gruen data.append(rgb_in['blau']) # channel 21 blau data.append(0) # channel 22 weiss data.append(255) # channel 23 dimmer data.append(0) # channel 24 strobe # fifth fixture data.append(rgb_in['rot']) # channel 25 rot data.append(rgb_in['gruen']) # channel 26 gruen data.append(rgb_in['blau']) # channel 27 blau data.append(0) # channel 28 weiss data.append(255) # channel 29 dimmer data.append(0) # channel 30 strobe # sixth fixture data.append(rgb_in['rot']) # channel 31 rot data.append(rgb_in['gruen']) # channel 32 gruen data.append(rgb_in['blau']) # channel 33 blau data.append(0) # channel 34 weiss data.append(255) # channel 35 dimmer data.append(0) # channel 36 strobe global wrapper wrapper = ClientWrapper() client = wrapper.Client() # send 1 dmx frame with values for channels 1-6 client.SendDmx(universe, data, dmxsent) wrapper.Run()
def main(a, b, c, d): universe = 0 data = array.array('B') # append first dmx-value for x in range(512): r1 = random.randint(0, 255) data.append(r1) global wrapper wrapper = ClientWrapper() client = wrapper.Client() # send 1 dmx frame with values for channels 1-3 client.SendDmx(universe, data, DmxSent) wrapper.Run()
def main(): serial_device = None if len(sys.argv) == 1: serial_device = Serial(detect_serial_device(), 115200, timeout=1) elif len(sys.argv) == 2: serial_device = Serial(sys.argv[1], 115200, timeout=1) configfile = open(settings.WALL_CONFIG_FILE, 'r') data = simplejson.load(configfile) configfile.close() w = int(data['w']) h = int(data['h']) mapping = {} for k, v in data['mapping'].items(): mapping[int(k)] = int(v) def dmxdata(data): print data pindex = 0 fdata = [] for y in range(h): for x in range(w): r = data[pindex * 3] g = data[pindex * 3 + 1] b = data[pindex * 3 + 2] color = correct_rgb((r, g, b)) fdata.extend([0xFF, mapping[y * w + x]]) fdata.extend(color) pindex += 1 serial_device.write("".join([chr(v) for v in fdata])) universe = 1 wrapper = None try: wrapper = ClientWrapper() except OLADNotRunningException: print "Start olad first" sys.exit(1) client = wrapper.Client() client.RegisterUniverse(universe, client.REGISTER, dmxdata) wrapper.Run()
def main(): args = ParseArgs() device = args.device port = args.port is_output = args.mode == 'output' action = OlaClient.PATCH if args.action == 'patch' else OlaClient.UNPATCH universe = args.universe global wrapper wrapper = ClientWrapper() client = wrapper.Client() client.PatchPort(device, port, is_output, action, universe, PatchPortCallback) wrapper.Run()
def main(): universe = 1 data = array.array('B') # append first dmx-value data.append(10) # append second dmx-value data.append(50) # append third dmx-value data.append(255) global wrapper wrapper = ClientWrapper() client = wrapper.Client() # send 1 dmx frame with values for channels 1-3 client.SendDmx(universe, data, DmxSent) wrapper.Run()
class DMXAdapter(LightAdapter): def __init__(self): pass def start(self): from ola.ClientWrapper import ClientWrapper from ola.DMXConstants import DMX_MIN_SLOT_VALUE, DMX_MAX_SLOT_VALUE, DMX_UNIVERSE_SIZE self._universe = 0 self._wrapper = ClientWrapper() self._client = self._wrapper.Client() self.run() # TODO We could use OLA's internal event scheduling system, but currently # I'm not aware of any obvious reason to do so. Nevertheless it bears # further investigation. def _sent_callback(self, status): if (not status.Succeeded()): # TODO catch this and report it in our heartbeat log.error("Failed to send DMX: %s" % status.message) # Always stop, as we call ourselves from a loop self._wrapper.Stop() def send(self, data): self._client.SendDmx(0, data, self._sent_callback) self._wrapper.Run() def run(self): dt_start = time.time_ns() # awkwardly wait around while we waight for an animator to be assigned while not self.animator: time.sleep(1) while True: dt = time.time_ns() - dt_start dt_start = time.time_ns() self.animator.step(dt / (10**9)) with self.animator.lock: self.send(self.animator.lightstate) # TODO use configuration time.sleep(1 / 60)
def main(): global wrapper wrapper = ClientWrapper() client = wrapper.Client() global l l = LightDrummer(client, 140) # Intro pb2 = PartyBar() pb2.set(PURPLE, BLUE, BLUE, PURPLE) l.run(twobardimmer(pb2)) def handle_input(input): exec input in globals(), globals() shell.run(l, handle_input)