fixes; implement the Pins
authorRalf Jung <post@ralfj.de>
Thu, 17 Oct 2013 06:51:12 +0000 (08:51 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 17 Oct 2013 06:51:12 +0000 (08:51 +0200)
actor.py
libtuer.py
statemachine.py

index 439a7bb0cd2bc0d783d1d01831f420e9b47a0a18..25939a61ee3d3dbbda368a0d3b942a7549fd023e 100644 (file)
--- a/actor.py
+++ b/actor.py
@@ -3,9 +3,13 @@ import RPi.GPIO as GPIO
 import time
        
 class Actor:
 import time
        
 class Actor:
-       CMD_BUZZ = 0
-       CMD_UNLOCK = 1
-       CMD_LOCK = 2
+       CMD_BUZZ      = 0
+       CMD_UNLOCK    = 1
+       CMD_LOCK      = 2
+       CMD_GREEN_ON  = 3
+       CMD_GREEN_OFF = 4
+       CMD_RED_ON    = 5
+       CMD_RED_OFF   = 6
        
        class CMD():
                def __init__(self, name, pin, tid, todo):
        
        class CMD():
                def __init__(self, name, pin, tid, todo):
@@ -21,12 +25,17 @@ class Actor:
                                if value is not None:
                                        logger.debug("Actor: Setting pin %d to %d" % (self.pin, value))
                                        GPIO.output(self.pin, value)
                                if value is not None:
                                        logger.debug("Actor: Setting pin %d to %d" % (self.pin, value))
                                        GPIO.output(self.pin, value)
-                               time.sleep(delay)
+                               if delay > 0:
+                                       time.sleep(delay)
        
        CMDs = {
        
        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)]),
+               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.5), (False, 0.1)]),
+               CMD_GREEN_ON: CMD("green on",      pin=23, tid=2, todo=[(True, 0)]),
+               CMD_GREEN_OFF: CMD("green off",    pin=23, tid=2, todo=[(False, 0)]),
+               CMD_RED_ON: CMD("red on",          pin=26, tid=2, todo=[(True, 0)]),
+               CMD_RED_OFF: CMD("red on",          pin=26, tid=2, todo=[(False, 0)]),
        }
        
        def __init__(self):
        }
        
        def __init__(self):
@@ -34,6 +43,7 @@ class Actor:
                self.threads = {}
                for cmd in Actor.CMDs.values():
                        GPIO.setup(cmd.pin, GPIO.OUT)
                self.threads = {}
                for cmd in Actor.CMDs.values():
                        GPIO.setup(cmd.pin, GPIO.OUT)
+                       GPIO.output(cmd.pin, False)
                        if not cmd.tid in self.threads:
                                self.threads[cmd.tid] = ThreadFunction(self._execute, "Actor TID %d" % cmd.tid)
        
                        if not cmd.tid in self.threads:
                                self.threads[cmd.tid] = ThreadFunction(self._execute, "Actor TID %d" % cmd.tid)
        
index cd10a7bcded338e514ca8480633a07c278672d70..308179ee01568679d3b2096f6a9a29c1ccdd7789 100644 (file)
@@ -5,7 +5,7 @@ import email.mime.text, email.utils
 # Logging configuration
 syslogLevel = logging.INFO
 mailLevel   = logging.CRITICAL # must be "larger" than syslog level!
 # Logging configuration
 syslogLevel = logging.INFO
 mailLevel   = logging.CRITICAL # must be "larger" than syslog level!
-mailAddress = 'post+tuer'+'@'+'ralfj.de'
+mailAddress = ['post+tuer'+'@'+'ralfj.de', 'vorstand@lists.hacksaar.de']
 
 # Mail logging handler
 def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=None):
 
 # Mail logging handler
 def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=None):
@@ -19,7 +19,7 @@ def sendeMail(subject, text, receivers, sender='sphinx@hacksaar.de', replyTo=Non
        if replyTo is not None:
                msg['Reply-To'] = replyTo
        # put into envelope and send
        if replyTo is not None:
                msg['Reply-To'] = replyTo
        # put into envelope and send
-       s = smtplib.SMTP('ralfj.de')
+       s = smtplib.SMTP('localhost')
        s.sendmail(sender, receivers, msg.as_string())
        s.quit()
 
        s.sendmail(sender, receivers, msg.as_string())
        s.quit()
 
@@ -32,7 +32,7 @@ class Logger:
                                                                                                                facility = logging.handlers.SysLogHandler.LOG_LOCAL0))
        
        def _log (self, lvl, what):
                                                                                                                facility = logging.handlers.SysLogHandler.LOG_LOCAL0))
        
        def _log (self, lvl, what):
-               thestr = "%s[%d]: %s" % ("osspd", os.getpid(), what)
+               thestr = "%s[%d]: %s" % ("tuerd", os.getpid(), what)
                # console log
                print(thestr)
                # syslog
                # console log
                print(thestr)
                # syslog
index 850eb0e598f61f2239b685b9e79a0f008f6ceef0..522657637b9731d236b853889db6f9af5a362395 100644 (file)
@@ -99,16 +99,30 @@ class StateMachine():
                        else:
                                raise Exception("Unknown command number: %d" % ev)
        
                        else:
                                raise Exception("Unknown command number: %d" % ev)
        
-       class AbstractLockedState(State):
+       class AbstractNonStartState(State):
+               def handle_pins_event(self):
+                       if self.pins().door_locked != (not self.pins().space_active):
+                               self.actor().act(Actor.CMD_RED_ON)
+                       else:
+                               self.actor().act(Actor.CMD_RED_OFF)
+                       return super().handle_pins_event()
+       
+       class AbstractLockedState(AbstractNonStartState):
                '''A state with invariant "The space is locked", switching to StateAboutToOpen when the space becomes unlocked'''
                '''A state with invariant "The space is locked", switching to StateAboutToOpen when the space becomes unlocked'''
+               def __init__(self, sm, nervlist = None):
+                       super().__init__(sm, nervlist)
+                       self.actor().act(Actor.CMD_GREEN_OFF)
                def handle_pins_event(self):
                        if not self.pins().door_locked:
                                logger.info("Door unlocked, space is about to open")
                                return StateMachine.StateAboutToOpen(self.state_machine)
                        return super().handle_pins_event()
        
                def handle_pins_event(self):
                        if not self.pins().door_locked:
                                logger.info("Door unlocked, space is about to open")
                                return StateMachine.StateAboutToOpen(self.state_machine)
                        return super().handle_pins_event()
        
-       class AbstractUnlockedState(State):
+       class AbstractUnlockedState(AbstractNonStartState):
                '''A state with invariant "The space is unlocked", switching to StateZu when the space becomes locked'''
                '''A state with invariant "The space is unlocked", switching to StateZu when the space becomes locked'''
+               def __init__(self, sm, nervlist = None):
+                       super().__init__(sm, nervlist)
+                       self.actor().act(Actor.CMD_GREEN_ON)
                def handle_pins_event(self):
                        if self.pins().door_locked:
                                logger.info("Door locked, closing space")
                def handle_pins_event(self):
                        if self.pins().door_locked:
                                logger.info("Door locked, closing space")