From 6e251d6d36410572db8c4328358650439cc019ca Mon Sep 17 00:00:00 2001 From: Admin Date: Sat, 21 Mar 2026 15:37:54 +0000 Subject: [PATCH] Fix Bosch BLE protocol: correct UUIDs, 2-byte data IDs, new dashboard fields --- webapp/js/app.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/webapp/js/app.js b/webapp/js/app.js index 6c2fb19..d782552 100644 --- a/webapp/js/app.js +++ b/webapp/js/app.js @@ -154,10 +154,18 @@ const app = (() => { // Cycle through modes every 15 seconds (30 ticks) const modeIndex = Math.floor(demoTick / 30) % DEMO_MODES.length; + const cadence = speed > 0.5 ? Math.round(speed * 2.8 + (Math.random() - 0.5) * 10) : 0; + const humanPower = speed > 0.5 ? Math.round(cadence * 1.3 + (Math.random() - 0.5) * 20) : 0; + const modeMultiplier = { OFF: 0, ECO: 0.5, TOUR: 1.0, eMTB: 1.5, TURBO: 2.2 }; + const motorPower = Math.round(humanPower * (modeMultiplier[DEMO_MODES[modeIndex]] || 1.0)); + const battery = Math.max(0, 87 - Math.floor(demoTick * 0.02)); + const data = { speed: Math.round(speed * 10) / 10, - torque: torque, - totalKm: Math.round(totalKm * 10) / 10, + cadence: Math.max(0, cadence), + humanPower: Math.max(0, humanPower), + motorPower: Math.max(0, motorPower), + battery: battery, mode: DEMO_MODES[modeIndex] }; @@ -227,9 +235,26 @@ const app = (() => { * Update dashboard with telemetry data */ function updateDashboard(data) { - document.getElementById('val-speed').textContent = (data.speed || 0).toFixed(1); - document.getElementById('val-torque').textContent = Math.round(data.torque || 0); - document.getElementById('val-totalkm').textContent = (data.totalKm || 0).toFixed(1); + if (data.speed !== null && data.speed !== undefined) { + document.getElementById('val-speed').textContent = (data.speed || 0).toFixed(1); + } + if (data.cadence !== null && data.cadence !== undefined) { + document.getElementById('val-cadence').textContent = Math.round(data.cadence || 0); + } + if (data.humanPower !== null && data.humanPower !== undefined) { + document.getElementById('val-humanpower').textContent = Math.round(data.humanPower || 0); + } + if (data.motorPower !== null && data.motorPower !== undefined) { + document.getElementById('val-motorpower').textContent = Math.round(data.motorPower || 0); + } + if (data.battery !== null && data.battery !== undefined) { + document.getElementById('val-battery').textContent = data.battery; + const bar = document.getElementById('battery-bar'); + if (bar) { + bar.style.width = data.battery + '%'; + bar.style.background = data.battery > 50 ? '#4caf50' : data.battery > 20 ? '#ff9800' : '#f44336'; + } + } const modeStr = data.mode || 'OFF'; document.getElementById('val-mode').textContent = modeStr;