|
|
|
import time, json
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
pin_config = {}
|
|
|
|
with open('pin_config.json') as pin_config_stream:
|
|
|
|
pin_config = json.load(pin_config_stream)
|
|
|
|
if pin_config['mode'] == 'BOARD':
|
|
|
|
GPIO.setmode(GPIO.BOARD)
|
|
|
|
else:
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
GPIO.setup(pin_config['frigde_btn'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
|
|
GPIO.setup(pin_config['tools_btn'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
|
|
|
GPIO.setup(pin_config['fridge_red_LED'], GPIO.OUT)
|
|
|
|
GPIO.setup(pin_config['fridge_grn_LED'], GPIO.OUT)
|
|
|
|
GPIO.setup(pin_config['tools_red_LED'], GPIO.OUT)
|
|
|
|
GPIO.setup(pin_config['tools_grn_LED'], GPIO.OUT)
|
|
|
|
while True:
|
|
|
|
cardID = raw_input("Enter card ID: ")
|
|
|
|
event = {}
|
|
|
|
event["time"] = time.time()
|
|
|
|
event["cardID"] = cardID
|
|
|
|
event["name"] = ''
|
|
|
|
try:
|
|
|
|
with open('cards/' + cardID + '.json') as card_data:
|
|
|
|
data = json.load(card_data)
|
|
|
|
event["name"] = data['name']
|
|
|
|
if data['secretTools']:
|
|
|
|
GPIO.output(pin_config['tools_grn_LED'], GPIO.HIGH)
|
|
|
|
else
|
|
|
|
GPIO.output(pin_config['tools_red_LED'], GPIO.HIGH)
|
|
|
|
if data['fridge']:
|
|
|
|
GPIO.output(pin_config['fridge_grn_LED'], GPIO.HIGH)
|
|
|
|
else
|
|
|
|
GPIO.output(pin_config['fridge_red_LED'], GPIO.HIGH)
|
|
|
|
timeout = time.time() + 5 # 5 seconds timeout
|
|
|
|
while wait:
|
|
|
|
if data['secretTools'] and GPIO.input(pin_config['tools_btn']) == 0:
|
|
|
|
wait = False
|
|
|
|
GPIO.output(pin_config['fridge_grn_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['tools_grn_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['fridge_red_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['tools_red_LED'], GPIO.LOW)
|
|
|
|
# Open tools
|
|
|
|
if data['fridge'] and GPIO.input(pin_config['fridge_btn']) == 0:
|
|
|
|
GPIO.output(pin_config['fridge_grn_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['tools_grn_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['fridge_red_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['tools_red_LED'], GPIO.LOW)
|
|
|
|
wait = False
|
|
|
|
# Open fridge
|
|
|
|
if time.time() > timeout:
|
|
|
|
GPIO.output(pin_config['fridge_grn_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['tools_grn_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['fridge_red_LED'], GPIO.LOW)
|
|
|
|
GPIO.output(pin_config['tools_red_LED'], GPIO.LOW)
|
|
|
|
wait = False
|
|
|
|
except:
|
|
|
|
print "Card not registered."
|
|
|
|
history = []
|
|
|
|
try:
|
|
|
|
with open('history.json', 'r') as json_data:
|
|
|
|
history = json.load(json_data)
|
|
|
|
except:
|
|
|
|
print 'Initializing new history file.'
|
|
|
|
finally:
|
|
|
|
history.append(event)
|
|
|
|
with open('history.json', 'w') as outfile:
|
|
|
|
json.dump(history, outfile)
|
|
|
|
|