From dc82c04a17c31679193160e228e64a0d6d40bc6b Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Sat, 15 Feb 2025 09:01:23 +0100 Subject: [PATCH] feat: enhance reconnect functionality and improve UI feedback for connection status --- html/rfid.js | 49 ++++++++++++++++++++++++++++++++++++++++++++----- html/style.css | 9 +++++++++ src/website.cpp | 10 ++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/html/rfid.js b/html/rfid.js index e55a788..fa17a49 100644 --- a/html/rfid.js +++ b/html/rfid.js @@ -112,9 +112,39 @@ function initWebSocket() { if (bambuDot) { bambuDot.className = 'status-dot ' + (data.bambu_connected ? 'online' : 'offline'); + // Add click handler only when offline + if (!data.bambu_connected) { + bambuDot.style.cursor = 'pointer'; + bambuDot.onclick = function() { + if (socket && socket.readyState === WebSocket.OPEN) { + socket.send(JSON.stringify({ + type: 'reconnect', + payload: 'bambu' + })); + } + }; + } else { + bambuDot.style.cursor = 'default'; + bambuDot.onclick = null; + } } if (spoolmanDot) { spoolmanDot.className = 'status-dot ' + (data.spoolman_connected ? 'online' : 'offline'); + // Add click handler only when offline + if (!data.spoolman_connected) { + spoolmanDot.style.cursor = 'pointer'; + spoolmanDot.onclick = function() { + if (socket && socket.readyState === WebSocket.OPEN) { + socket.send(JSON.stringify({ + type: 'reconnect', + payload: 'spoolman' + })); + } + }; + } else { + spoolmanDot.style.cursor = 'default'; + spoolmanDot.onclick = null; + } } if (ramStatus) { ramStatus.textContent = `${data.freeHeap}k`; @@ -305,7 +335,13 @@ function displayAmsData(amsData) { tray[prop.key] !== '' && tray[prop.key] !== 'null' ) - .map(prop => `

${prop.label}: ${tray[prop.key]}

`) + .map(prop => { + // Spezielle Behandlung für setting_id + if (prop.key === 'setting_id' && tray[prop.key] === '-1') { + return `

${prop.label}: not calibrated

`; + } + return `

${prop.label}: ${tray[prop.key]}

`; + }) .join(''); // Temperaturen nur anzeigen, wenn beide nicht 0 sind @@ -418,13 +454,16 @@ function handleSpoolIn(amsId, trayId) { nozzle_temp_max: parseInt(maxTemp), type: selectedSpool.filament.material, brand: selectedSpool.filament.vendor.name, - tray_info_idx: selectedSpool.filament.extra.bambu_idx.replace(/['"]+/g, '').trim(), - cali_idx: selectedSpool.filament.extra.bambu_setting_id.replace(/['"]+/g, '').trim() + tray_info_idx: selectedSpool.filament.extra.bambu_idx.replace(/['"]+/g, '').trim() } }; - // Debug logging - console.log("Sende WebSocket Nachricht:", payload); + // Prüfe, ob der Key bambu_setting_id vorhanden ist + if (selectedSpool.filament.extra.bambu_setting_id) { + payload.payload.cali_idx = selectedSpool.filament.extra.bambu_setting_id.replace(/['"]+/g, '').trim(); + } else { + payload.payload.cali_idx = "-1"; + } try { socket.send(JSON.stringify(payload)); diff --git a/html/style.css b/html/style.css index d4f1184..f4dd1c7 100644 --- a/html/style.css +++ b/html/style.css @@ -133,6 +133,15 @@ body { background-color: #dc2626; } +.status-dot.offline { + cursor: pointer; +} + +.status-dot.offline:hover { + opacity: 0.8; + transform: scale(1.1); +} + .ram-status { color: var(--inner-text-color); font-size: 0.9em; diff --git a/src/website.cpp b/src/website.cpp index de69c0e..3ff2bd9 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -69,6 +69,16 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp } } + else if (doc["type"] == "reconnect") { + if (doc["payload"] == "bambu") { + bambu_restart(); + } + + if (doc["payload"] == "spoolman") { + initSpoolman(); + } + } + else if (doc["type"] == "setBambuSpool") { Serial.println(doc["payload"].as()); setBambuSpool(doc["payload"]);