diff options
author | Russell Cohen <rcoh@mit.edu> | 2011-01-12 10:02:10 -0500 |
---|---|---|
committer | Russell Cohen <rcoh@mit.edu> | 2011-01-12 10:02:10 -0500 |
commit | c7fc6c2725231eb1427f0edf00d3219409b3d55b (patch) | |
tree | 5b0040cb8673c9a01513977e3b11f440afd30d49 /inputs | |
parent | aaf8bdbee7fdc1d4721f43307fc824c373c69ec4 (diff) | |
parent | 9315ded6555a7afb8f11d96e5a4c446389f157cb (diff) |
Merge branch 'master' into behaviors
Conflicts:
LightInstallation.py
Diffstat (limited to 'inputs')
-rw-r--r-- | inputs/PygameInput.py | 4 | ||||
-rw-r--r-- | inputs/TCPInput.py | 19 |
2 files changed, 15 insertions, 8 deletions
diff --git a/inputs/PygameInput.py b/inputs/PygameInput.py index a39c089..27b82b0 100644 --- a/inputs/PygameInput.py +++ b/inputs/PygameInput.py @@ -13,8 +13,8 @@ class PygameInput(Input): return for event in pygame.event.get(): if event.type is KEYDOWN: - if event.key == 301: - exit() + if event.key == 27: + self.die() self.respond({Strings.LOCATION: (5,5),'Key': event.key}) if event.type is MOUSEBUTTONDOWN: self.respond({Strings.LOCATION: pygame.mouse.get_pos()}) diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py index 197045f..5bf06bf 100644 --- a/inputs/TCPInput.py +++ b/inputs/TCPInput.py @@ -1,4 +1,5 @@ import util.Strings as Strings +import pdb from operationscore.Input import * import socket, json, time import logging as main_log @@ -18,17 +19,23 @@ 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: # data end, close socket main_log.debug('End in data') self.IS_RESPONDING = 0 self.sock.close() - if self.IS_RESPONDING == 1: # if 'responding', respond to the received data - dataDict = json.loads(data) - # socketDict = {'data':dataDict, 'address':self.address} - socketDict = {Strings.LOCATION: (100 * (1 - dataDict['x'] / 10), 25 * (1 + dataDict['y'] / 10))} # like PygameInput - - self.respond(socketDict) + if self.IS_RESPONDING == 1: # if 'responding', respond to the received data + try: + for datagroup in data.split('\n'): + if datagroup != None and datagroup != '': + dataDict = json.loads(datagroup) + # 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) 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. |