Added system lock feature

master
Jared 7 years ago
parent d99f70433a
commit b726139474

2
.gitignore vendored

@ -7,4 +7,4 @@ history.json
*.pyc
tags
client_secret.json
locked_till.txt

@ -56,18 +56,23 @@ if __name__ == '__main__':
with open('cards/' + cardID + '.json') as card_data:
data = json.load(card_data)
event["name"] = data['name']
if data['secretTools']:
locked = False
with open('locked_till.txt', 'rb') as f:
txt = f.read()
t = float(txt)
locked = time.time() < t
if data['secretTools'] and not locked:
GPIO.output(pin_config['tools_grn_LED'], GPIO.HIGH)
else:
GPIO.output(pin_config['tools_red_LED'], GPIO.HIGH)
if data['fridge']:
if data['fridge'] and not locked:
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
wait = True
while wait:
if data['secretTools'] and GPIO.input(pin_config['tools_btn']) == 0:
if data['secretTools'] and GPIO.input(pin_config['tools_btn']) == 0 and not locked:
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)
@ -76,7 +81,7 @@ if __name__ == '__main__':
wait = False
# Open tools
subprocess.call("/home/pi/ELAB-RFID-I2C/RPi/i2c_challenge 0x30", shell=True)
if data['fridge'] and GPIO.input(pin_config['fridge_btn']) == 0:
if data['fridge'] and GPIO.input(pin_config['fridge_btn']) == 0 and not locked:
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)

@ -37,6 +37,20 @@ def help():
def status():
return render_template('status.html')
@app.route('/lock-fridge/<duration>')
@requires_auth
def lock_fridge(duration):
with open('locked_till.txt', 'wb') as f:
f.write(str(time.time() + float(duration) * 3600))
return '{"success":true}'
@app.route('/unlock-fridge')
@requires_auth
def unlock_fridge():
with open('locked_till.txt', 'wb') as f:
f.write('0')
return '{"success":true}'
@app.route('/open/<what>')
@requires_auth
def users(what):

@ -133,3 +133,12 @@ $(document).ready(function() {
$('.event-wrapper').replaceWith(newHistory);
});
})
function lock_fridge() {
var period = parseFloat($('#period').val())
if (isNaN(period))
return;
$.getJSON('http://130.237.3.207/lock-fridge/' + period, function(data) {
});
}

@ -165,6 +165,18 @@ input[type=text].search-bar {
width: 75%;
}
input[type=text].duration-input {
width: 25%;
margin-left: 15pt;
}
.disable-lock {
display: inline-block;
border-radius: 3pt;
background-color: #226666;
margin: 5pt 30pt 5pt 30pt;
}
.button {
background-color: #013A3A;
color: #5E9292;

@ -24,6 +24,11 @@
<a href="/open/fridge"><div class="big-button">Open fridge</div></a>
<br>
<a href="/open/tools"><div class="big-button">Open tools</div></a>
<br>
<div class="disable-lock">
<a href="#"><div class="big-button" onclick="lock_fridge()">Lock</div></a>
<input type="text" name="period" placeholder="Duration (h)" id="period" class="duration-input">
</div>
</div>
<div class="shadow" onclick="overlay_out()"></div>
<div class="overlay">

Loading…
Cancel
Save