Initial Commit

This commit is contained in:
Jared Dunbar 2023-03-12 00:35:05 -05:00
commit 58e4666d96
2 changed files with 66 additions and 0 deletions

39
main.py Normal file
View File

@ -0,0 +1,39 @@
from flask import request, Flask, render_template
app = Flask(__name__)
app.debug=True
app.config['SECRET_KEY'] = 'Thisisasecret!'
throttle: float = 0.0
direction: int = 0
@app.route('/')
def index():
return render_template('index.html')
@app.route("/data", methods=["POST"])
def data():
global throttle, direction
print(request.json)
if "throttle" in request.json:
throttle = int(request.json["throttle"]) / 100.0
print(throttle)
if "direction" in request.json:
direction = int(request.json["direction"])
print(direction)
return "Success"
@app.route("/control", methods=["GET"])
def control():
print(request.data)
return {
"throttle": throttle,
"direction": direction
}
if __name__=="__main__":
app.run(host="10.0.2.148", port=2093)

27
templates/index.html Normal file
View File

@ -0,0 +1,27 @@
<html>
<head></head>
<body>
<div class="slidecontainer">
<input type="range" min="0" max="100" value="0" class="slider" id="throttle">
<input type="range" min="-1" max="1" value="0" class="slider" id="direction">
</div>
</body>
<script>
var throttle_input = document.getElementById("throttle");
var direction_input = document.getElementById("direction");
function send_update() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/data", true);
xhr.setRequestHeader('Content-Type', 'application/json');
data = {
"throttle": throttle_input.value,
"direction": direction_input.value
}
xhr.send(JSON.stringify(data));
}
throttle_input.oninput = send_update
direction_input.oninput = send_update
</script>
</html>