- Move blink_leds() to be next to other LED handling code
- read_rfid() should handle exceptions
- Rename main() -> loop()

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
Anna Schumaker 2015-04-23 10:44:44 -04:00
parent 40ee611f33
commit 673a6bd9c6
1 changed files with 23 additions and 20 deletions

View File

@ -80,6 +80,16 @@ def leds_off():
GPIO.output(GREEN_LED, OFF) GPIO.output(GREEN_LED, OFF)
GPIO.output(YELLOW_LED, OFF) GPIO.output(YELLOW_LED, OFF)
def blink_leds():
print("Blinking LEDs")
for i in range(5):
if (i % 2) == 0:
leds_on()
else:
leds_off()
time.sleep(1)
lock_door()
lock_door() lock_door()
@ -113,36 +123,29 @@ import serial
RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1) RFID_SERIAL = serial.Serial(RFID_PATH, 2400, timeout=1)
def read_rfid(): def _do_read_rfid():
string = RFID_SERIAL.read(12) string = RFID_SERIAL.read(12)
if len(string) == 0: if len(string) == 0:
print("No tag read") print("No tag read")
#continue
else: else:
key = string[1:11].decode() #exclude start x0A and stop x0D bytes key = string[1:11].decode() #exclude start x0A and stop x0D bytes
print(key) print(key)
verify_key(key) verify_key(key)
RFID_SERIAL.flushInput() # ignore errors, no data RFID_SERIAL.flushInput() # ignore errors, no data
def read_rfid():
def blink_leds(): try:
for i in range(5): _do_read_rfid()
if (i % 2) == 0: except Exception as e:
leds_on() print(e)
else: lock_door()
leds_off() blink_leds()
time.sleep(1)
lock_door()
def main():
def loop():
while True: while True:
try: read_rfid()
read_rfid()
except Exception as e:
print(e)
lock_door()
blink_leds()
if __name__ == "__main__":
if __name__ == "__main__": main() loop()