diff --git a/.gitignore b/.gitignore index f2b155c..5585d68 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ history.json *.pyc tags client_secret.json - +locked_till.txt diff --git a/cardlistener.py b/cardlistener.py index 9121e30..028cf8a 100755 --- a/cardlistener.py +++ b/cardlistener.py @@ -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) diff --git a/server.py b/server.py index 4ac55ca..91bcd4c 100644 --- a/server.py +++ b/server.py @@ -37,6 +37,20 @@ def help(): def status(): return render_template('status.html') +@app.route('/lock-fridge/') +@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/') @requires_auth def users(what): diff --git a/static/script.js b/static/script.js index bf8ac60..7b3199f 100644 --- a/static/script.js +++ b/static/script.js @@ -85,7 +85,7 @@ $(document).ready(function() { var toMatch = [-1,-1,-1]; var nameToMatch = ''; for (var j = 0; j < args.length; j++) { - if(args[j].charAt(0) == '-') { + if(args[j].charAt(0) == '-') { switch(args[j].charAt(1)) { case 'y': toMatch[0] = parseInt(args[j].substring(2)); @@ -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) { + + }); +} diff --git a/static/style.css b/static/style.css index b26e7c4..e350836 100644 --- a/static/style.css +++ b/static/style.css @@ -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; diff --git a/templates/status.html b/templates/status.html index 962bf2d..45a4d85 100644 --- a/templates/status.html +++ b/templates/status.html @@ -16,14 +16,19 @@
History

- +

Card access manager


Open fridge

-
Open tools
+
Open tools
+
+
+
Lock
+ +
@@ -37,4 +42,4 @@
- \ No newline at end of file +