From c25a387e8b21384e48977db61330d971a0336e05 Mon Sep 17 00:00:00 2001 From: Etienne Chassaing <60154720+cetiennec@users.noreply.github.com> Date: Mon, 4 Aug 2025 17:01:59 +0200 Subject: [PATCH] Connect button auto switch --- main.py | 7 ++----- templates/control.html | 10 ++++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index cf8f0a5..d23c34d 100644 --- a/main.py +++ b/main.py @@ -86,7 +86,7 @@ def format_data(data): "MV02_sp": np.round(data.get("MV02_sp", 0.0), 1), "MV03": np.round(data.get("MV03", 0.0), 1), "MV03_sp": np.round(data.get("MV03_sp", 0.0), 1), - "MV04": np.round(data.get("MV05", 0.0), 1), + "MV04": np.round(data.get("MV04", 0.0), 1), "MV04_sp": np.round(data.get("MV04_sp", 0.0), 1), "MV05": np.round(data.get("MV05", 0.0), 1), "MV05_sp": np.round(data.get("MV05_sp", 0.0), 1), @@ -182,9 +182,6 @@ def connect_toggle(): @app.post("/is_connected") def is_can_connected(): - """" - - """ return {"connected": can_backend.connected} @@ -427,7 +424,7 @@ if __name__ == "__main__": uvicorn.run( "main:app", host="127.0.0.1", - port=8081, + port=8080, reload=True, reload_dirs=["."], ) diff --git a/templates/control.html b/templates/control.html index 8727c3e..e1b36ec 100644 --- a/templates/control.html +++ b/templates/control.html @@ -343,10 +343,16 @@ } async function getConnectionStatus() { - const response = await fetch('/connect_toggle', { method: 'GET' }); + const response = await fetch('/is_connected', { method: 'GET' }); const data = await response.json(); const connectButton = document.getElementById('connectButton'); - connectButton.classList.toggle('connected', data.connected); + if (data.connected) { + connectButton.classList.add('connected'); + connectButton.innerHTML = ' Disconnect'; + } else { + connectButton.classList.remove('connected'); + connectButton.innerHTML = ' Connect'; + } connectButton.innerHTML = ` ${data.connected ? 'Disconnect' : 'Connect'}`; }