1

Compare commits

...

7 Commits

Author SHA1 Message Date
Ventilaar
a082c7a038 al het hardware hoort in principe te werken 2021-01-18 20:30:03 +01:00
Ventilaar
696ecc02ca theoretisch gezien hoort al het hardware behalve het schuifregister te werken 2021-01-18 20:17:37 +01:00
Ventilaar
56051b886d afstand sensor werkt 2021-01-18 18:55:41 +01:00
Ventilaar
7406ef157f pushbutton api geimplementeerd en een rpi check toegevoegd voor de html pagina 2021-01-18 18:38:46 +01:00
Ventilaar
b2a397d4f8 pushbutton functie werkt 2021-01-18 18:38:14 +01:00
Ventilaar
f48e9309b9 debug print toegevoegd voor ledstrip 2021-01-18 18:07:45 +01:00
Ventilaar
80d6bf0061 noway de letstrip werkt 2021-01-18 18:05:35 +01:00
2 changed files with 145 additions and 15 deletions

44
run.py
View File

@@ -5,11 +5,11 @@ import stats
import steam_api
RPI = True # ZET NAAR TRUE ALS JE OP EEN RPI DRAAIT MET DE JUISTE LIBRARIES, ZODAT DE HARDWARE TAB WERKT
RPI = False # ZET NAAR TRUE ALS JE OP EEN RPI DRAAIT MET DE JUISTE LIBRARIES, ZODAT DE HARDWARE TAB WERKT
# if RPI:
# import hardware
if RPI:
import hardware
app = Flask(__name__) # flask app initialiseren
@@ -95,7 +95,7 @@ def fulltable():
@app.route('/hardware')
def hardware():
return render_template('hardware.html')
return render_template('hardware.html', RPI=RPI)
@app.route('/search')
@@ -118,9 +118,8 @@ def api_afstandsensor():
"""Dit pad geeft een json array met de key 'afstand' met waarde van de afstandsensor in cm """
if not RPI:
return Response('Hardware kan niet aangestuurt worden omdat het niet op een RPI draait!', status=418)
afstand = 0
return {'afstand': afstand}
return {'afstand': hardware.poll_sensor()[0]}
@app.route('/api/schuifregister', methods=['POST', 'GET'])
@@ -131,9 +130,20 @@ def api_schuifregister():
"""
if not RPI:
return Response('Hardware kan niet aangestuurt worden omdat het niet op een RPI draait!', status=418)
global state_schuifregister
if request.method == 'POST':
pass
desired_state = request.form['setstate']
try:
hardware.set_register(desired_state)
except:
return {'request': 'False'}
print(f'Set value for schuifregister {desired_state}')
state_schuifregister = desired_state
return {'request': 'True'}
else:
return {'state': state_schuifregister}
@@ -146,9 +156,20 @@ def api_servo():
"""
if not RPI:
return Response('Hardware kan niet aangestuurt worden omdat het niet op een RPI draait!', status=418)
global state_servo
if request.method == 'POST':
pass
desired_state = request.form['setstate']
try:
hardware.set_servo(desired_state)
except:
return {'request': 'False'}
print(f'Set value for servo {desired_state}')
state_servo = desired_state
return {'request': 'True'}
else:
return {'state': state_servo}
@@ -158,9 +179,11 @@ def api_pushbutton():
"""Dit pad geeft de status van de pushbuttons af in True en False, de keys alsvolgd genoemd: button0, button1"""
if not RPI:
return Response('Hardware kan niet aangestuurt worden omdat het niet op een RPI draait!', status=418)
button0 = False
return {'button0': button0}
if hardware.poll_button():
return {'button0': True}
else:
return {'button0': False}
@app.route('/api/ledstrip', methods=['POST', 'GET'])
@@ -182,6 +205,7 @@ def api_ledstrip_set():
except:
return {'request': 'False'}
print(f'Set value for ledstrip {desired_state}')
state_ledstrip = desired_state
return {'request': 'True'}
else:

View File

@@ -3,32 +3,138 @@
<title>Hardware</title>
<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
</head>
<body>
<body class="text-center">
{% include "t-navbar.html" %}
<div class="container">
{% if RPI == False %}
<div class="alert alert-danger mt-4" role="alert">
Volgens de webserver is de hardware niet aangesloten en kan dus niet worden bestuurd. (Is de variabele aangepast in run.py?)
</div>
{% endif %}
<div class="row row-cols-2">
<div class="col">
<h1>Afstand sensor</h1>
kkkkk
<h2>Gemeten afstand is <span class="badge badge-secondary" id="afstand-badge">x cm</span></h2>
</div>
<div class="col">
<h1>Push buttons</h1>
kkkk
<h2>Button0 is <span class="badge badge-danger" id="button-badge">Nog niet opgevraagd</span></h2>
</div>
</div>
<br>
<div class="row row-cols-3">
<div class="col">
<h1>Ledstrip</h1>
<p>Kies een kleur uit in de colorpicker en klik op set value</p>
<input type="color" id="ledstrip-input" />
<button type="button" id="ledstrip-set" class="btn btn-primary" onclick="setval()">Set value</button>
</div>
<div class="col">
<h1>Schuifregister</h1>
dafadfadfadfaf
<p>Kies de bit uit die je positief wil aansluiten</p>
<select name="Bit volgorde" id="register-input" onchange="set_register(this.value)">
<option value="0">Uit</option>
<option value="1">Bit 1</option>
<option value="2">Bit 2</option>
<option value="4">Bit 3</option>
<option value="8">Bit 4</option>
<option value="16">Bit 5</option>
<option value="32">Bit 6</option>
<option value="64">Bit 7</option>
<option value="128">Bit 8</option>
</select>
</div>
<div class="col">
<h1>Servo</h1>
fhdghfdghdfgh
<p>Stel waarde in tussen 0 en 180 graden</p>
<input id="servo-range" type="range" min="0" max="180" step="10" value="90" oninput="this.nextElementSibling.value = this.value" onchange="set_servo(this.value)">
<output id="servo-span">90</output>
</div>
</div>
</div>
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<script>
// dit script blok geldt alleen voor de ledstrip
$(document).ready(function() {
$.getJSON('/api/ledstrip', function(data) {
document.getElementById('ledstrip-input').value = data.state
});
});
function setval() {
let valinbox = document.getElementById('ledstrip-input').value
$.post("/api/ledstrip", {setstate:valinbox})
}
</script>
<script>
// dit script blok geldt alleen voor de pushknoppen
// functie om de badge groen te maken en text 'ingedrukt'
function set_true() {
document.getElementById('button-badge').className = "badge badge-success";
document.getElementById('button-badge').textContent = 'Ingedrukt';
};
// functie om de badge rood te maken en text 'niet ingedrukt'
function set_false() {
document.getElementById('button-badge').className = "badge badge-danger";
document.getElementById('button-badge').textContent = 'Niet ingedrukt';
};
function button_poll() {
$.getJSON('/api/pushbutton', function(data) {
if (data.button0 == true) {
set_true();
} else {
set_false();
};
});
};
{% if RPI == False %}// {% endif %}setInterval(function(){ button_poll(); }, 500);
</script>
<script>
// dit script blok geldt alleen voor de afstandsensor
// functie om de waarde aan te passen in html
function set_afstand(waarde) {
document.getElementById('afstand-badge').textContent = waarde + ' cm';
};
// waarde opvragen en dan set_afstand() uitvoeren
function afstand_poll() {
$.getJSON('/api/afstandsensor', function(data) {
set_afstand(data.afstand);
});
};
{% if RPI == False %}// {% endif %}setInterval(function(){ afstand_poll(); }, 1500);
</script>
<script>
// dit script blok geldt alleen voor de servo
$(document).ready(function() {
$.getJSON('/api/servo', function(data) {
document.getElementById('servo-range').value = data.state
document.getElementById('servo-span').value = data.state
});
});
function set_servo(deg) {
$.post("/api/servo", {setstate:deg})
};
</script>
<script>
// dit script blok geldt alleen voor het schuifregister
$(document).ready(function() {
$.getJSON('/api/schuifregister', function(data) {
document.getElementById('register-input').value = data.state
});
});
function set_register(bit) {
$.post("/api/schuifregister", {setstate:bit})
};
</script>
</body>
</html>