From ef1abfa913498e02a4ece3be4be45d2f03e47d05 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 15:19:21 -0500 Subject: Lots of stuff INCOMPLETE --- LightInstallation.py | 2 +- behaviors/ExpandingColorZones.py | 7 ++++--- behaviors/MITDoors.py | 1 + behaviors/RiseFall.py | 6 ++++++ behaviors/SmootWind.py | 24 +++++++++++++++++------- config/6thFloorOSC.xml | 30 +++++++++++++++++++++++++++++- config/Jennifer.xml | 1 + config/Kuan.xml | 9 +++++++++ config/SmootWindTest.xml | 12 ++++++++++-- inputs/OSCInput.py | 4 ++-- inputs/PygameInput.py | 5 ++++- pixelcore/Pixel.py | 4 +++- renderers/IndoorRenderer.py | 7 ++++++- util/NetworkOps.py | 6 ++++++ util/PacketComposition.py | 15 ++++++++++++--- 15 files changed, 111 insertions(+), 22 deletions(-) diff --git a/LightInstallation.py b/LightInstallation.py index 24ad8b1..c1f01e8 100755 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -139,7 +139,7 @@ class LightInstallation(object): def mainLoop(self): lastLoopTime = clock.time() - refreshInterval = 30 + refreshInterval = 30 while not self.dieNow: #dieNow is set if one of its constituents sends a die request. loopStart = clock.time() responses = self.evaluateBehaviors() diff --git a/behaviors/ExpandingColorZones.py b/behaviors/ExpandingColorZones.py index 345851e..75be761 100644 --- a/behaviors/ExpandingColorZones.py +++ b/behaviors/ExpandingColorZones.py @@ -2,13 +2,14 @@ from operationscore.Behavior import * from logger import main_log class ExpandingColorZones(Behavior): def behaviorInit(self): - self.mapping = {'r':[(132,0),(255,0,0)], 'g':[(400,0), (0,255,0)], - 'b':[(668,0), + self.mapping = {'s001':[(132,0),(255,0,0)], 's002':[(400,0), (0,255,0)], + 's003':[(668,0), (0,0,255)]} - self.mappingkey = 'KeyChar' + self.mappingkey = 'data' def processResponse(self, sensorInputs, recursiveInputs): ret = [] for data in sensorInputs: + print data data = dict(data) if self.mappingkey in data: try: diff --git a/behaviors/MITDoors.py b/behaviors/MITDoors.py index 03bef6d..cee47f0 100644 --- a/behaviors/MITDoors.py +++ b/behaviors/MITDoors.py @@ -23,5 +23,6 @@ class MITDoors(Behavior): data['Left'], data['Right'] = bounds data['Bottom'] = self['Bottom'] data['Location'] = (sum(bounds) / 2., self['Bottom']) + data['Oscillate'] = False ret.append(data) return (ret, []) diff --git a/behaviors/RiseFall.py b/behaviors/RiseFall.py index 109cd10..eea2283 100644 --- a/behaviors/RiseFall.py +++ b/behaviors/RiseFall.py @@ -29,7 +29,13 @@ class RiseFall(Behavior): data['Right'] = data['Location'][0]+data['Width']/2. currentTime = timeOps.time() deltaTime = currentTime-data['StartTime'] + #if data['Oscillate'] == True: data['Height'] = data['MaxHeight']*math.sin(deltaTime/data['Period']*(math.pi*2)) + #else: + # data['Height'] = data['MaxHeight'] + #if (currentTime-data['StartTime']) > data['Period']: + # del data['StartTime'] + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ {y}>"+str(data['Bottom']-data['Height']) diff --git a/behaviors/SmootWind.py b/behaviors/SmootWind.py index 347e2fc..804183c 100755 --- a/behaviors/SmootWind.py +++ b/behaviors/SmootWind.py @@ -22,12 +22,22 @@ class SmootWind(Behavior): for sensory in sensorInputs: print sensory # input[0] is windspeed, [1] is dir - windSpeed = sensory[0] - windDir = sensory[1] + if 0 in sensory and 1 in sensory: + windSpeed = sensory[0] + windDir = sensory[1] + #print self.mapper.argDict + self.mapper.argDict['Width'] = self.mapper.argDict['Width']+float(windSpeed)*2+20 + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+float(windSpeed)*3+10*random.random(); + #print 'Width: ' + str(self.mapper.argDict['Width']) + #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) + + elif 'Key' in sensory: + if sensory['Key'] == 273: + self.mapper.argDict['Width'] = self.mapper.argDict['Width']+10; + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']+5; + + elif sensory['Key'] == 274: + self.mapper.argDict['Width'] = self.mapper.argDict['Width']-10; + self.xFor.argDict['ParamOp'] = self.xFor.argDict['ParamOp']-5; - #print self.mapper.argDict - self.mapper.argDict['Width'] = float(windSpeed)*2+20 - self.xFor.argDict['ParamOp'] = float(windSpeed)*3+10*random.random(); - #print 'Width: ' + str(self.mapper.argDict['Width']) - #print 'xFor: ' + str(self.xFor.argDict['ParamOp']) return (sensorInputs, recursiveInputs) diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 792fd0c..2215688 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -37,6 +37,14 @@ + + inputs.OSCInput + + osc2 + 1234 + 10 + + inputs.OSCInput @@ -79,6 +87,12 @@ False + + + sixaxis + + behaviors.ControllerOSC + touchosc @@ -262,13 +276,27 @@ + + behaviors.BehaviorChain + + mousechaser2 + + osc2 + + + sixaxis + singleframe + + True + gaussmap + + behaviors.BehaviorChain mousechaser - tcp osc diff --git a/config/Jennifer.xml b/config/Jennifer.xml index e6cfc40..179c462 100644 --- a/config/Jennifer.xml +++ b/config/Jennifer.xml @@ -98,6 +98,7 @@ colorbars pygamekey + udp colorzones diff --git a/config/Kuan.xml b/config/Kuan.xml index c85cb75..7d76ed4 100644 --- a/config/Kuan.xml +++ b/config/Kuan.xml @@ -82,6 +82,15 @@ 2000 + behaviors.MITDoors diff --git a/config/SmootWindTest.xml b/config/SmootWindTest.xml index 6b74450..f6e7a97 100755 --- a/config/SmootWindTest.xml +++ b/config/SmootWindTest.xml @@ -53,6 +53,14 @@ 1 + + inputs.PygameInput + + pygamekey + 10 + True + + inputs.HTMLInput @@ -141,8 +149,8 @@ smootwind - weatherinput - + pygamekey + diff --git a/inputs/OSCInput.py b/inputs/OSCInput.py index f867fb5..ba1e035 100644 --- a/inputs/OSCInput.py +++ b/inputs/OSCInput.py @@ -7,8 +7,8 @@ class OSCInput(Input): def inputInit(self): HOST = '' # Symbolic name meaning all available interfaces PORT = self['Port'] # Arbitrary non-privileged port - self.server = liblo.Server(PORT) - self.server.add_method(None,None, self.fallback) + self.server = liblo.Server(PORT) + self.server.add_method(None,None, self.fallback) # except liblo.ServerError, err: # main_log.error(str(err)) diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py index 18f463d..414adf3 100644 --- a/inputs/PygameInput.py +++ b/inputs/PygameInput.py @@ -23,7 +23,10 @@ class PygameInput(Input): if event.key == 27: self.die() if self['Keyboard']: - self.respond({'Key': event.key, 'KeyChar': chr(event.key)}) + try: + self.respond({'Key': event.key, 'KeyChar': chr(event.key)}) + except: + self.respond({'Key': event.key}) return else: pygame.event.post(event) diff --git a/pixelcore/Pixel.py b/pixelcore/Pixel.py index 6ff2e67..4e7cfce 100644 --- a/pixelcore/Pixel.py +++ b/pixelcore/Pixel.py @@ -1,4 +1,5 @@ import util.ColorOps as color +from logger import main_log import pdb from pixelevents.StepEvent import * import util.TimeOps as timeops @@ -57,7 +58,8 @@ class Pixel: if eventResult != None: scaledEvent = color.multiplyColor(eventResult,scale) if (scaledEvent[0] + scaledEvent[1] + scaledEvent[2]) < 5: - deadEvents.append(eventObj) + pass + #deadEvents.append(eventObj) else: colors.append(scaledEvent) else: diff --git a/renderers/IndoorRenderer.py b/renderers/IndoorRenderer.py index 531a732..710ca43 100644 --- a/renderers/IndoorRenderer.py +++ b/renderers/IndoorRenderer.py @@ -21,7 +21,7 @@ class IndoorRenderer(Renderer): for stripId in stripsInPowerSupply: self.stripLocations[stripId] = (ip, \ stripsInPowerSupply[stripId]) - + self.broadSocket = network.getBroadcastSocket(6038) def render(self, lightSystem, currentTime=timeops.time()): #try: for pixelStrip in lightSystem.pixelStrips: @@ -32,4 +32,9 @@ class IndoorRenderer(Renderer): self.sockets[ip] = network.getConnectedSocket(ip,sock_port) packet = composer.composePixelStripPacket(pixelStrip, port, currentTime) self.sockets[ip].send(packet, 0x00) + + synchPacket = composer.composeSynchPacket() + #pdb.set_trace() + #self.broadSocket.sendto(synchPacket, ('10.0.32.255', 6038)) + diff --git a/util/NetworkOps.py b/util/NetworkOps.py index 8894b78..3ece763 100644 --- a/util/NetworkOps.py +++ b/util/NetworkOps.py @@ -8,3 +8,9 @@ def getConnectedSocket(ip,port): except Exception as inst: main_log.error('Network down. All network based renderers and sensors will not function.', inst) + +def getBroadcastSocket(port): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + return s diff --git a/util/PacketComposition.py b/util/PacketComposition.py index 7b4fe95..75ef917 100644 --- a/util/PacketComposition.py +++ b/util/PacketComposition.py @@ -5,7 +5,7 @@ PORTOUT = 0x0108 UNI = 0 import pdb import util.TimeOps as timeops -argDict = {'flags': 0, 'startcode': 0, 'pad':0} +argDict = {'flags': 0, 'startcode': 0x0fff, 'pad':0} def composePixelStripData(pixelStrip,currentTime=timeops.time()): packet = bytearray() @@ -33,10 +33,10 @@ def memoize(f): def cachePacketHeader(port): packet = bytearray() subDict = dict(argDict) - subDict['len'] = 38500 #I have no idea why this works. + subDict['len'] = 150 #I have no idea why this works. subDict['port'] = port packet.extend(portOutPacket(subDict)) - packet.append(0x0) +# packet.append(0x0) return packet def composePixelStripPacket(pixelStrip,port, currentTime): @@ -61,10 +61,19 @@ def portOut(): def portOutPayload(argDict): payload = bytearray() payload.extend(struct.pack('B', argDict['port'])) + payload.extend(struct.pack('B',0)) payload.extend(struct.pack('H', argDict['flags'])) payload.extend(struct.pack('H', argDict['len'])) payload.extend(struct.pack('H', argDict['startcode'])) return payload +def composeSynchPacket(): + header = bytearray() + header.extend(struct.pack('L', MAGIC)) + header.extend(struct.pack('H', VERSION)) + header.extend(struct.pack('H', 0x0109)) + header.extend(struct.pack('L', 0)) + header.extend(struct.pack('L', 0)) + return header def portOutPacket(payloadArgs): packet = bytearray() -- cgit v1.2.3 From 3cf7f82b2c88181925e01c2736e13d8be7574ab9 Mon Sep 17 00:00:00 2001 From: eugue Date: Fri, 28 Jan 2011 15:19:40 -0500 Subject: get string data instead of int --- behaviors/MobileShakeBehavior.py | 29 +++++++++++++++++++---------- behaviors/MoveBehavior.py | 18 ++++++++++-------- config/MobileTest.xml | 28 ++++++++++++---------------- inputs/TCPInput.py | 2 ++ 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/behaviors/MobileShakeBehavior.py b/behaviors/MobileShakeBehavior.py index e25e929..b05cb5f 100644 --- a/behaviors/MobileShakeBehavior.py +++ b/behaviors/MobileShakeBehavior.py @@ -1,17 +1,26 @@ from operationscore.Behavior import * +import util.ComponentRegistry as compReg import util.Strings as Strings class MobileShakeBehavior(Behavior): + def behaviorInit(self): + self.mapper = None + def processResponse(self, sensorInputs, recursiveInputs): + if self.mapper == None: + try: + self.mapper = compReg.getComponent('mobilegaussmap') + except KeyError: + pass + #print sensorInputs - ret = [] for sInput in sensorInputs: - outDict = dict(sInput) - if 'type' in sInput and sInput['type'] == 2: - outDict['Location'] = '{x}>' + str(0) + ',{y}>' + str(0) - outDict['Color'] = [sInput['r'], sInput['g'], sInput['b']] - else: # dumb invisible pixel - outDict['Location'] = (-1, -1) - outDict['Color'] = [0, 0, 0] - ret.append(outDict) - return (ret, recursiveInputs) + if 'Shake' in sInput and sInput['Shake'] == 1: + #print 'increase!' + self.mapper.argDict['Width'] += 30 + #self.mapper.argDict['CutoffDist'] += 20 + sInput['Shake'] = 0 + print 'Width:' + str(compReg.getComponent('mobilegaussmap').argDict['Width']) + #print 'CutoffDist: '+ str(compReg.getComponent('mobilegaussmap').argDict['CutoffDist']) + + return (sensorInputs, recursiveInputs) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index e504ca9..6f57437 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -13,20 +13,22 @@ class MoveBehavior(Behavior): else: currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] + #print sensorInputs if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - if 'type' in sensorInput and sensorInput['type'] == 1: - currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ - currDict['Location'][1] + sensorInput['y'] * self['YStep']) - currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] - #elif sensorInput['type'] == 2: - # currDict['Shake'] = 1 - # currDict['Force'] = sensorInput['force'] + if 'type' in sensorInput and int(sensorInput['type']) == 1: + #currDict['Shake'] = 0 + currDict['Location'] = (currDict['Location'][0] - int(sensorInput['x']) * self['XStep'], \ + currDict['Location'][1] + int(sensorInput['y']) * self['YStep']) + currDict['Color'] = [int(sensorInput['r']), int(sensorInput['g']), int(sensorInput['b'])] + elif int(sensorInput['type']) == 2: + #print sensorInput + currDict['Shake'] = 1 + #currDict['Force'] = sensorInput['force'] ret.append(currDict) - #print ret return (ret, ret) else: # if not, return current recursive location. diff --git a/config/MobileTest.xml b/config/MobileTest.xml index af94c25..63c3b47 100644 --- a/config/MobileTest.xml +++ b/config/MobileTest.xml @@ -26,6 +26,16 @@ 1 + + pixelmappers.GaussianMapper + + mobilegaussmap + 30 + 0.1 + 10 + 1 + + @@ -227,26 +237,12 @@ move + mobileshake decay True - gaussmap + mobilegaussmap - - behaviors.BehaviorChain - - shakeanddecay - - tcp - - - mobileshake - slowdecay - - True - simplemap - - diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 17ea7e6..2d8ab4d 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -38,6 +38,8 @@ class TCPInput(Input): for datagroup in data.split('\n'): if datagroup != None and datagroup != '': dataDict = json.loads(datagroup) + #if dataDict['type'] != 1: + #print dataDict self.respond(dataDict) except Exception as exp: print str(exp) -- cgit v1.2.3 From 51b0d5f0cd4524a977e0bf48ca6f643d85d05d00 Mon Sep 17 00:00:00 2001 From: eugue Date: Fri, 28 Jan 2011 16:10:58 -0500 Subject: reverted the effort to take string inputs. --- behaviors/MoveBehavior.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index 6f57437..6e7fc6a 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -13,22 +13,21 @@ class MoveBehavior(Behavior): else: currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] - #print sensorInputs if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - if 'type' in sensorInput and int(sensorInput['type']) == 1: - #currDict['Shake'] = 0 - currDict['Location'] = (currDict['Location'][0] - int(sensorInput['x']) * self['XStep'], \ - currDict['Location'][1] + int(sensorInput['y']) * self['YStep']) - currDict['Color'] = [int(sensorInput['r']), int(sensorInput['g']), int(sensorInput['b'])] - elif int(sensorInput['type']) == 2: - #print sensorInput + if 'type' in sensorInput and sensorInput['type'] == 1: + currDict['Shake'] = 0 + currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ + currDict['Location'][1] + sensorInput['y'] * self['YStep']) + currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] + elif sensorInput['type'] == 2: currDict['Shake'] = 1 #currDict['Force'] = sensorInput['force'] ret.append(currDict) + #print ret return (ret, ret) else: # if not, return current recursive location. -- cgit v1.2.3 From bd1119e82ff9f4bd8835ed6d3934f156a6da8b23 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 16:24:21 -0500 Subject: Fixed TCPInput bug. --- config/6thFloorOSC.xml | 67 +++++++++++++++++++++++++++++++++++++++++--------- inputs/TCPInput.py | 14 ++++++++++- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 2215688..aa7a07d 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -60,14 +60,14 @@ 10 - + inputs/MouseFollower.xml @@ -79,15 +79,60 @@ - - behaviors.EchoBehavior - - echo - 0 - False - - - + + behaviors.EchoBehavior + + echo + 0 + False + + + + behaviors.BehaviorChain + + moveanddecay + + tcp + + + move + decay + + True + gaussmap + + + + behaviors.MoveBehavior + + move + 3 + 3 + + + + behaviors.MobileShakeBehavior + + mobileshake + 3 + + + + behaviors.BehaviorChain + + shakeanddecay + + tcp + + + mobileshake + slowdecay + + True + simplemap + + + sixaxis diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 17ea7e6..51a6677 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -4,6 +4,7 @@ from operationscore.Input import * import socket, json, time import logging as main_log import string +from select import select class TCPInput(Input): """TCPInput is a input to receive input on a TCP port. In its current incarnation, it parses @@ -20,9 +21,20 @@ class TCPInput(Input): self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.bind((self.HOST, self.PORT)) self.sock.listen(1) - (self.conn, self.address) = self.sock.accept() + + isreadable=select([self.sock],[],[], 0)[0] + self.conn = None + if isreadable: + (self.conn, self.address) = self.sock.accept() def sensingLoop(self): + if self.conn == None: + isreadable=select([self.sock],[],[], 0)[0] + if isreadable: + (self.conn, self.address) = self.sock.accept() + else: + return + data = self.conn.recv(self.BUFFER_SIZE) main_log.debug('Incoming data', data) -- cgit v1.2.3 From b67a37ad06fa4c97dcdb32cecc71c7f492b12840 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 28 Jan 2011 16:29:36 -0500 Subject: Picking up some files that were lost. --- behaviors/ControllerOSC.py | 67 +++++++++++++++++++++++++++++++++++++++++++ behaviors/Sink.py | 42 +++++++++++++++++++++++++++ behaviors/SynchTest.py | 12 ++++++++ config/SynchTest.xml | 39 +++++++++++++++++++++++++ pixelevents/SynchTestEvent.py | 15 ++++++++++ 5 files changed, 175 insertions(+) create mode 100644 behaviors/ControllerOSC.py create mode 100644 behaviors/Sink.py create mode 100644 behaviors/SynchTest.py create mode 100644 config/SynchTest.xml create mode 100644 pixelevents/SynchTestEvent.py diff --git a/behaviors/ControllerOSC.py b/behaviors/ControllerOSC.py new file mode 100644 index 0000000..ce2cf26 --- /dev/null +++ b/behaviors/ControllerOSC.py @@ -0,0 +1,67 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +from numpy import array +import pdb +import util.ComponentRegistry as compReg + +speedfactor = 15 +vel_decay = .00 + +def constrainLocation(v,c): + if v[0] > c[0]: + v[0] = c[0] + elif v[0]<0: + v[0] = 0 + + if v[1] > c[1]: + v[1] = c[1] + elif v[1]<0: + v[1] = 0 + + return v + +class ControllerOSC(Behavior): + def behaviorInit(self): + self.xy = array((0,0)) + self.v_xy = array((0,0)) + self.v_decay = vel_decay + + self.start_hsv = [0,1,1] + self.dest_hsv = [0,1,1] + self.ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 + + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + if sensorInputs: + data = sensorInputs[-1]#for data in sensorInputs: + if data['Path'] == '/sixaxis/xy': + #try: + x = data['Value'][0] + y = data['Value'][1] + main_log.error(str(x)) + if y < 0: + self.start_hsv[1] = 1.0+y #s + else: + self.start_hsv[2] = 1.0-y + self.start_hsv[0] = (x+1) * 180.0 + elif data['Path'] == '/sixaxis/lrud': + val=data['Value'] + vy = val[3]-val[2] + vx = val[1]-val[0] + #pdb.set_trace() + #self.v_xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) + self.v_xy = array((vx, vy)) * speedfactor + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + self.xy = self.xy + self.v_xy + constrainLocation(self.xy,self.ssize) + self.v_xy -= self.v_decay + if self.v_xy[0] < 0: + self.v_xy[0] = 0 + if self.v_xy[1] < 0: + self.v_xy[1] = 0 + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(*self.start_hsv)],'Location':(int(self.xy[0]), int(self.xy[1]))}) + + return (ret, []) diff --git a/behaviors/Sink.py b/behaviors/Sink.py new file mode 100644 index 0000000..52d0be2 --- /dev/null +++ b/behaviors/Sink.py @@ -0,0 +1,42 @@ + +from operationscore.Behavior import * +import math +import util.TimeOps as timeOps +#Required Args: +#Period (ms), MaxHeight, Width +class Sink(Behavior): + """RiseFall is a behavior that creates a rising and falling column of light. Specify: + -- the maximum height that it rises to. + -- the width of the column OR and + -- the period of oscillation in ms + + Designed to be used as part of a recursive hook. + """ + + def processResponse(self, sensorInputs, recurInputs): + ret = [] + for data in sensorInputs: + #first time with behavior: + data = dict(data) + if not 'StartTime' in data: + data['StartTime'] = timeOps.time() + data['Period'] = self['Period'] + data['MaxHeight'] = self['MaxHeight'] #Consider just using += + if not 'Bottom' in data: + data['Bottom'] = data['Location'][1] + if 'Width' in self: #TODO: improve + data['Width'] = self['Width'] + data['Left'] = data['Location'][0]-data['Width']/2. + data['Right'] = data['Location'][0]+data['Width']/2. + currentTime = timeOps.time() + deltaTime = currentTime-data['StartTime'] + data['Height'] = data['MaxHeight']*math.cos(deltaTime/data['Period']*(math.pi*2)) + + data['Location'] = "{x}>"+str(data['Left']) + ", " +\ + "{x}<"+str(data['Right'])+", {y}<" + str(data['Bottom']) + ",\ + {y}>"+str(data['Bottom']-data['Height']) + + ret.append(data) + return (ret, []) + + diff --git a/behaviors/SynchTest.py b/behaviors/SynchTest.py new file mode 100644 index 0000000..e7b8acc --- /dev/null +++ b/behaviors/SynchTest.py @@ -0,0 +1,12 @@ +from operationscore.Behavior import * +from pixelevents.SynchTestEvent import * +import pdb +class SynchTest(Behavior): + def behaviorInit(self): + self.rendered = False + def processResponse(self, sensorInputs, recurs): + if not self.rendered: + self.rendered = True + print 'here1' + return ([{'Location':'True', 'PixelEvent':SynchTestEvent({'Color':(255,0,0)})}], []) + return ([], []) diff --git a/config/SynchTest.xml b/config/SynchTest.xml new file mode 100644 index 0000000..fcb8293 --- /dev/null +++ b/config/SynchTest.xml @@ -0,0 +1,39 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + + + renderers/60StripSeq.xml + + + renderers/Pygame.xml + + + + + + + behaviors.SynchTest + + synch + True + + + + diff --git a/pixelevents/SynchTestEvent.py b/pixelevents/SynchTestEvent.py new file mode 100644 index 0000000..3e7ed0c --- /dev/null +++ b/pixelevents/SynchTestEvent.py @@ -0,0 +1,15 @@ +from operationscore.PixelEvent import * +class SynchTestEvent(PixelEvent): + """SynchTestEvent is an event to test the synchronization of the power supplies""" + def initEvent(self): + self.eventstate = 0 + self.cachedDelay = 0 + def state(self, timeDelay): + if timeDelay != self.cachedDelay: + self.eventstate += 1 + self.cachedDelay = timeDelay + color = [0]*3 + color[self.eventstate % 3] = 150 + if self.eventstate > 500: + self.eventstate = 0 + return color -- cgit v1.2.3