X-Git-Url: https://git.ralfj.de/saartuer.git/blobdiff_plain/cf244d9312e36b30583da60d3b9918db57ab3610..a7c0b8e1ba3fc6170f14bb0c964e5ac9e9ba4881:/actor.py diff --git a/actor.py b/actor.py deleted file mode 100644 index 439a7bb..0000000 --- a/actor.py +++ /dev/null @@ -1,49 +0,0 @@ -from libtuer import ThreadFunction, logger -import RPi.GPIO as GPIO -import time - -class Actor: - CMD_BUZZ = 0 - CMD_UNLOCK = 1 - CMD_LOCK = 2 - - class CMD(): - def __init__(self, name, pin, tid, todo): - self.name = name - self.pin = pin - self.tid = tid - self.todo = todo - # don't do the GPIO setup here, the main init did not yet run - - def execute(self): - logger.info("Actor: Running command %s" % self.name) - for (value, delay) in self.todo: - if value is not None: - logger.debug("Actor: Setting pin %d to %d" % (self.pin, value)) - GPIO.output(self.pin, value) - time.sleep(delay) - - CMDs = { - CMD_UNLOCK: CMD("unlock", pin=12, tid=0, todo=[(True, 0.3), (False, 0.1)]), - CMD_LOCK: CMD("lock", pin=16, tid=0, todo=[(True, 0.3), (False, 0.1)]), - CMD_BUZZ: CMD("buzz", pin=22, tid=1, todo=[(True, 2.0), (False, 0.1)]), - } - - def __init__(self): - # launch threads, all running the "_execute" method - self.threads = {} - for cmd in Actor.CMDs.values(): - GPIO.setup(cmd.pin, GPIO.OUT) - if not cmd.tid in self.threads: - self.threads[cmd.tid] = ThreadFunction(self._execute, "Actor TID %d" % cmd.tid) - - def _execute(self, cmd): - Actor.CMDs[cmd].execute() - - def act(self, cmd): - # dispatch command to correct thread - self.threads[Actor.CMDs[cmd].tid](cmd) - - def stop(self): - for thread in self.threads.values(): - thread.stop()