From 82f99fc4583ca3cc9861a9fe30990a4a9ef162c4 Mon Sep 17 00:00:00 2001 From: eugue Date: Tue, 25 Jan 2011 15:22:24 -0500 Subject: working version of IconMover --- behaviors/MoveBehavior.py | 10 ++-- config/MobileTest.xml | 119 ++++++++++++++++++++++++++++++++++++------- inputs/TCPInput.py | 25 +++++---- operationscore/PixelEvent.py | 1 + 4 files changed, 118 insertions(+), 37 deletions(-) diff --git a/behaviors/MoveBehavior.py b/behaviors/MoveBehavior.py index 9ae98b9..590f0e4 100644 --- a/behaviors/MoveBehavior.py +++ b/behaviors/MoveBehavior.py @@ -5,21 +5,19 @@ import util.Strings as Strings class MoveBehavior(Behavior): def processResponse(self, sensorInputs, recursiveInputs): - print 'processing' - print sensorInputs if recursiveInputs: currRecLocs = recursiveInputs else: - currRecLocs = [{'Location' : (5, 5)), 'Color' : [255, 255, 255]}] + currRecLocs = [{'Location' : (5, 5), 'Color' : [255, 255, 255]}] if sensorInputs: # if input exists, change location ret = [] for currRecLoc in currRecLocs: currDict = dict(currRecLoc) for sensorInput in sensorInputs: - currDict['Location'][0] += sensorInput['x'] * self['XStep'] - currDict['Location'][1] += sensorInput['y'] * self['YStep'] - #currDict['Color'] = sensorInput['color'] + currDict['Location'] = (currDict['Location'][0] - sensorInput['x'] * self['XStep'], \ + currDict['Location'][1] + sensorInput['y'] * self['YStep']) + currDict['Color'] = [sensorInput['r'], sensorInput['g'], sensorInput['b']] ret.append(currDict) #print ret return (ret, ret) diff --git a/config/MobileTest.xml b/config/MobileTest.xml index 2f736ea..a318069 100644 --- a/config/MobileTest.xml +++ b/config/MobileTest.xml @@ -6,7 +6,7 @@ - layouts/BasicSixStrip.xml + layouts/60StripLayout.xml @@ -29,7 +29,7 @@ - renderers/SixStripUDP.xml + renderers/60StripSeq.xml renderers/Pygame.xml @@ -40,7 +40,15 @@ inputs.PygameInput pygame - 100 + 10 + + + + inputs.TCPInput + + tcp + 20120 + 50 @@ -52,14 +60,6 @@ randomLoc - - inputs.TCPInput - - TCP - 20120 - 100 - - @@ -70,12 +70,21 @@ False + + behaviors/RedShift.xml + behaviors/RandomColor.xml behaviors/PixelDecay.xml + + behaviors/PixelDecay.xml + + .01 + + behaviors.DebugBehavior @@ -92,10 +101,17 @@ pixelsleft + + behaviors.Square + + square + 20 + + behaviors/LoopAndDie.xml - 200 + 50 @@ -115,6 +131,46 @@ gaussmap + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'redwalk'} + True + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + redwalk + + randmovement + redshift + + + + + behaviors.RandomWalk + + randmovement + 2 + + behaviors/Accelerate.xml @@ -128,6 +184,22 @@ + + behaviors.BehaviorChain + + mousechaser + + followmouse + + + echo + redshift + square + slowdecay + + True + + behaviors/RunningBehavior.xml @@ -135,12 +207,23 @@ behaviors.MoveBehavior move - - TCP - - 1 - 1 - True + 5 + 5 + + + + behaviors.BehaviorChain + + moveanddecay + + tcp + + + move + decay + + True + gaussmap diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index e5475c1..513b853 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -21,28 +21,27 @@ class TCPInput(Input): def sensingLoop(self): data = self.conn.recv(self.BUFFER_SIZE) main_log.debug('Incoming data', data) - if not data or 'end' in data or data == '': # data end, close socket + if not data or 'end' in data: # data end, close socket main_log.debug('End in data') print 'end of stream' self.IS_RESPONDING = 0 self.conn.close() self.sock.close() - - if self.IS_RESPONDING == 1: # if 'responding', respond to the received data - dataDict = json.loads(data) - self.respond(dataDict) - #try: - # for datagroup in data.split('\n'): - # if datagroup != None and datagroup != '': - # dataDict = json.loads(datagroup) - # self.respond(dataDict) - # socketDict = {'data':dataDict, 'address':self.address} + if self.IS_RESPONDING == 1: # if 'responding', respond to the received data + #dataDict = json.loads(data) + try: + for datagroup in data.split('\n'): + if datagroup != None and datagroup != '': + dataDict = json.loads(datagroup) + #print dataDict + self.respond(dataDict) + #socketDict = {'data':dataDict, 'address':self.address} #socketDict = {Strings.LOCATION: (dataDict['x'], dataDict['y'])} # like PygameInput #print 'input' #self.respond(socketDict) - #except Exception as exp: - # print str(exp) + except Exception as exp: + print str(exp) else: # if not 'responding', don't respond to data and restart socket # * an incomplete hack for now. will be changed if same-type-multi-Input is implemented. diff --git a/operationscore/PixelEvent.py b/operationscore/PixelEvent.py index 80d3b9e..c41df17 100644 --- a/operationscore/PixelEvent.py +++ b/operationscore/PixelEvent.py @@ -26,5 +26,6 @@ class PixelEvent(SmootCoreObject): color = responseDict['Color'] else: raise Exception('Need Color. Probably') + pdb.set_trace() responseDict['PixelEvent'] = StepEvent.generate(300, color) -- cgit v1.2.3