diff options
-rw-r--r-- | behaviors/MoveBehavior.py | 10 | ||||
-rw-r--r-- | config/MobileTest.xml | 119 | ||||
-rw-r--r-- | inputs/TCPInput.py | 25 | ||||
-rw-r--r-- | 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 @@ </Defaults> </InstallationConfiguration> <PixelConfiguration> - <InheritsFrom>layouts/BasicSixStrip.xml</InheritsFrom> + <InheritsFrom>layouts/60StripLayout.xml</InheritsFrom> </PixelConfiguration> <PixelMapperConfiguration> <PixelMapper> @@ -29,7 +29,7 @@ </PixelMapperConfiguration> <RendererConfiguration> <Renderer> - <InheritsFrom>renderers/SixStripUDP.xml</InheritsFrom> + <InheritsFrom>renderers/60StripSeq.xml</InheritsFrom> </Renderer> <Renderer> <InheritsFrom>renderers/Pygame.xml</InheritsFrom> @@ -40,7 +40,15 @@ <Class>inputs.PygameInput</Class> <Args><!--Passed as a dictionary--> <Id>pygame</Id> - <RefreshInterval>100</RefreshInterval> + <RefreshInterval>10</RefreshInterval> + </Args> + </InputElement> + <InputElement> + <Class>inputs.TCPInput</Class> + <Args> + <Id>tcp</Id> + <Port>20120</Port> + <RefreshInterval>50</RefreshInterval> </Args> </InputElement> <InputElement Id="followmouse"> @@ -52,14 +60,6 @@ <Id>randomLoc</Id> </Args> </InputElement> - <InputElement> - <Class>inputs.TCPInput</Class> - <Args> - <Id>TCP</Id> - <Port>20120</Port> - <RefreshInterval>100</RefreshInterval> - </Args> - </InputElement> </InputConfiguration> <BehaviorConfiguration> <Behavior> @@ -70,12 +70,21 @@ <RenderToScreen>False</RenderToScreen> </Args> </Behavior> + <Behavior Id="redshift"> + <InheritsFrom>behaviors/RedShift.xml</InheritsFrom> + </Behavior> <Behavior Id="colorchange"> <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom> </Behavior> <Behavior Id="decay"> <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom> </Behavior> + <Behavior Id="slowdecay"> + <InheritsFrom>behaviors/PixelDecay.xml</InheritsFrom> + <Args> + <Coefficient>.01</Coefficient> + </Args> + </Behavior> <Behavior> <Class>behaviors.DebugBehavior</Class> <Args> @@ -92,10 +101,17 @@ <Id>pixelsleft</Id> </Args> </Behavior> + <Behavior> + <Class>behaviors.Square</Class> + <Args> + <Id>square</Id> + <Width>20</Width> + </Args> + </Behavior> <Behavior Id="recursivedecay"> <InheritsFrom>behaviors/LoopAndDie.xml</InheritsFrom> <Args> - <InitialResponseCount>200</InitialResponseCount> + <InitialResponseCount>50</InitialResponseCount> </Args> </Behavior> <Behavior> @@ -115,6 +131,46 @@ <Mapper>gaussmap</Mapper> </Args> </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>randomwalk</Id> + <Inputs> + <Id>pygame</Id> + </Inputs> + <ChainedBehaviors> + <Id>colorchange</Id> + <Id>mover</Id> + <Id>decay</Id> + </ChainedBehaviors> + <RecursiveHooks>{'mover':'redwalk'}</RecursiveHooks> + <RenderToScreen>True</RenderToScreen> + <Mapper>gaussmap</Mapper> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.ResponseMover</Class> + <Args> + <Id>mover</Id> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>redwalk</Id> + <ChainedBehaviors> + <Id>randmovement</Id> + <Id>redshift</Id> + </ChainedBehaviors> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.RandomWalk</Class> + <Args> + <Id>randmovement</Id> + <StepSize>2</StepSize> + </Args> + </Behavior> <Behavior Id="accelerate"> <InheritsFrom>behaviors/Accelerate.xml</InheritsFrom> </Behavior> @@ -128,6 +184,22 @@ </ChainedBehaviors> </Args> </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>mousechaser</Id> + <Inputs> + <Id>followmouse</Id> + </Inputs> + <ChainedBehaviors> + <Id>echo</Id> + <Id>redshift</Id> + <Id>square</Id> + <Id>slowdecay</Id> + </ChainedBehaviors> + <RenderToScreen>True</RenderToScreen> + </Args> + </Behavior> <Behavior Id="running"> <InheritsFrom>behaviors/RunningBehavior.xml</InheritsFrom> </Behavior> @@ -135,12 +207,23 @@ <Class>behaviors.MoveBehavior</Class> <Args> <Id>move</Id> - <Inputs> - <Id>TCP</Id> - </Inputs> - <XStep>1</XStep> - <YStep>1</YStep> - <RenderToScreen>True</RenderToScreen> + <XStep>5</XStep> + <YStep>5</YStep> + </Args> + </Behavior> + <Behavior> + <Class>behaviors.BehaviorChain</Class> + <Args> + <Id>moveanddecay</Id> + <Inputs> + <Id>tcp</Id> + </Inputs> + <ChainedBehaviors> + <Id>move</Id> + <Id>decay</Id> + </ChainedBehaviors> + <RenderToScreen>True</RenderToScreen> + <Mapper>gaussmap</Mapper> </Args> </Behavior> </BehaviorConfiguration> 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) |