Make sure lock pin is pulled down when exiting on interrupt

This commit is contained in:
Ondrej Mikle 2014-07-24 18:42:23 +02:00
parent e181278df5
commit 19721744a0
2 changed files with 16 additions and 0 deletions

View file

@ -99,6 +99,7 @@ class NFCScanner(object):
logging.info("Exiting on keyboard interrupt")
self.nfc.close()
self.nfc.unload()
self.unlocker.lock()
sys.exit(2)
except Exception:
logging.exception("Exception in main unlock thread")

View file

@ -22,6 +22,13 @@ class Unlocker(object):
"""
time.sleep(self.lockOpenedSecs)
def lock(self):
"""
Lock the lock back. Meant to be used when program is shut down
so that lock is not left disengaged.
"""
pass
class UnlockerWiringPi(Unlocker):
"""Uses configured pings via WiringPi to open lock.
@ -39,3 +46,11 @@ class UnlockerWiringPi(Unlocker):
wiringpi.digitalWrite(self.lockPin, 1)
time.sleep(self.lockOpenedSecs)
wiringpi.digitalWrite(self.lockPin, 0)
def lock(self):
"""
Lock the lock back. Meant to be used when program is shut down
so that lock is not left disengaged.
"""
wiringpi.digitalWrite(self.lockPin, 0)