Connect button auto switch

This commit is contained in:
Etienne Chassaing 2025-08-04 17:01:59 +02:00
parent 9e79f343a5
commit c25a387e8b
2 changed files with 10 additions and 7 deletions

View File

@ -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=["."],
)

View File

@ -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 = '<i class="fas fa-power-off"></i> Disconnect';
} else {
connectButton.classList.remove('connected');
connectButton.innerHTML = '<i class="fas fa-power-off"></i> Connect';
}
connectButton.innerHTML = `<i class="fas fa-power-off"></i> ${data.connected ? 'Disconnect' : 'Connect'}`;
}