Adds documentation, some minor cleanup
This commit is contained in:
parent
58e4666d96
commit
2288ebc5a9
25
main.py
25
main.py
|
|
@ -1,18 +1,28 @@
|
|||
from flask import request, Flask, render_template
|
||||
|
||||
# Flask server boilerplate
|
||||
app = Flask(__name__)
|
||||
app.debug=True
|
||||
app.config['SECRET_KEY'] = 'Thisisasecret!'
|
||||
app.config['SECRET_KEY'] = 'Thisisasecret!' # Feel free to change this TODO: Make this change itself each boot
|
||||
|
||||
# Values used to track the train's throttle and direction.
|
||||
throttle: float = 0.0
|
||||
direction: int = 0
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
"""
|
||||
Renders the webpage if you view the IP address and port
|
||||
"""
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route("/data", methods=["POST"])
|
||||
def data():
|
||||
def data() -> str:
|
||||
"""
|
||||
Used by the webpage to set the throttle and/or travel direction
|
||||
|
||||
:return: Always returns "Success" (200)
|
||||
"""
|
||||
global throttle, direction
|
||||
print(request.json)
|
||||
|
||||
|
|
@ -26,14 +36,17 @@ def data():
|
|||
return "Success"
|
||||
|
||||
@app.route("/control", methods=["GET"])
|
||||
def control():
|
||||
print(request.data)
|
||||
def control() -> dict[str, str]:
|
||||
"""
|
||||
Used by the train controller to determine what the throttle and direction currently are
|
||||
|
||||
:return: A dictionary containing the throttle and direction values, will be jsonified
|
||||
"""
|
||||
return {
|
||||
"throttle": throttle,
|
||||
"direction": direction
|
||||
}
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
app.run(host="10.0.2.148", port=2093)
|
||||
# Listen on all interfaces on port 2093
|
||||
app.run(host="0.0.0.0", port=2093)
|
||||
Loading…
Reference in New Issue