forked from anna/doors
Only enable the yellow LED when making a network request
This is what the yellow LED was always intended to be, and I think making this change helps simplify the code. Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:
parent
ff381ba87c
commit
5b6897ba28
16
doors.py
16
doors.py
|
@ -47,6 +47,7 @@ GPIO.setup(DOOR_STRIKE, GPIO.OUT)
|
|||
GPIO.setup(RED_LED, GPIO.OUT)
|
||||
GPIO.setup(GREEN_LED, GPIO.OUT)
|
||||
GPIO.setup(YELLOW_LED, GPIO.OUT)
|
||||
GPIO.output(YELLOW_LED, GPIO.OUT)
|
||||
|
||||
|
||||
OFF = GPIO.LOW
|
||||
|
@ -58,27 +59,23 @@ def unlock_door():
|
|||
GPIO.output(DOOR_STRIKE, ON)
|
||||
GPIO.output(RED_LED, OFF)
|
||||
GPIO.output(GREEN_LED, ON)
|
||||
GPIO.output(YELLOW_LED, OFF)
|
||||
|
||||
def lock_door():
|
||||
print("Door is locked");
|
||||
GPIO.output(DOOR_STRIKE, OFF)
|
||||
GPIO.output(RED_LED, ON)
|
||||
GPIO.output(GREEN_LED, OFF)
|
||||
GPIO.output(YELLOW_LED, OFF);
|
||||
lock_door()
|
||||
|
||||
# Turn all LEDs on
|
||||
def leds_on():
|
||||
GPIO.output(RED_LED, ON)
|
||||
GPIO.output(GREEN_LED, ON)
|
||||
GPIO.output(YELLOW_LED, ON)
|
||||
|
||||
# Turn all LEDs off
|
||||
def leds_off():
|
||||
GPIO.output(RED_LED, OFF)
|
||||
GPIO.output(GREEN_LED, OFF)
|
||||
GPIO.output(YELLOW_LED, OFF)
|
||||
|
||||
def blink_leds():
|
||||
print("Blinking LEDs")
|
||||
|
@ -106,14 +103,18 @@ NEED_FLUSH = []
|
|||
THIS_MONTH = datetime.date.today().month
|
||||
|
||||
def ping_server(key):
|
||||
ret = False
|
||||
|
||||
print("Pinging server with key: %s (%s/%s)" % (key, SERVER, key))
|
||||
GPIO.output(YELLOW_LED, ON);
|
||||
with request.urlopen("%s/%s" % (SERVER, key)) as f:
|
||||
if f.read().decode() == "OK":
|
||||
ret = f.read().decode() == "OK"
|
||||
if ret:
|
||||
CACHED_KEYS.add(key)
|
||||
return True
|
||||
else:
|
||||
CACHED_KEYS.remove(key)
|
||||
return False
|
||||
GPIO.output(YELLOW_LED, OFF);
|
||||
return ret
|
||||
|
||||
def clear_cache():
|
||||
global THIS_MONTH
|
||||
|
@ -126,7 +127,6 @@ def clear_cache():
|
|||
|
||||
def verify_key(key):
|
||||
print("Verifying key: %s" % key)
|
||||
GPIO.output(YELLOW_LED, ON);
|
||||
clear_cache()
|
||||
if key in CACHED_KEYS:
|
||||
print("Using cached key")
|
||||
|
|
Loading…
Reference in New Issue
Block a user