3abd2328af97172cd04481b28d7dc7d5f7f77c48
[saartuer.git] / actor.py
1 from libtuer import ThreadFunction, logger
2 import RPi.GPIO as GPIO
3         
4 class Actor:
5         CMD_BUZZ = 0
6         CMD_OPEN = 1
7         CMD_CLOSE = 2
8         
9         CMDs = {
10                 CMD_BUZZ:  ("buzz", 12, [(True, 0.3), (False, 2.0)]),
11                 CMD_OPEN:  ("open", 16, [(None, 0.2), (True, 0.3), (False, 1.0)]),
12                 CMD_CLOSE: ("close", 22, [(None, 0.2), (True, 0.3), (False, 1.0)]),
13         }
14         
15         def __init__(self):
16                 self.act = ThreadFunction(self._act)
17                 for (name, pin, todo) in self.CMDs.values():
18                         GPIO.setup(pin, GPIO.OUT)
19         
20         def _act(self, cmd):
21                 if cmd in self.CMDs:
22                         (name, pin, todo) = self.CMDs[cmd]
23                         logger.info("Actor: Running command %s" % name)
24                         for (value, delay) in todo:
25                                 if value is not None:
26                                         GPIO.output(pin, value)
27                                 time.sleep(delay)
28                 else:
29                         logger.error("Actor: Gut unknown command %d" % cmd)
30         
31         def stop(self):
32                 pass