Motor driver fix
All checks were successful
Build / build-backend (push) Successful in 3s
Build / build-web (push) Successful in 13s
Build / release (push) Successful in 5s

This commit is contained in:
2026-04-22 12:31:15 +02:00
parent 965d6dde63
commit 1e3198d09b

View File

@@ -28,8 +28,6 @@ def step_motor(steps, direction, delay=0.001):
GPIO.output(DIR, direction) GPIO.output(DIR, direction)
for _ in range(steps): for _ in range(steps):
if not motor_running:
break
GPIO.output(STEP, GPIO.HIGH) GPIO.output(STEP, GPIO.HIGH)
time.sleep(delay) time.sleep(delay)
GPIO.output(STEP, GPIO.LOW) GPIO.output(STEP, GPIO.LOW)
@@ -39,13 +37,13 @@ def step_motor(steps, direction, delay=0.001):
def motor_loop(): def motor_loop():
global motor_running global motor_running
while motor_running: while True:
if not motor_running:
time.sleep(0.1)
continue
step_motor(200, GPIO.HIGH, 0.001) step_motor(200, GPIO.HIGH, 0.001)
time.sleep(1) time.sleep(1)
if not motor_running:
break
step_motor(200, GPIO.LOW, 0.001) step_motor(200, GPIO.LOW, 0.001)
time.sleep(1) time.sleep(1)
@@ -64,6 +62,10 @@ COMMANDS = {
# API ENDPOINTS # API ENDPOINTS
# ------------------------- # -------------------------
motor_thread = threading.Thread(target=motor_loop, daemon=True)
motor_thread.start()
print("Motor thread initialized")
@app.post("/run") @app.post("/run")
def run_task(task: str, token: str): def run_task(task: str, token: str):
if token != "MY_SECRET_TOKEN": if token != "MY_SECRET_TOKEN":
@@ -90,12 +92,12 @@ def start_motor(token: str):
return {"status": "already running"} return {"status": "already running"}
motor_running = True motor_running = True
motor_thread = threading.Thread(target=motor_loop, daemon=True) GPIO.output(EN, GPIO.LOW) # disable driver
motor_thread.start()
return {"status": "motor started"} return {"status": "motor started"}
@app.post("/motor/stop") @app.post("/motor/stop")
def stop_motor(token: str): def stop_motor(token: str):
global motor_running global motor_running