Permalink
Browse files

Adding timeout

  • Loading branch information...
1 parent 89a0777 commit 3026038d4b0d6d8d73e0bf8da92a9fc3815c0a29 @rjmarsan rjmarsan committed Mar 12, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 lights/python/osc.py
View
12 lights/python/osc.py
@@ -2,7 +2,7 @@
from OSC import OSCServer, OSCClient, OSCMessage
import sys
import time
-#import octoapi
+import octoapi
# funny python's way to add a method to an instance of a class
import types
@@ -25,7 +25,8 @@ def set_colors(self,path, tags, args, source):
pixels.append( pixel )
#print "Pixels: %s"%str(pixels)
#print "Time: "+str((time.time()*1000) % 10000)
- #octoapi.write(pixels)
+ octoapi.write(pixels)
+ self.lastwrite=time.time()
self.server.lastpixels = pixels
def diff_colors(self, path, tags, args, source):
@@ -39,7 +40,8 @@ def diff_colors(self, path, tags, args, source):
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)
+ octoapi.write(pixels)
+ self.lastwrite=time.time()
self.server.lastpixels = pixels
def each_frame(self):
@@ -51,13 +53,15 @@ def start(self):
#server = OSCServer( ("128.174.251.39", 11661) )
self.server = OSCServer( ("localhost", 11661) )
self.server.timeout = 0
-
+ self.lastwrite = time.time()
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:
+ if time.time() - self.lastwrite > 10:
+ octoapi.clear()
self.each_frame()
self.server.close()

0 comments on commit 3026038

Please sign in to comment.