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 ++++++++++-------- 2 files changed, 29 insertions(+), 18 deletions(-) (limited to 'behaviors') 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. -- cgit v1.2.3