From 5332ab9dc17d5d0950dddb880757c5e1cd536367 Mon Sep 17 00:00:00 2001 From: rouggy Date: Wed, 14 Jan 2026 14:29:47 +0100 Subject: [PATCH] update km/h --- web/src/App.svelte | 8 +- web/src/components/RotatorGenius.svelte | 100 +++++++++++++----------- 2 files changed, 58 insertions(+), 50 deletions(-) diff --git a/web/src/App.svelte b/web/src/App.svelte index 11d87a8..2bd383f 100644 --- a/web/src/App.svelte +++ b/web/src/App.svelte @@ -95,10 +95,10 @@
- 🌬️ {weatherData.wind_speed.toFixed(1)}m/s - 💨 {weatherData.wind_gust.toFixed(1)}m/s - 🌡️ {weatherData.temp.toFixed(1)}°C - → {weatherData.feels_like.toFixed(1)}°C + 🌬️ {weatherData.wind_speed.toFixed(1)} km/h + 💨 {weatherData.wind_gust.toFixed(1)} km/h + 🌡️ {weatherData.temp.toFixed(1)} °C + → {weatherData.feels_like.toFixed(1)} °C
{formatTime(currentTime)} diff --git a/web/src/components/RotatorGenius.svelte b/web/src/components/RotatorGenius.svelte index ab52377..b95c461 100644 --- a/web/src/components/RotatorGenius.svelte +++ b/web/src/components/RotatorGenius.svelte @@ -13,7 +13,6 @@ // Update heading with detailed logging to debug $: if (status?.heading !== undefined && status?.heading !== null) { const newHeading = status.heading; - const oldHeading = heading; if (heading === null) { // First time: accept any value @@ -25,7 +24,6 @@ } else { // Normal update heading = newHeading; - console.log(` ✓ Updated to ${heading}°`); } } @@ -34,31 +32,38 @@ $: connected = status?.connected || false; - let targetHeading = 0; - let hasTarget = false; + // ✅ Target heading from rotator status (when controlled by PST Rotator or other software) + $: statusTargetHeading = status?.target_heading ?? null; - // Clear target when we reach it (within 5 degrees) - $: if (hasTarget && heading !== null) { - const diff = Math.abs(heading - targetHeading); + // Local target (when clicking on map in ShackMaster) + let localTargetHeading = null; + + // ✅ Determine if antenna is moving to a target from status + // (target differs from current heading by more than 2 degrees) + $: isMovingFromStatus = statusTargetHeading !== null && + heading !== null && + (() => { + const diff = Math.abs(statusTargetHeading - heading); + const wrappedDiff = Math.min(diff, 360 - diff); + return wrappedDiff > 2; + })(); + + // ✅ Active target: prefer status target when moving, otherwise use local target + $: activeTargetHeading = localTargetHeading ?? (isMovingFromStatus ? statusTargetHeading : null); + + // ✅ Has target if there's an active target that differs from current heading + $: hasTarget = activeTargetHeading !== null && heading !== null && (() => { + const diff = Math.abs(activeTargetHeading - heading); const wrappedDiff = Math.min(diff, 360 - diff); - if (wrappedDiff < 5) { - hasTarget = false; - } - } + return wrappedDiff > 2; + })(); - async function goToHeading() { - if (targetHeading < 0 || targetHeading > 359) { - // Removed alert popup - check console for errors - return; - } - try { - hasTarget = true; // Mark that we have a target - const adjustedHeading = (targetHeading + 360) % 360; - await api.rotator.setHeading(adjustedHeading); - } catch (err) { - console.error('Failed to set heading:', err); - hasTarget = false; - // Removed alert popup - check console for errors + // Clear local target when we reach it (within 3 degrees) + $: if (localTargetHeading !== null && heading !== null) { + const diff = Math.abs(heading - localTargetHeading); + const wrappedDiff = Math.min(diff, 360 - diff); + if (wrappedDiff < 3) { + localTargetHeading = null; } } @@ -80,6 +85,7 @@ async function stop() { try { + localTargetHeading = null; // Clear local target on stop await api.rotator.stop(); } catch (err) { console.error('Failed to stop:', err); @@ -87,7 +93,7 @@ } // Handle click on compass to set heading - function handleCompassClick(event) { + async function handleCompassClick(event) { const svg = event.currentTarget; const rect = svg.getBoundingClientRect(); const centerX = rect.width / 2; @@ -103,10 +109,16 @@ // Round to nearest 5 degrees const roundedHeading = Math.round(angle / 5) * 5; + const adjustedHeading = (roundedHeading + 360) % 360; - // Set target and go - targetHeading = roundedHeading; - goToHeading(); + // ✅ CORRIGÉ : Send command first, then set localTargetHeading only on success + try { + await api.rotator.setHeading(adjustedHeading); + // Only set local target AFTER successful API call + localTargetHeading = adjustedHeading; + } catch (err) { + console.error('Failed to set heading:', err); + } } @@ -123,8 +135,8 @@
CURRENT HEADING
{displayHeading}° - {#if hasTarget} - → {targetHeading}° + {#if hasTarget && activeTargetHeading !== null} + → {activeTargetHeading}° {/if}
@@ -281,19 +293,21 @@ - - {#if hasTarget} - - + {#if hasTarget && activeTargetHeading !== null} + + + - - + + @@ -301,7 +315,7 @@ {/if} - + @@ -343,8 +357,6 @@
{/if} - - @@ -395,8 +407,6 @@ gap: 10px; } - /* Heading Display */ - .heading-controls-row { display: flex; align-items: center; @@ -485,7 +495,6 @@ 50% { opacity: 1; } } - /* Map */ .map-container { display: flex; justify-content: center; @@ -521,7 +530,7 @@ .clickable-compass { cursor: crosshair; user-select: none; - outline: none; /* Remove focus outline */ + outline: none; } .clickable-compass:hover { @@ -540,5 +549,4 @@ font-size: 12px; font-weight: 600; } - - \ No newline at end of file +