Example #1
0
    def run(self):
        L.info("run")

        if not ispi():
            L.info("launching emulator")
            GPIO.init()

        GPIO.setmode(GPIO.BCM)
        GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

        GPIO.setup(UPSTAIRS_BELL_PIN, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(DOWNSTAIRS_BELL_PIN, GPIO.OUT, initial=GPIO.LOW)

        start = 0
        high = 0

        L.info("ready")

        while True:
            if GPIO.input(4) and high == 0:
                start = time.time()
                high = time.time()
                self.ding()

            if start > 0:
                if (time.time() - start) >= 1:
                    start = 0
                    self.dong()
            if not GPIO.input(4) and start == 0 and high > 0:
                if (time.time() - high) >= 5:
                    L.info("Cooled off, ready to fire again!")
                    high = 0
            time.sleep(0.05)
Example #2
0
 def setUp(self):
     """Method called before each test function"""
     GPIO.init()
     self.eventer = GPIO.Eventer()
     self.eventer.start()