Added system lock feature
This commit is contained in:
+1
-1
@@ -7,4 +7,4 @@ history.json
|
||||
*.pyc
|
||||
tags
|
||||
client_secret.json
|
||||
|
||||
locked_till.txt
|
||||
|
||||
+9
-4
@@ -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):
|
||||
|
||||
+10
-1
@@ -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) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -16,14 +16,19 @@
|
||||
<div class="recent">
|
||||
<div class="history-header">History</div><br>
|
||||
<input type="text" name="search-bar" class="search-bar" placeholder="Search">
|
||||
|
||||
|
||||
</div>
|
||||
<div class="everything-else">
|
||||
<h1>Card access manager</h1>
|
||||
<br>
|
||||
<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>
|
||||
<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">
|
||||
@@ -37,4 +42,4 @@
|
||||
<input type="button" class="button" value="Save" id="save" onclick="save()">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user