@sailingrotevista/rotevista-dash 6.0.11 → 6.0.13
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 +43 -21
- package/index.js +24 -17
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -116,11 +116,13 @@ function getShortestRotation(curr, target) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* Scrive il testo nel DOM solo se il valore è realmente cambiato
|
|
119
|
+
* Scrive il testo nel DOM/SVG solo se il valore è realmente cambiato.
|
|
120
|
+
* Utilizza innerHTML perché è l'unico metodo sicuro al 100% per forzare il ridisegno dei testi negli SVG.
|
|
120
121
|
*/
|
|
121
122
|
function safeSetText(el, text) {
|
|
122
|
-
if (el
|
|
123
|
-
|
|
123
|
+
if (!el) return;
|
|
124
|
+
if (el.innerHTML !== text) {
|
|
125
|
+
el.innerHTML = text;
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
|
|
@@ -609,17 +611,18 @@ function startDisplayLoop() {
|
|
|
609
611
|
ui.status.className = (socket && socket.readyState === WebSocket.OPEN) ? "online" : "offline";
|
|
610
612
|
|
|
611
613
|
// --- WATCHDOG: CONTROLLO TIMEOUT ---
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
614
|
+
const watch = {
|
|
615
|
+
"navigation.speedThroughWater": ui.stw, "navigation.speedOverGround": ui.sog,
|
|
616
|
+
"navigation.headingTrue": ui.hdg, "navigation.courseOverGroundTrue": ui.cog,
|
|
617
|
+
"environment.wind.speedApparent": ui.awsSvg, "environment.depth.belowTransducer": ui.depth,
|
|
618
|
+
"environment.wind.speedTrue": ui.tws
|
|
619
|
+
};
|
|
620
|
+
for (let p in watch) {
|
|
621
|
+
if (!store.timestamps[p] || (now - store.timestamps[p] > TIMEOUT_MS)) {
|
|
622
|
+
safeSetText(watch[p], "---"); // Sostituito innerText con la funzione protetta!
|
|
623
|
+
delete store.raw[p];
|
|
624
|
+
}
|
|
621
625
|
}
|
|
622
|
-
}
|
|
623
626
|
|
|
624
627
|
// --- AGGIORNAMENTO VELOCITÀ SULL'ACQUA (STW) ---
|
|
625
628
|
if (store.raw["navigation.speedThroughWater"] !== undefined) {
|
|
@@ -664,14 +667,20 @@ function startDisplayLoop() {
|
|
|
664
667
|
manageHistory('depth', store.raw["environment.depth.belowTransducer"]);
|
|
665
668
|
}
|
|
666
669
|
|
|
667
|
-
// --- GESTIONE VENTO (TWS / AWS SWITCH) ---
|
|
668
|
-
|
|
669
|
-
|
|
670
|
+
// --- GESTIONE VENTO (TWS / AWS SWITCH & BUSSOLA) ---
|
|
671
|
+
|
|
672
|
+
// Estrazione dati sicura: controlliamo esplicitamente se il dato esiste, altrimenti 0
|
|
673
|
+
const rawTws = store.raw["environment.wind.speedTrue"];
|
|
674
|
+
const rawAws = store.raw["environment.wind.speedApparent"];
|
|
675
|
+
|
|
676
|
+
const twsVal = (rawTws !== undefined && rawTws !== null) ? msToKts(rawTws) : 0;
|
|
677
|
+
const awsVal = (rawAws !== undefined && rawAws !== null) ? msToKts(rawAws) : 0;
|
|
670
678
|
|
|
671
|
-
if (
|
|
672
|
-
if (
|
|
679
|
+
if (rawTws !== undefined && rawTws !== null) manageHistory('tws', twsVal);
|
|
680
|
+
if (rawAws !== undefined && rawAws !== null) manageHistory('aws', awsVal);
|
|
673
681
|
|
|
674
|
-
|
|
682
|
+
// Disegno testo casella destra (TWS o AWS)
|
|
683
|
+
if (rawTws !== undefined || rawAws !== undefined) {
|
|
675
684
|
const labelWind = document.getElementById('tws-aws-label');
|
|
676
685
|
const currentWind = (displayModeTws === 'AWS') ? awsVal : twsVal;
|
|
677
686
|
|
|
@@ -692,8 +701,21 @@ function startDisplayLoop() {
|
|
|
692
701
|
}
|
|
693
702
|
}
|
|
694
703
|
|
|
695
|
-
|
|
696
|
-
|
|
704
|
+
// --- SBLOCCO FORZATO TESTO BUSSOLA (AWS) ---
|
|
705
|
+
if (rawAws !== undefined && rawAws !== null && !isNaN(awsVal)) {
|
|
706
|
+
const strVal = awsVal.toFixed(1);
|
|
707
|
+
// Recupero robusto dell'elemento
|
|
708
|
+
let awsSvgEl = document.getElementById('aws-val-svg');
|
|
709
|
+
|
|
710
|
+
if (awsSvgEl) {
|
|
711
|
+
// Trucco anti-congelamento SVG: se il testo non combacia, lo forziamo usando
|
|
712
|
+
// textContent (standard SVG) invece di innerHTML (standard HTML).
|
|
713
|
+
if (awsSvgEl.textContent !== strVal) {
|
|
714
|
+
awsSvgEl.textContent = strVal;
|
|
715
|
+
}
|
|
716
|
+
} else {
|
|
717
|
+
console.error("ERRORE: Elemento SVG bussola ('aws-val-svg') non trovato nel documento!");
|
|
718
|
+
}
|
|
697
719
|
}
|
|
698
720
|
|
|
699
721
|
// --- PUNTATORI ANALOGICI ---
|
package/index.js
CHANGED
|
@@ -16,11 +16,11 @@ module.exports = function (app) {
|
|
|
16
16
|
let routeRegistered = false;
|
|
17
17
|
let unsubscribes = [];
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// Database dello storico in RAM sul server (Sintonizzato Pro v6.0)
|
|
20
|
+
let histories = { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [], twd: [] };
|
|
21
|
+
let graphTempBuf = { stw: [], sog: [], depth: [], tws: [], vmg: [], aws: [], twd: [] };
|
|
22
|
+
let lastUpdates = { stw: 0, sog: 0, depth: 0, tws: 0, vmg: 0, aws: 0, twd: 0 };
|
|
23
|
+
let raw = {};
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* plugin.start: Inizializza il plugin.
|
|
@@ -128,18 +128,25 @@ module.exports = function (app) {
|
|
|
128
128
|
const cog = raw["navigation.courseOverGroundTrue"] || 0;
|
|
129
129
|
|
|
130
130
|
if (aws !== undefined && awa !== undefined) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
131
|
+
const awsKts = aws * 1.94384;
|
|
132
|
+
const stwKts = stw * 1.94384;
|
|
133
|
+
const tw_water_x = awsKts * Math.cos(awa) - stwKts;
|
|
134
|
+
const tw_water_y = awsKts * Math.sin(awa);
|
|
135
|
+
const tws = Math.sqrt(tw_water_x * tw_water_x + tw_water_y * tw_water_y);
|
|
136
|
+
|
|
137
|
+
manageHistory('tws', tws);
|
|
138
|
+
|
|
139
|
+
const twa = Math.atan2(tw_water_y, tw_water_x);
|
|
140
|
+
const vmg = Math.abs(stwKts * Math.cos(twa));
|
|
141
|
+
manageHistory('vmg', vmg);
|
|
142
|
+
|
|
143
|
+
// --- CALCOLO TWD STRATEGICO SERVER-SIDE ---
|
|
144
|
+
if (hdg !== undefined) {
|
|
145
|
+
// Calcolo della direzione del vento reale rispetto al nord (TWD) in radianti
|
|
146
|
+
const twd = (hdg + twa + 2 * Math.PI) % (2 * Math.PI);
|
|
147
|
+
manageHistory('twd', twd);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
/**
|