aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar dxiao <dxiao@mit.edu>2011-02-20 14:24:25 -0500
committerGravatar dxiao <dxiao@mit.edu>2011-02-20 14:24:25 -0500
commit3049644b2ba2045efb96c698105956ce6fedae08 (patch)
tree3d0034bbed8f1184d85506b716aad278312c3ce0
parent9ad7728d6303f5ee1be1f105b87cea872d84a5c4 (diff)
added ParametricLocationInput
-rw-r--r--inputs/ParametricLocationInput.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/inputs/ParametricLocationInput.py b/inputs/ParametricLocationInput.py
new file mode 100644
index 0000000..f413c64
--- /dev/null
+++ b/inputs/ParametricLocationInput.py
@@ -0,0 +1,39 @@
+import util.TimeOps as clock
+import util.ComponentRegistry as compReg
+import util.Strings as Strings
+from operationscore.Input import *
+class ParametricLocationInput(Input):
+ '''Continuously returns one of nine positions on the screen as specified by the xloc
+ and yloc arguments, which can take values 'min', 'max', and 'center'. '''
+
+ def clockTick(self):
+ return clock.time() - clock.t
+
+ def callTick(self):
+ self.t += 1
+ return self.t - 1
+
+ def inputInit(self):
+ self.t = 0
+
+ compReg.getLock().acquire()
+ xmin, ymin, xmax, ymax = compReg.getComponent('Screen').getSize()
+ compReg.getLock().release()
+
+ xlen = xmax-xmin
+ ylen = ymax-ymin
+
+ if self['useClock']:
+ self.t=self.clock()
+ self.getTime = self.clockTick
+ else:
+ self.t=0
+ self.getTime = self.callTick
+
+ self.x_eqn = eval('lambda t:' + str(xmin) + '+' + str(xlen) + '*(' + str(self['xEquation']) + ')')
+ self.y_eqn = eval('lambda t:' + str(xmin) + '+' + str(xlen) + '*(' + str(self['yEquation']) + ')')
+
+ def sensingLoop(self):
+ self.respond({Strings.LOCATION: (self.x_eqn(self.t), self.y_eqn(self.t))})
+ self.t += 1
+