Explicitly set relay open and close states
This commit is contained in:
parent
06cf642074
commit
b84c968845
14
main.py
14
main.py
|
@ -17,8 +17,10 @@ from signal import *
|
|||
|
||||
import secrets
|
||||
|
||||
|
||||
RELAY_PIN = 17
|
||||
RELAY_CLOSE = GPIO.LOW
|
||||
RELAY_OPEN = GPIO.HIGH
|
||||
|
||||
RFID_EN_PIN = 27
|
||||
CARDS_FILE = 'card_data.json'
|
||||
OPEN_DURATION = 4
|
||||
|
@ -26,17 +28,17 @@ OPEN_DURATION = 4
|
|||
ser = None
|
||||
|
||||
def unlock_door():
|
||||
GPIO.output(RELAY_PIN, GPIO.HIGH)
|
||||
GPIO.output(RELAY_PIN, RELAY_CLOSE)
|
||||
GPIO.output(RFID_EN_PIN, GPIO.HIGH)
|
||||
|
||||
time.sleep(OPEN_DURATION)
|
||||
|
||||
GPIO.output(RELAY_PIN, GPIO.LOW)
|
||||
GPIO.output(RELAY_PIN, RELAY_OPEN)
|
||||
GPIO.output(RFID_EN_PIN, GPIO.LOW)
|
||||
|
||||
def lock_door_on_exit(*args):
|
||||
logging.info('Exiting, locking door...')
|
||||
GPIO.output(RELAY_PIN, GPIO.LOW)
|
||||
GPIO.output(RELAY_PIN, RELAY_OPEN)
|
||||
GPIO.output(RFID_EN_PIN, GPIO.LOW)
|
||||
os._exit(0)
|
||||
|
||||
|
@ -46,12 +48,12 @@ def init():
|
|||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(RELAY_PIN, GPIO.OUT)
|
||||
GPIO.output(RELAY_PIN, GPIO.LOW)
|
||||
GPIO.output(RELAY_PIN, RELAY_OPEN)
|
||||
GPIO.setup(RFID_EN_PIN, GPIO.OUT)
|
||||
GPIO.output(RFID_EN_PIN, GPIO.LOW)
|
||||
logging.info('GPIO initialized')
|
||||
|
||||
ser = serial.Serial(port='/dev/ttyAMA0', baudrate=secrets.BAUD_RATE, timeout=0.05)
|
||||
ser = serial.Serial(port='/dev/ttyAMA0', baudrate=secrets.BAUD_RATE, timeout=0.06)
|
||||
logging.info('Serial initialized')
|
||||
|
||||
for sig in (SIGABRT, SIGILL, SIGINT, SIGSEGV, SIGTERM):
|
||||
|
|
Loading…
Reference in New Issue
Block a user