diff --git a/.codex b/.codex new file mode 100644 index 0000000..e69de29 diff --git a/backend/main.py b/backend/main.py index 603342f..00b61fd 100644 --- a/backend/main.py +++ b/backend/main.py @@ -20,10 +20,8 @@ GPIO.setup(EN, GPIO.OUT) GPIO.output(EN, GPIO.LOW) -motor_running = False motor_thread = None - def step_motor(steps, direction, delay=0.001): GPIO.output(DIR, direction) @@ -33,22 +31,13 @@ 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_loop(): - global motor_running + print("Motor running...") + step_motor(400, GPIO.HIGH, 0.001) - while True: - if not motor_running: - time.sleep(0.1) - print("Waiting for motor to start...") - continue - - print("Motor running...") - step_motor(200, GPIO.HIGH, 0.001) - time.sleep(1) - - step_motor(200, GPIO.LOW, 0.001) - time.sleep(1) + GPIO.output(EN, GPIO.HIGH) # disable driver # ------------------------- @@ -65,10 +54,6 @@ COMMANDS = { # API ENDPOINTS # ------------------------- -motor_thread = threading.Thread(target=motor_loop, daemon=True) -motor_thread.start() -print("Motor thread initialized") - @app.post("/run") def run_task(task: str, token: str): if token != "MY_SECRET_TOKEN": @@ -84,7 +69,7 @@ def run_task(task: str, token: str): return {"error": e.output} -@app.post("/motor/start") +@app.post("/motor/step") def start_motor(token: str): global motor_running, motor_thread @@ -94,8 +79,9 @@ def start_motor(token: str): if motor_running: return {"status": "already running"} - motor_running = True - GPIO.output(EN, GPIO.LOW) # disable driver + + motor_thread = threading.Thread(target=motor_step, daemon=True) + motor_thread.start() return {"status": "motor started"} diff --git a/quibot-web/app/app.vue b/quibot-web/app/app.vue index a0df395..1ea8239 100644 --- a/quibot-web/app/app.vue +++ b/quibot-web/app/app.vue @@ -1,3 +1,116 @@ \ No newline at end of file +
+

Quibot Motor Control

+ +
+ + + +
+ +

+ {{ message }} +

+ +

+ {{ error }} +

+
+ + + + + diff --git a/quibot-web/nuxt.config.ts b/quibot-web/nuxt.config.ts index b26ebd9..e3376af 100644 --- a/quibot-web/nuxt.config.ts +++ b/quibot-web/nuxt.config.ts @@ -2,6 +2,10 @@ export default defineNuxtConfig({ compatibilityDate: '2025-07-15', devtools: { enabled: true }, + runtimeConfig: { + quibotBaseUrl: process.env.QUIBOT_BASE_URL || 'http://quibot:8000', + quibotToken: process.env.QUIBOT_TOKEN || 'MY_SECRET_TOKEN', + }, vite: { optimizeDeps: { include: [ diff --git a/quibot-web/server/api/motor/step.post.ts b/quibot-web/server/api/motor/step.post.ts new file mode 100644 index 0000000..2dca8e5 --- /dev/null +++ b/quibot-web/server/api/motor/step.post.ts @@ -0,0 +1,10 @@ +export default defineEventHandler(async () => { + const config = useRuntimeConfig() + + return await $fetch(`${config.quibotBaseUrl}/motor/step`, { + method: 'POST', + query: { + token: config.quibotToken, + }, + }) +}) diff --git a/quibot-web/server/api/motor/stop.post.ts b/quibot-web/server/api/motor/stop.post.ts new file mode 100644 index 0000000..6e787b4 --- /dev/null +++ b/quibot-web/server/api/motor/stop.post.ts @@ -0,0 +1,10 @@ +export default defineEventHandler(async () => { + const config = useRuntimeConfig() + + return await $fetch(`${config.quibotBaseUrl}/motor/stop`, { + method: 'POST', + query: { + token: config.quibotToken, + }, + }) +})