Now working
All checks were successful
Build / build-backend (push) Successful in 4s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 5s

This commit is contained in:
2026-04-22 13:41:39 +02:00
parent e43aee9b13
commit 44fe3361a3
2 changed files with 25 additions and 12 deletions

View File

@@ -18,7 +18,7 @@ GPIO.setup(STEP, GPIO.OUT)
GPIO.setup(DIR, GPIO.OUT)
GPIO.setup(EN, GPIO.OUT)
GPIO.output(EN, GPIO.HIGH)
GPIO.output(EN, GPIO.LOW)
motor_thread = None
@@ -32,13 +32,11 @@ def step_motor(steps, direction, delay=0.001):
GPIO.output(STEP, GPIO.LOW)
time.sleep(delay)
def motor_step():
GPIO.output(EN, GPIO.LOW) # enable driver
def motor_step(dir):
dir_pin = GPIO.HIGH if dir == "forward" else GPIO.LOW
time.sleep(0.02) # small delay before starting
print("Motor running...")
step_motor(400, GPIO.LOW, 0.001)
GPIO.output(EN, GPIO.HIGH) # disable driver
step_motor(200, dir_pin, 0.001)
# -------------------------
@@ -70,7 +68,7 @@ def run_task(task: str, token: str):
return {"error": e.output}
@app.post("/motor/step")
@app.post("/motor/step/forward")
def start_motor(token: str):
global motor_thread
@@ -78,12 +76,23 @@ def start_motor(token: str):
raise HTTPException(status_code=403, detail="Unauthorized")
motor_thread = threading.Thread(target=motor_step, daemon=True)
motor_thread = threading.Thread(target=motor_step, args=("forward",), daemon=True)
motor_thread.start()
return {"status": "motor started"}
@app.post("/motor/step/backwards")
def start_motor(token: str):
global motor_thread
if token != "MY_SECRET_TOKEN":
raise HTTPException(status_code=403, detail="Unauthorized")
motor_thread = threading.Thread(target=motor_step, args=("backwards",), daemon=True)
motor_thread.start()
return {"status": "motor started"}
@app.post("/motor/stop")
def stop_motor(token: str):