@sailingrotevista/rotevista-dash 6.1.4 → 6.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.js CHANGED
@@ -79,7 +79,7 @@ const store = {
79
79
  herculesScales: {}, // Memoria per i limiti attivi della modalità Hercules
80
80
  smoothBuf: { hdg: [], cog: [], awa: [], twa: [], twd: [] },
81
81
  longBuf: { hdg: [], cog: [], awa: [], twa: [], twd: [] },
82
- histories: { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [] },
82
+ histories: { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [], twd: [] },
83
83
  graphTempBuf: { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [] },
84
84
  lastUpdates: { stw: 0, sog: 0, depth: 0, tws: 0, vmg: 0, aws: 0 }
85
85
  };
@@ -121,8 +121,12 @@ function getShortestRotation(curr, target) {
121
121
  */
122
122
  function safeSetText(el, text) {
123
123
  if (!el) return;
124
- if (el.innerHTML !== text) {
125
- el.innerHTML = text;
124
+ // Se l'elemento è parte di un SVG, usiamo textContent, altrimenti innerHTML
125
+ const isSVG = el instanceof SVGElement;
126
+ if (isSVG) {
127
+ if (el.textContent !== text) el.textContent = text;
128
+ } else {
129
+ if (el.innerHTML !== text) el.innerHTML = text;
126
130
  }
127
131
  }
128
132
 
@@ -182,7 +186,8 @@ function getCircularAverageFromBuffer(bufferArray, windowMs, signed = false, now
182
186
  const clampedDiff = Math.sign(diffRad) * limitRad;
183
187
  const clampedRad = pilotRad + clampedDiff;
184
188
  finalSin = Math.sin(clampedRad);
185
- finalCos = Math.cos(clampedRad);
189
+ const relativeCos = Math.cos(clampedRad);
190
+ finalCos = relativeCos;
186
191
  } else {
187
192
  finalSin = item.sin;
188
193
  finalCos = item.cos;
@@ -343,13 +348,14 @@ function computeTrueWind() {
343
348
  // Altrimenti eseguiamo il calcolo vettoriale tattico sull'acqua
344
349
  tws_water = Math.sqrt(aws * aws + stw * stw - 2 * aws * stw * Math.cos(awa));
345
350
  store.raw["environment.wind.speedTrue"] = tws_water;
346
-
347
- if (tws_water > 0.05) {
348
- const twa = Math.atan2(aws * Math.sin(awa), aws * Math.cos(awa) - stw);
349
- store.raw["environment.wind.angleTrueWater"] = twa;
350
- safePush(store.smoothBuf.twa, twa, now);
351
- safePush(store.longBuf.twa, twa, now);
352
- }
351
+ }
352
+
353
+ // BUG RISOLTO: Calcoliamo il TWA sempre, indipendentemente dal TWS nativo!
354
+ if (tws_water > 0.05) {
355
+ const twa = Math.atan2(aws * Math.sin(awa), aws * Math.cos(awa) - stw);
356
+ store.raw["environment.wind.angleTrueWater"] = twa;
357
+ safePush(store.smoothBuf.twa, twa, now);
358
+ safePush(store.longBuf.twa, twa, now);
353
359
  }
354
360
 
355
361
  // ==========================================================================
@@ -441,6 +447,19 @@ function processIncomingData(path, val, source, timeMs) {
441
447
  safePush(store.smoothBuf.awa, val, now);
442
448
  safePush(store.longBuf.awa, val, now);
443
449
  }
450
+
451
+ // BUG RISOLTO: Intercetta il TWD nativo e lo spinge nei buffer della bussola radar
452
+ if (path === "environment.wind.directionTrue") {
453
+ let directionVal = (val && typeof val === 'object' && val.val !== undefined) ? val.val : val;
454
+ safePush(store.smoothBuf.twd, directionVal, now);
455
+ safePush(store.longBuf.twd, directionVal, now);
456
+ }
457
+
458
+ // BUG RISOLTO: Intercetta il TWS nativo e lo memorizza in tempo reale
459
+ if (path === "environment.wind.speedTrue") {
460
+ let speedVal = (val && typeof val === 'object' && val.val !== undefined) ? val.val : val;
461
+ store.raw["environment.wind.speedTrue"] = speedVal;
462
+ }
444
463
 
445
464
  // --- GESTIONE PRUA VERA / MAGNETICA CON AUTODIVIAZIONE ---
446
465
  if (path === "navigation.headingTrue") {
@@ -713,7 +732,7 @@ function startDisplayLoop() {
713
732
  else if (drift > 0.3) ui.sog.style.setProperty('color', '#00C851', 'important'); // Favore
714
733
  else ui.sog.style.setProperty('color', '#ffbb33', 'important'); // Neutro SOG
715
734
  } else {
716
- ui.sog.style.color = "";
735
+ ui.sog.style.removeProperty('color');
717
736
  }
718
737
  }
719
738
  }
@@ -1274,7 +1293,7 @@ function drawGraph(d, id, min, max, isTws, isHercules) {
1274
1293
  if (visibleData.length < 2) return;
1275
1294
 
1276
1295
  const colDanger = "#ff3b30", colWarning = "#ff9800", colTws = "#2c3e50", colAws = "#5c6bc0";
1277
- const colDepth = "#0088cc", colStw = "#00C851", colSog = "#ffbb33", colVmg = "#00b8d4";
1296
+ const colDepth = "#0088cc", colStw = "#00C851", colStwBorder = "#007a3d", colSog = "#ffbb33", colVmg = "#00b8d4";
1278
1297
 
1279
1298
  const getColorProps = (val) => {
1280
1299
  // Se siamo in Dual Screen (focus), aumentiamo lo spessore base della curva di un filino (da 1.6 a 2.2)
@@ -1589,6 +1608,27 @@ async function init() {
1589
1608
  }
1590
1609
  }
1591
1610
 
1611
+ // Watchdog per il risveglio dallo stato di sospensione / cambio scheda
1612
+ document.addEventListener('visibilitychange', () => {
1613
+ if (document.visibilityState === 'visible') {
1614
+ console.log("🔌 [Watchdog] Tab ritornato visibile. Verifica connessione...");
1615
+
1616
+ // Se il socket esiste ma non è attivo o se vogliamo forzare la pulizia delle connessioni fantasma:
1617
+ if (socket) {
1618
+ if (socket.readyState !== WebSocket.OPEN) {
1619
+ // Se era già chiuso o in errore, proviamo a riconnettere subito
1620
+ connect();
1621
+ } else {
1622
+ // Se risulta "OPEN" ma potrebbe essere una connessione fantasma,
1623
+ // la chiudiamo forzatamente per scatenare la riconnessione pulita e il download della cronologia
1624
+ console.log("🔌 [Watchdog] Riavvio precauzionale del WebSocket per evitare connessioni fantasma.");
1625
+ socket.close();
1626
+ }
1627
+ } else {
1628
+ connect();
1629
+ }
1630
+ }
1631
+ });
1592
1632
 
1593
1633
  window.addEventListener('load', init);
1594
1634
  window.addEventListener('pagehide', saveDashboardState);
package/index.html CHANGED
@@ -12,7 +12,6 @@
12
12
 
13
13
  <!-- Icona per Bookmark e schermata Home su Apple iPad, iPhone e Mac -->
14
14
  <link rel="apple-touch-icon" href="icons/dash.png">
15
-
16
15
  <title>Sailing Dashboard Pro</title>
17
16
  <link rel="stylesheet" href="style.css">
18
17
  </head>