Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

whoos forgot osc.py

  • Loading branch information...
commit 89a077794a07d6edfd3681f03be5f179bf8c254e 1 parent d4e8930
@rjmarsan rjmarsan authored
Showing with 56 additions and 27 deletions.
  1. +56 −27 lights/python/osc.py
View
83 lights/python/osc.py 100644 → 100755
@@ -1,3 +1,4 @@
+#!/usr/bin/python
from OSC import OSCServer, OSCClient, OSCMessage
import sys
import time
@@ -5,44 +6,67 @@
# funny python's way to add a method to an instance of a class
import types
+def handle_timeout(self):
+ self.timed_out = True
+class ColorsIn:
# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
-def handle_timeout(self):
- self.timed_out = True
-def set_colors(path, tags, args, source):
- # which user will be determined by path:
- # we just throw away all slashes and join together what's left
- print "Here's what we got : path:%s tags:%s args:%s source:%s"%(str(path),str(tags),str(args),str(source))
- pixels = []
- for i in range(0,len(args)/3):
- pixel = (args[i*3],args[i*3+1],args[i*3+2])
- pixels.append( pixel )
- #print "Pixels: %s"%str(pixels)
- #print "Time: "+str((time.time()*1000) % 10000)
- #octoapi.write(pixels)
+ def set_colors(self,path, tags, args, source):
+ # which user will be determined by path:
+ # we just throw away all slashes and join together what's left
+ #print "Here's what we got : path:%s tags:%s args:%s source:%s"%(str(path),str(tags),str(args),str(source))
+ pixels = []
+ for i in range(0,len(args)/3):
+ pixel = (args[i*3],args[i*3+1],args[i*3+2])
+ pixels.append( pixel )
+ #print "Pixels: %s"%str(pixels)
+ #print "Time: "+str((time.time()*1000) % 10000)
+ #octoapi.write(pixels)
+ self.server.lastpixels = pixels
+
+ def diff_colors(self, path, tags, args, source):
+ # which user will be determined by path:
+ # we just throw away all slashes and join together what's left
+ #print "Here's what we got : path:%s tags:%s args:%s source:%s"%(str(path),str(tags),str(args),str(source))
+ pixels = server.lastpixels
+ for i in range(0,len(args)/3):
+ pp = (args[i*3],args[i*3+1],args[i*3+2])
+ p = pixels[i]
+ pixels[i] = (p[0]+pp[0], p[1]+pp[1], p[2]+pp[2])
+ #print "Pixels: %s"%str(pixels)
+ #print "Time: "+str((time.time()*1000) % 10000)
+ #octoapi.write(pixels)
+ self.server.lastpixels = pixels
+
+ def each_frame(self):
+ self.server.timed_out = False
+ while not self.server.timed_out:
+ self.server.handle_request()
+
+ def start(self):
+ #server = OSCServer( ("128.174.251.39", 11661) )
+ self.server = OSCServer( ("localhost", 11661) )
+ self.server.timeout = 0
+
+ self.server.handle_timeout = types.MethodType(handle_timeout, self.server)
+ self.server.lastpixels = [(0,0,0)]*24
+
+ self.server.addMsgHandler( "/setcolors", self.set_colors)
+ self.server.addMsgHandler( "/diffcolors", self.diff_colors)
+ while True:
+ self.each_frame()
+
+ self.server.close()
-def each_frame():
- server.timed_out = False
- while not server.timed_out:
- server.handle_request()
if __name__ == "__main__":
- #server = OSCServer( ("128.174.251.39", 11661) )
- server = OSCServer( ("localhost", 11661) )
- server.timeout = 0
-
- server.handle_timeout = types.MethodType(handle_timeout, server)
- server.lastpixels = [(0,0,0)]*24
+ ColorsIn().start()
- server.addMsgHandler( "/setcolors", set_colors)
- while True:
- each_frame()
- server.close()
class ColorsOut:
@@ -54,3 +78,8 @@ def write(self, pixels):
message = OSCMessage("/setcolors")
message.append(pixels)
self.client.send( message )
+
+ def diff(self, pixels):
+ message = OSCMessage("/diffcolors")
+ message.append(pixels)
+ self.client.send( message )
Please sign in to comment.
Something went wrong with that request. Please try again.