aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--behaviors/RunFinite.py25
-rw-r--r--behaviors/SplitBehavior.py45
-rw-r--r--config/C5Sign.xml63
-rw-r--r--inputs/InitialLocationInput.py24
-rw-r--r--operationscore/Input.py3
5 files changed, 158 insertions, 2 deletions
diff --git a/behaviors/RunFinite.py b/behaviors/RunFinite.py
new file mode 100644
index 0000000..de2ce27
--- /dev/null
+++ b/behaviors/RunFinite.py
@@ -0,0 +1,25 @@
+from operationscore.Behavior import *
+import util.ComponentRegistry as compReg
+
+class RunFinite(Behavior):
+ """RunFinite will just wire input to output, but only a finite number of
+ times as specified by the Iterations argument tag"""
+
+ def behaviorInit(self):
+ pass
+
+ def processResponse(self, inp, state):
+
+ if state:
+ iterations = state
+ else:
+ iterations = self['Iterations']
+
+ if iterations > 0:
+ out = inp
+ else:
+ out = []
+
+ iterations -= 1
+
+ return (out, iterations)
diff --git a/behaviors/SplitBehavior.py b/behaviors/SplitBehavior.py
new file mode 100644
index 0000000..1892ad3
--- /dev/null
+++ b/behaviors/SplitBehavior.py
@@ -0,0 +1,45 @@
+from operationscore.Behavior import *
+import util.ComponentRegistry as compReg
+
+class SplitBehavior(Behavior):
+ """SplitBehavior takes a list of behaviors, runs the input on all behaviors
+ listed, and then returns the concantenation of all the behavior outputs.
+ Behavior list is given under tag <BehaviorList> as a list of Id's
+
+ Example:
+ <Behavior>
+ <Class>behaviors.SplitBehavior</Class>
+ <Args>
+ <Id>splitbehavior</Id>
+ <BehaviorList>
+ <Id>behavior1Id</Id>
+ <Id>behavior2Id</Id>
+ </BehaviorList>
+ </Args>
+ </Behavior>
+ """
+
+ def behaviorInit(self):
+ pass
+
+ def processResponse(self, inp, state):
+
+ out = []
+ newstate = {}
+ for behaviorId in self['BehaviorList']:
+
+ behavior = compReg.getComponent(behaviorId)
+ if behaviorId in state:
+ behaviorState = state[behaviorId]
+ else:
+ behaviorState = []
+
+ #print behaviorId, " ", str(inp), ",", str(behaviorState)
+ output = behavior.immediateProcessInput(inp, behaviorState)
+ (behaviorOutput, behaviorState) = output
+ #print " -->", str(behaviorState), ",", str(behaviorOutput)
+
+ newstate[behaviorId] = behaviorState
+ out.extend(behaviorOutput)
+
+ return (out, newstate)
diff --git a/config/C5Sign.xml b/config/C5Sign.xml
index 6d7de20..93b3028 100644
--- a/config/C5Sign.xml
+++ b/config/C5Sign.xml
@@ -52,6 +52,14 @@
</Args>
</InputElement>
<InputElement>
+ <Class>inputs.InitialLocationInput</Class>
+ <Args>
+ <Id>centeronce</Id>
+ <xPos>0.5</xPos>
+ <yPos>0.5</yPos>
+ </Args>
+ </InputElement>
+ <InputElement>
<Class>inputs.OSCInput</Class>
<Args>
<Id>osc</Id>
@@ -130,6 +138,14 @@
<RenderToScreen>False</RenderToScreen>
</Args>
</Behavior>
+ <Behavior Id="redcolor">
+ <InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
+ <Args>
+ <ColorList>
+ <Color>(255,0,0)</Color>
+ </ColorList>
+ </Args>
+ </Behavior>
<Behavior Id="colorchange">
<InheritsFrom>behaviors/RandomColor.xml</InheritsFrom>
</Behavior>
@@ -183,6 +199,13 @@
<Behavior>
<Class>behaviors.LocationMask</Class>
<Args>
+ <Id>stripsonly</Id>
+ <Location>ts.all ls.all rs.all bs.all</Location>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.LocationMask</Class>
+ <Args>
<Id>wordsonly</Id>
<Location>wt.all cl.all c5.all</Location>
</Args>
@@ -207,8 +230,8 @@
<Id>centerleft</Id>
<Id>center</Id>
</Inputs>
- <TimeMap>{'scanningbars':10,'runcolordecay':10,'expandingcircles':10}</TimeMap>
- <InputMap>{'scanningbars':'centerleft', 'runcolordecay':'center',\
+ <TimeMap>{'framedbars':10,'runcolordecay':10,'expandingcircles':10}</TimeMap>
+ <InputMap>{'framedbars':'centerleft', 'runcolordecay':'center',\
'expandingcircles':'center'}</InputMap>
<RenderToScreen>True</RenderToScreen>
</Args>
@@ -310,6 +333,42 @@
</Args>
</Behavior>
<Behavior>
+ <Class>behaviors.RunFinite</Class>
+ <Args>
+ <Id>runonce</Id>
+ <Iterations>1</Iterations>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.BehaviorChain</Class>
+ <Args>
+ <Id>coloredframe</Id>
+ <!--Inputs>
+ <Id>centeronce</Id>
+ </Inputs-->
+ <ChainedBehaviors>
+ <Id>runonce</Id>
+ <Id>redcolor</Id>
+ <Id>square</Id>
+ <Id>mover</Id>
+ <Id>singleframe</Id>
+ <Id>stripsonly</Id>
+ </ChainedBehaviors>
+ <RecursiveHooks>{'mover':'colorshift'}</RecursiveHooks>
+ <RenderToScreen>False</RenderToScreen>
+ </Args>
+ </Behavior>
+ <Behavior>
+ <Class>behaviors.SplitBehavior</Class>
+ <Args>
+ <Id>framedbars</Id>
+ <BehaviorList>
+ <Id>coloredframe</Id>
+ <Id>scanningbars</Id>
+ </BehaviorList>
+ </Args>
+ </Behavior>
+ <Behavior>
<Class>behaviors.BehaviorChain</Class>
<Args>
<Id>expandingcircles</Id>
diff --git a/inputs/InitialLocationInput.py b/inputs/InitialLocationInput.py
new file mode 100644
index 0000000..8d39a40
--- /dev/null
+++ b/inputs/InitialLocationInput.py
@@ -0,0 +1,24 @@
+import util.TimeOps as clock
+import util.ComponentRegistry as compReg
+import util.Strings as Strings
+from operationscore.Input import *
+class InitialLocationInput(Input):
+ """Takes two arguments: xPos, yPos, where xPos and yPos is a value from
+ 0 to 1, where 0 represents top/left and 1 represents bottom/right of the
+ lightscreen. Will return that position on the screen only once."""
+
+ def inputInit(self):
+ compReg.getLock().acquire()
+ xmin, ymin, xmax, ymax = compReg.getComponent('Screen').getSize()
+ compReg.getLock().release()
+
+ xlen = xmax-xmin
+ ylen = ymax-ymin
+
+ self.xloc = xmin + xlen * self['xPos']
+ self.yloc = ymin + ylen * self['yPos']
+
+ def sensingLoop(self):
+ self.respond({Strings.LOCATION: (self.xloc, self.yloc)})
+ self.done = True
+
diff --git a/operationscore/Input.py b/operationscore/Input.py
index 7720847..8800556 100644
--- a/operationscore/Input.py
+++ b/operationscore/Input.py
@@ -14,6 +14,7 @@ class Input(ThreadedSmootCoreObject):
if not 'RefreshInterval' in self.argDict:
self.argDict['RefreshInterval'] = 500
self.parentScope = self.argDict['parentScope']
+ self.done = False
self.inputInit()
def respond(self, eventDict):
@@ -44,6 +45,8 @@ class Input(ThreadedSmootCoreObject):
self.acquireLock()
self.sensingLoop()
self.releaseLock()
+ if self.done:
+ break
def sensingLoop(self):
pass