Frontend test
This commit is contained in:
@@ -71,14 +71,11 @@ def run_task(task: str, token: str):
|
|||||||
|
|
||||||
@app.post("/motor/step")
|
@app.post("/motor/step")
|
||||||
def start_motor(token: str):
|
def start_motor(token: str):
|
||||||
global motor_running, motor_thread
|
global motor_thread
|
||||||
|
|
||||||
if token != "MY_SECRET_TOKEN":
|
if token != "MY_SECRET_TOKEN":
|
||||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||||
|
|
||||||
if motor_running:
|
|
||||||
return {"status": "already running"}
|
|
||||||
|
|
||||||
|
|
||||||
motor_thread = threading.Thread(target=motor_step, daemon=True)
|
motor_thread = threading.Thread(target=motor_step, daemon=True)
|
||||||
motor_thread.start()
|
motor_thread.start()
|
||||||
@@ -89,12 +86,9 @@ def start_motor(token: str):
|
|||||||
|
|
||||||
@app.post("/motor/stop")
|
@app.post("/motor/stop")
|
||||||
def stop_motor(token: str):
|
def stop_motor(token: str):
|
||||||
global motor_running
|
|
||||||
|
|
||||||
if token != "MY_SECRET_TOKEN":
|
if token != "MY_SECRET_TOKEN":
|
||||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||||
|
|
||||||
motor_running = False
|
|
||||||
GPIO.output(EN, GPIO.HIGH) # disable driver
|
GPIO.output(EN, GPIO.HIGH) # disable driver
|
||||||
|
|
||||||
return {"status": "motor stopped"}
|
return {"status": "motor stopped"}
|
||||||
|
|||||||
Reference in New Issue
Block a user