1 from libtuer import ThreadFunction, logger
2 import RPi.GPIO as GPIO
11 def __init__(self, name, pin, tid, todo):
16 # don't do the GPIO setup here, the main init did not yet run
19 logger.info("Actor: Running command %s" % self.name)
20 for (value, delay) in self.todo:
22 logger.debug("Actor: Setting pin %d to %d" % (self.pin, value))
23 GPIO.output(self.pin, value)
27 CMD_UNLOCK: CMD("unlock", pin=12, tid=0, todo=[(True, 0.3), (False, 0.1)]),
28 CMD_LOCK: CMD("lock", pin=16, tid=0, todo=[(True, 0.3), (False, 0.1)]),
29 CMD_BUZZ: CMD("buzz", pin=22, tid=1, todo=[(True, 2.0), (False, 0.1)]),
33 # launch threads, all running the "_execute" method
35 for cmd in Actor.CMDs.values():
36 GPIO.setup(cmd.pin, GPIO.OUT)
37 if not cmd.tid in self.threads:
38 self.threads[cmd.tid] = ThreadFunction(self._execute, "Actor TID %d" % cmd.tid)
40 def _execute(self, cmd):
41 Actor.CMDs[cmd].execute()
44 # dispatch command to correct thread
45 self.threads[Actor.CMDs[cmd].tid](cmd)
48 for thread in self.threads.values():