start implementing the new all-great tuerd
[saartuer.git] / actor.py
diff --git a/actor.py b/actor.py
new file mode 100644 (file)
index 0000000..3abd232
--- /dev/null
+++ b/actor.py
@@ -0,0 +1,32 @@
+from libtuer import ThreadFunction, logger
+import RPi.GPIO as GPIO
+       
+class Actor:
+       CMD_BUZZ = 0
+       CMD_OPEN = 1
+       CMD_CLOSE = 2
+       
+       CMDs = {
+               CMD_BUZZ:  ("buzz", 12, [(True, 0.3), (False, 2.0)]),
+               CMD_OPEN:  ("open", 16, [(None, 0.2), (True, 0.3), (False, 1.0)]),
+               CMD_CLOSE: ("close", 22, [(None, 0.2), (True, 0.3), (False, 1.0)]),
+       }
+       
+       def __init__(self):
+               self.act = ThreadFunction(self._act)
+               for (name, pin, todo) in self.CMDs.values():
+                       GPIO.setup(pin, GPIO.OUT)
+       
+       def _act(self, cmd):
+               if cmd in self.CMDs:
+                       (name, pin, todo) = self.CMDs[cmd]
+                       logger.info("Actor: Running command %s" % name)
+                       for (value, delay) in todo:
+                               if value is not None:
+                                       GPIO.output(pin, value)
+                               time.sleep(delay)
+               else:
+                       logger.error("Actor: Gut unknown command %d" % cmd)
+       
+       def stop(self):
+               pass