forked from brmlab/brmdoor_libnfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unlocker.py
60 lines (50 loc) · 1.92 KB
/
unlocker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import time
class Unlocker(object):
"""Abstract class/interface for Unlocker object.
Unlocker useful for simulation, but does not actually unlock any lock.
"""
def __init__(self, config):
"""
Creates unlocked instance from config, where section named after
the class is supposed to exist.
@param config: BrmdoorConfig instance
"""
self.config = config.config
self.lockOpenedSecs = config.lockOpenedSecs
self.unlockerName = type(self).__name__
def unlock(self):
"""Unlock lock for given self.lockOpenedSecs.
In this class case, it's only simulated
"""
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.
"""
def __init__(self, config):
import wiringpi
Unlocker.__init__(self, config)
# PIN numbers follow P1 header BCM GPIO numbering, see https://projects.drogon.net/raspberry-pi/wiringpi/pins/
# Local copy of the P1 in repo mapping see gpio_vs_wiringpi_numbering_scheme.png.
wiringpi.wiringPiSetupGpio()
self.lockPin = self.config.getint("UnlockerWiringPi", "lock_pin")
wiringpi.pinMode(self.lockPin, wiringpi.OUTPUT) #output
def unlock(self):
"""Unlocks lock at configured pin by pulling it high.
"""
import wiringpi
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.
"""
import wiringpi
wiringpi.digitalWrite(self.lockPin, 0)