class ColorsOut: def __init__(self, streamclass="something"): self.client = OSCClient() self.client.connect(("localhost", 11661)) self.title = "Something went wrong" try: print "argv[0] " + sys.argv[0] print "getcwd " + os.getcwd() path = os.getcwd() + "/" + sys.argv[0] path = path.replace("main.py", "") manifest = open(path + "manifest.json") data = simplejson.load(manifest) self.title = data["name"] self.creator = data["creator"] self.description = data["description"] manifest.close() except: print "Hey we died" self.framenumber = 0 self.streamclass = streamclass def write(self, pixels): #pixels = self.crazyMofoingReorderingOfLights(pixels) chroma = ChromaMessage(pixels, self.title, self.streamclass, self.framenumber, self.creator, self.description) message = chroma.toOSC("/setcolors") #print "Sending message %s"%str(pixels) self.client.send(message) self.framenumber += 1
class ColorsOut: def __init__(self, streamclass="something"): self.client = OSCClient() self.client.connect( ("localhost",11661) ) self.title = "Something went wrong" try: print "argv[0] "+sys.argv[0] print "getcwd "+os.getcwd() path = os.getcwd()+"/"+sys.argv[0] path = path.replace("main.py","") manifest = open(path+"manifest.json") data = simplejson.load(manifest) self.title = data["name"] self.creator = data["creator"] self.description = data["description"] manifest.close() except: print "Hey we died" self.framenumber = 0 self.streamclass = streamclass def write(self, pixels): #pixels = self.crazyMofoingReorderingOfLights(pixels) chroma = ChromaMessage(pixels, self.title, self.streamclass, self.framenumber, self.creator, self.description) message = chroma.toOSC("/setcolors") self.client.send( message ) self.framenumber += 1
def _connect(): settings = _read_settings() client = OSCClient(settings['ion-ip'], int(settings['ion-port'])) try: client.connect() except (socket.timeout, TimeoutError, ConnectionRefusedError): return None return client
class ColorsOut: def __init__(self): self.client = OSCClient() self.client.connect( ("localhost",11661) ) def write(self, pixels): message = OSCMessage("/setcolors") pixels = self.crazyMofoingReorderingOfLights(pixels) message.append(pixels) self.client.send( message ) def diff(self, pixels): message = OSCMessage("/diffcolors") message.append(pixels) self.client.send( message ) def crazyMofoingReorderingOfLights(self, pixels): pixels2 = pixels[:] #make a copy so we don't kerplode someone's work """ what are we expecting? we want the back left (by the couches) of the room to be pixel 0, and by the front is the last row whereas in reality, it's the opposite. here is the order it'd be nice to have them in: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 this is the actual order: 23 22 21 20 19 16 17 18 15 14 13 12 11 10 9 8 3 2 5 4 6 *0**1**7* *=not there """ actualorder = [23,22,21,20,19,16,17,18,15,14,13,12,11,10,9,8,3,2,5,4,6,0,1,7] badcolors = [3,2,5,4,6,0,1,7] for i in range(len(actualorder)): (r,g,b) = pixels[i] r = max(0.0, min(r, 1023.0)) g = max(0.0, min(g, 1023.0)) b = max(0.0, min(b, 1023.0)) pixels2[actualorder[i]] = (r,g,b) for i in range(len(badcolors)): pixels2[badcolors[i]] = (0.0,0.0,0.0) return pixels2
class ColorsOut: def __init__(self, title="demo", streamclass="something"): self.client = OSCClient() self.client.connect( ("localhost",11661) ) self.title = title self.framenumber = 0 self.streamclass = streamclass def write(self, pixels): #pixels = self.crazyMofoingReorderingOfLights(pixels) chroma = ChromaMessage(pixels, self.title, self.streamclass, self.framenumber) message = chroma.toOSC("/setcolors") self.client.send( message ) self.framenumber += 1
parser = argparse.ArgumentParser( description="Run a specific chroma animation script.") parser.add_argument('animation', metavar='animation', help='One of these animations: ' + string.join(os.listdir('animations/'), ', '), choices=os.listdir('animations/')) args = parser.parse_args() animation = args.animation # Open emulator if there's no OSC responsive on that port already try: sys.path.append("./osc") from osc import OSCClient, OSCMessage s = OSCClient() s.connect(('localhost', 11661)) # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) except Exception, e: if '[Errno 61]' in str(e): print "Starting emulator, since it doesn't seem to be running yet." os.system('emulator/lights_emulator > /dev/null &') emu_up = False while not emu_up: try: # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) emu_up = True except Exception, e:
# Argument handling parser = argparse.ArgumentParser(description="Run a specific chroma animation script.") parser.add_argument('animation', metavar='animation', help='One of these animations: '+string.join(os.listdir('animations/'),', '), choices=os.listdir('animations/')) args = parser.parse_args() animation = args.animation # Open emulator if there's no OSC responsive on that port already try: sys.path.append("./osc") from osc import OSCClient,OSCMessage s=OSCClient() s.connect(('localhost',11661)) # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) except Exception,e: if '[Errno 61]' in str(e): print "Starting emulator, since it doesn't seem to be running yet." os.system('emulator/lights_emulator > /dev/null &') emu_up = False while not emu_up: try: # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) emu_up = True except Exception,e:
#!/usr/bin/python from osc import OSCServer, OSCClient, OSCMessage import sys if __name__ == "__main__": if len(sys.argv) < 2: print """ sendcommand.py: sends commands to the running oscapi.py daemon. usage: ./sendcommand.py command available commands: reloadconfig - reloads config.py in the octoapi - usually reordering the lights """ sys.exit(-1) messagename = sys.argv[1] client = OSCClient() client.connect( ("localhost",11661) ) message = OSCMessage('/'+messagename) for param in sys.argv[2:]: message.append(param) client.send( message )