Added basic PIN to web interface, partially implemented back-end
This commit is contained in:
2
app.py
2
app.py
@ -60,11 +60,13 @@ def transmit():
|
||||
action = ACTION_MAP[data['action']]
|
||||
intensity = int(data.get('intensity', 0))
|
||||
lucal = bool(data.get('lucalEncoded', False))
|
||||
pin = int(data['shockerPin'])
|
||||
# If any of those failed, return an error.
|
||||
except (ValueError, KeyError):
|
||||
return {'success': False, 'message': 'Request must contain the following keys:\n'+
|
||||
'txID: int,\n'+
|
||||
'channel: int,\n'+
|
||||
'pin: int,\n'+
|
||||
'action: "shock", "vibrate" or "beep",\n'+
|
||||
'intensity (optional): int\n'+
|
||||
'lucalEncoded (optional): bool'}, 400
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
<input type="number" value="1" min="1" max="3" id="channelIDInput">
|
||||
<h2>LucalEncoded?</h2>
|
||||
<input type="checkbox" id="lucalEncodedInput">
|
||||
<h2>PIN</h2>
|
||||
<input type="number" id="shockerPinInput">
|
||||
<h2>Shock</h2>
|
||||
<input type="range" min="0" max="99" value="0" id="shockIntensity" oninput="document.getElementById('sliderValueFirst').value = this.value" class="sliderInput">
|
||||
<br>
|
||||
|
||||
@ -24,13 +24,13 @@ function assert(condition, message) {
|
||||
}
|
||||
}
|
||||
|
||||
async function transmit(transmitterID, channel, action, intensity=0, lucalEncoded=false) {
|
||||
async function transmit(transmitterID, channel, action, intensity=0, lucalEncoded=false, shockerPin) {
|
||||
assert(typeof transmitterID === 'number');
|
||||
assert(typeof channel === 'number');
|
||||
assert(['shock', 'vibrate', 'beep'].includes(action));
|
||||
assert(typeof intensity === 'number');
|
||||
assert(typeof lucalEncoded === 'boolean');
|
||||
POST('/transmit', {transmitterID: transmitterID, channel: channel, action: action, intensity: intensity, lucalEncoded: lucalEncoded});
|
||||
POST('/transmit', {transmitterID: transmitterID, channel: channel, action: action, intensity: intensity, lucalEncoded: lucalEncoded, shockerPin: shockerPin});
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,8 @@ async function txFromUI(action, intensity=0) {
|
||||
let transmitterID = Number(document.getElementById('transmitterIDInput').value);
|
||||
let channel = Number(document.getElementById('channelIDInput').value);
|
||||
let lucalEncoded = document.getElementById('lucalEncodedInput').checked;
|
||||
transmit(transmitterID, channel, action, intensity, lucalEncoded);
|
||||
let shockerPin = document.getElementById('shockerPinInput').value;
|
||||
transmit(transmitterID, channel, action, intensity, lucalEncoded, shockerPin);
|
||||
}
|
||||
|
||||
async function shock() {
|
||||
|
||||
Reference in New Issue
Block a user