From 4835d78bf1598a3c280b5dc2bedd653ab59ad7fc Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sat, 24 Feb 2024 00:19:12 +0100 Subject: [PATCH 1/5] widadjust: Add application to automatically determine PPM fixup from GPS data --- apps/widadjust/ChangeLog | 1 + apps/widadjust/app-icon.js | 2 + apps/widadjust/metadata.json | 7 +- apps/widadjust/widadjust.app.js | 208 ++++++++++++++++++++++++++++++++ 4 files changed, 215 insertions(+), 3 deletions(-) create mode 100644 apps/widadjust/app-icon.js create mode 100644 apps/widadjust/widadjust.app.js diff --git a/apps/widadjust/ChangeLog b/apps/widadjust/ChangeLog index 5f7738762a..01b1d8a69c 100644 --- a/apps/widadjust/ChangeLog +++ b/apps/widadjust/ChangeLog @@ -1,3 +1,4 @@ 0.01: New widget 0.02: Use default Bangle formatter for booleans 0.03: Add option to hide widget +0.04: Add auto-adjust app diff --git a/apps/widadjust/app-icon.js b/apps/widadjust/app-icon.js new file mode 100644 index 0000000000..066d5837c6 --- /dev/null +++ b/apps/widadjust/app-icon.js @@ -0,0 +1,2 @@ +require("heatshrink").decompress(atob("mEwhHXAH4A/AH4AegADDAAYLGF8QuEGAYvlFwwwCF/4vUABZf/F/4vEGA4LEF8YwFBYwA/AHB8uWIoxtGH4w/FB5fpRWQxwEE5YvXmJixKn4v/F/4v/F/4v/F8gAFK1AvGB4RpmL8oA/AH4A/AH4A/AH4AIgAlkA")) + diff --git a/apps/widadjust/metadata.json b/apps/widadjust/metadata.json index db82b36e39..079f1e35de 100644 --- a/apps/widadjust/metadata.json +++ b/apps/widadjust/metadata.json @@ -2,15 +2,16 @@ "id": "widadjust", "name": "Adjust Clock", "icon": "icon.png", - "version": "0.03", + "version": "0.04", "description": "Adjusts clock continually in the background to counter clock drift", - "type": "widget", "tags": "widget", "supports": [ "BANGLEJS", "BANGLEJS2" ], "readme": "README.md", "storage": [ { "name": "widadjust.wid.js", "url": "widget.js" }, - { "name": "widadjust.settings.js", "url": "settings.js" } + { "name": "widadjust.settings.js", "url": "settings.js" }, + { "name": "widadjust.app.js","url":"widadjust.app.js"}, + { "name": "widadjust.img","url":"app-icon.js","evaluate":true} ], "data": [ { "name": "widadjust.json" }, diff --git a/apps/widadjust/widadjust.app.js b/apps/widadjust/widadjust.app.js new file mode 100644 index 0000000000..e62e2417b4 --- /dev/null +++ b/apps/widadjust/widadjust.app.js @@ -0,0 +1,208 @@ +/* Widadjust auto adjuster */ + +/* fmt library v0.1.2 */ +let fmt = { + icon_alt : "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_m : "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3", + icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + + /* 0 .. DD.ddddd + 1 .. DD MM.mmm' + 2 .. DD MM'ss" + */ + geo_mode : 1, + + init: function() {}, + fmtDist: function(km) { return km.toFixed(1) + this.icon_km; }, + fmtSteps: function(n) { return fmtDist(0.001 * 0.719 * n); }, + fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, + draw_dot : 1, + add0: function(i) { + if (i > 9) { + return ""+i; + } else { + return "0"+i; + } + }, + fmtTOD: function(now) { + this.draw_dot = !this.draw_dot; + let dot = ":"; + if (!this.draw_dot) + dot = "."; + return now.getHours() + dot + this.add0(now.getMinutes()); + }, + fmtNow: function() { return this.fmtTOD(new Date()); }, + fmtTimeDiff: function(d) { + if (d < 180) + return ""+d.toFixed(0); + d = d/60; + return ""+d.toFixed(0)+"m"; + }, + fmtAngle: function(x) { + switch (this.geo_mode) { + case 0: + return "" + x; + case 1: { + let d = Math.floor(x); + let m = x - d; + m = m*60; + return "" + d + " " + m.toFixed(3) + "'"; + } + case 2: { + let d = Math.floor(x); + let m = x - d; + m = m*60; + let mf = Math.floor(m); + let s = m - mf; + s = s*60; + return "" + d + " " + mf + "'" + s.toFixed(0) + '"'; + } + } + return "bad mode?"; + }, + fmtPos: function(pos) { + let x = pos.lat; + let c = "N"; + if (x<0) { + c = "S"; + x = -x; + } + let s = c+this.fmtAngle(x) + "\n"; + c = "E"; + if (x<0) { + c = "W"; + x = -x; + } + return s + c + this.fmtAngle(x); + }, +}; + +/* gps library v0.1.1 */ +let gps = { + emulator: -1, + init: function(x) { + this.emulator = (process.env.BOARD=="EMSCRIPTEN" + || process.env.BOARD=="EMSCRIPTEN2")?1:0; + }, + state: {}, + on_gps: function(f) { + let fix = this.getGPSFix(); + f(fix); + + /* + "lat": number, // Latitude in degrees + "lon": number, // Longitude in degrees + "alt": number, // altitude in M + "speed": number, // Speed in kph + "course": number, // Course in degrees + "time": Date, // Current Time (or undefined if not known) + "satellites": 7, // Number of satellites + "fix": 1 // NMEA Fix state - 0 is no fix + "hdop": number, // Horizontal Dilution of Precision + */ + this.state.timeout = setTimeout(this.on_gps, 1000, f); + }, + off_gps: function() { + clearTimeout(gps_state.timeout); + }, + getGPSFix: function() { + if (!this.emulator) + return Bangle.getGPSFix(); + let fix = {}; + fix.fix = 1; + fix.lat = 50; + fix.lon = 14; + fix.alt = 200; + fix.speed = 5; + fix.course = 30; + fix.time = Date(); + fix.satellites = 5; + fix.hdop = 12; + return fix; + }, + gps_start : -1, + start_gps: function() { + Bangle.setGPSPower(1, "libgps"); + this.gps_start = getTime(); + }, + stop_gps: function() { + Bangle.setGPSPower(0, "libgps"); + }, +}; + +var start_time = -5, start_delta; + +function updateTime(fix, now) { + let s = fmt.fmtNow() + "\n"; + if (!fix.time) + return s + "???"; + + let delta = (now - fix.time.getTime()/1000); + let tdelta = "" + delta.toFixed(4); + + let is_fix = 1; + // = fix.fix + + if (start_time < -1) { + start_time ++; + } + + if (is_fix && start_time == -1) { + start_time = now; + start_delta = delta; + } + + if (!is_fix) + return s + "e " + tdelta + "s"; + + let ppm = (delta - start_delta) / (now - start_time); + let pd = ppm * (3600*24); + ppm *= 1000000; + return s + "ppm " + ppm.toFixed(1) + + "\n" + pd.toFixed(1) + "s/day" + + "\ne " + tdelta + "s"; +} + +var cancel_gps = 0; + +function on_gps(fix) { + // Do this first so that we don't get extra jitter + let now = getTime(); + let have = false, lat = "lat ", alt = "?", + speed = "speed ", hdop = "?", adelta = "adelta ", + tdelta = "tdelta "; + + if (cancel_gps) + return; + + let msg = ""; + if (fix && fix.fix && fix.lat) { + msg = "" + fix.speed.toFixed(1) + "km/h " + + fix.alt.toFixed(0) + "m"; + } else { + msg = "N/FIX " + + (getTime() - gps.gps_start).toFixed(0) + "s"; + } + + msg += "\n" + updateTime(fix, now); + + g.reset().clear().setFont("Vector", 31) + .setColor(1,1,1) + .fillRect(0, 24, 176, 100) + .setColor(0,0,0) + .drawString(msg, 3, 25); +} + +function stopGps() { + cancel_gps=true; + gps.stop_gps(); +} + +fmt.init(); +gps.init(); +gps.start_gps(); +Bangle.on('GPS', on_gps); + +g.reset(); From fdb9626dc988961bfe7278dc973472333e55b847 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 11 Nov 2024 21:23:25 +0100 Subject: [PATCH 2/5] widadjust: fix whitespace --- apps/widadjust/widadjust.app.js | 316 ++++++++++++++++---------------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/apps/widadjust/widadjust.app.js b/apps/widadjust/widadjust.app.js index e62e2417b4..8cfaf38199 100644 --- a/apps/widadjust/widadjust.app.js +++ b/apps/widadjust/widadjust.app.js @@ -2,126 +2,126 @@ /* fmt library v0.1.2 */ let fmt = { - icon_alt : "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", - icon_m : "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", - icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", - icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3", - icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + icon_alt : "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_m : "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", + icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3", + icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", /* 0 .. DD.ddddd 1 .. DD MM.mmm' 2 .. DD MM'ss" - */ - geo_mode : 1, - - init: function() {}, - fmtDist: function(km) { return km.toFixed(1) + this.icon_km; }, - fmtSteps: function(n) { return fmtDist(0.001 * 0.719 * n); }, - fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, - draw_dot : 1, - add0: function(i) { - if (i > 9) { - return ""+i; - } else { - return "0"+i; - } - }, - fmtTOD: function(now) { - this.draw_dot = !this.draw_dot; - let dot = ":"; - if (!this.draw_dot) - dot = "."; - return now.getHours() + dot + this.add0(now.getMinutes()); - }, - fmtNow: function() { return this.fmtTOD(new Date()); }, - fmtTimeDiff: function(d) { - if (d < 180) - return ""+d.toFixed(0); - d = d/60; - return ""+d.toFixed(0)+"m"; - }, - fmtAngle: function(x) { - switch (this.geo_mode) { - case 0: - return "" + x; - case 1: { - let d = Math.floor(x); - let m = x - d; - m = m*60; - return "" + d + " " + m.toFixed(3) + "'"; - } - case 2: { - let d = Math.floor(x); - let m = x - d; - m = m*60; - let mf = Math.floor(m); - let s = m - mf; - s = s*60; - return "" + d + " " + mf + "'" + s.toFixed(0) + '"'; - } - } - return "bad mode?"; - }, - fmtPos: function(pos) { - let x = pos.lat; - let c = "N"; - if (x<0) { - c = "S"; - x = -x; - } - let s = c+this.fmtAngle(x) + "\n"; - c = "E"; - if (x<0) { - c = "W"; - x = -x; - } - return s + c + this.fmtAngle(x); - }, + */ + geo_mode : 1, + + init: function() {}, + fmtDist: function(km) { return km.toFixed(1) + this.icon_km; }, + fmtSteps: function(n) { return fmtDist(0.001 * 0.719 * n); }, + fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, + draw_dot : 1, + add0: function(i) { + if (i > 9) { + return ""+i; + } else { + return "0"+i; + } + }, + fmtTOD: function(now) { + this.draw_dot = !this.draw_dot; + let dot = ":"; + if (!this.draw_dot) + dot = "."; + return now.getHours() + dot + this.add0(now.getMinutes()); + }, + fmtNow: function() { return this.fmtTOD(new Date()); }, + fmtTimeDiff: function(d) { + if (d < 180) + return ""+d.toFixed(0); + d = d/60; + return ""+d.toFixed(0)+"m"; + }, + fmtAngle: function(x) { + switch (this.geo_mode) { + case 0: + return "" + x; + case 1: { + let d = Math.floor(x); + let m = x - d; + m = m*60; + return "" + d + " " + m.toFixed(3) + "'"; + } + case 2: { + let d = Math.floor(x); + let m = x - d; + m = m*60; + let mf = Math.floor(m); + let s = m - mf; + s = s*60; + return "" + d + " " + mf + "'" + s.toFixed(0) + '"'; + } + } + return "bad mode?"; + }, + fmtPos: function(pos) { + let x = pos.lat; + let c = "N"; + if (x<0) { + c = "S"; + x = -x; + } + let s = c+this.fmtAngle(x) + "\n"; + c = "E"; + if (x<0) { + c = "W"; + x = -x; + } + return s + c + this.fmtAngle(x); + }, }; /* gps library v0.1.1 */ let gps = { - emulator: -1, - init: function(x) { - this.emulator = (process.env.BOARD=="EMSCRIPTEN" - || process.env.BOARD=="EMSCRIPTEN2")?1:0; - }, - state: {}, - on_gps: function(f) { - let fix = this.getGPSFix(); - f(fix); - - /* - "lat": number, // Latitude in degrees - "lon": number, // Longitude in degrees - "alt": number, // altitude in M - "speed": number, // Speed in kph - "course": number, // Course in degrees - "time": Date, // Current Time (or undefined if not known) - "satellites": 7, // Number of satellites - "fix": 1 // NMEA Fix state - 0 is no fix - "hdop": number, // Horizontal Dilution of Precision - */ - this.state.timeout = setTimeout(this.on_gps, 1000, f); - }, - off_gps: function() { - clearTimeout(gps_state.timeout); - }, - getGPSFix: function() { - if (!this.emulator) - return Bangle.getGPSFix(); - let fix = {}; - fix.fix = 1; - fix.lat = 50; - fix.lon = 14; - fix.alt = 200; - fix.speed = 5; - fix.course = 30; - fix.time = Date(); - fix.satellites = 5; - fix.hdop = 12; - return fix; - }, + emulator: -1, + init: function(x) { + this.emulator = (process.env.BOARD=="EMSCRIPTEN" + || process.env.BOARD=="EMSCRIPTEN2")?1:0; + }, + state: {}, + on_gps: function(f) { + let fix = this.getGPSFix(); + f(fix); + + /* + "lat": number, // Latitude in degrees + "lon": number, // Longitude in degrees + "alt": number, // altitude in M + "speed": number, // Speed in kph + "course": number, // Course in degrees + "time": Date, // Current Time (or undefined if not known) + "satellites": 7, // Number of satellites + "fix": 1 // NMEA Fix state - 0 is no fix + "hdop": number, // Horizontal Dilution of Precision + */ + this.state.timeout = setTimeout(this.on_gps, 1000, f); + }, + off_gps: function() { + clearTimeout(gps_state.timeout); + }, + getGPSFix: function() { + if (!this.emulator) + return Bangle.getGPSFix(); + let fix = {}; + fix.fix = 1; + fix.lat = 50; + fix.lon = 14; + fix.alt = 200; + fix.speed = 5; + fix.course = 30; + fix.time = Date(); + fix.satellites = 5; + fix.hdop = 12; + return fix; + }, gps_start : -1, start_gps: function() { Bangle.setGPSPower(1, "libgps"); @@ -135,64 +135,64 @@ let gps = { var start_time = -5, start_delta; function updateTime(fix, now) { - let s = fmt.fmtNow() + "\n"; - if (!fix.time) - return s + "???"; + let s = fmt.fmtNow() + "\n"; + if (!fix.time) + return s + "???"; - let delta = (now - fix.time.getTime()/1000); - let tdelta = "" + delta.toFixed(4); + let delta = (now - fix.time.getTime()/1000); + let tdelta = "" + delta.toFixed(4); - let is_fix = 1; + let is_fix = 1; // = fix.fix - if (start_time < -1) { - start_time ++; - } - - if (is_fix && start_time == -1) { - start_time = now; - start_delta = delta; - } - - if (!is_fix) - return s + "e " + tdelta + "s"; - - let ppm = (delta - start_delta) / (now - start_time); - let pd = ppm * (3600*24); - ppm *= 1000000; - return s + "ppm " + ppm.toFixed(1) - + "\n" + pd.toFixed(1) + "s/day" - + "\ne " + tdelta + "s"; + if (start_time < -1) { + start_time ++; + } + + if (is_fix && start_time == -1) { + start_time = now; + start_delta = delta; + } + + if (!is_fix) + return s + "e " + tdelta + "s"; + + let ppm = (delta - start_delta) / (now - start_time); + let pd = ppm * (3600*24); + ppm *= 1000000; + return s + "ppm " + ppm.toFixed(1) + + "\n" + pd.toFixed(1) + "s/day" + + "\ne " + tdelta + "s"; } var cancel_gps = 0; function on_gps(fix) { // Do this first so that we don't get extra jitter - let now = getTime(); - let have = false, lat = "lat ", alt = "?", - speed = "speed ", hdop = "?", adelta = "adelta ", - tdelta = "tdelta "; - - if (cancel_gps) - return; - - let msg = ""; - if (fix && fix.fix && fix.lat) { - msg = "" + fix.speed.toFixed(1) + "km/h " + - fix.alt.toFixed(0) + "m"; - } else { - msg = "N/FIX " - + (getTime() - gps.gps_start).toFixed(0) + "s"; - } + let now = getTime(); + let have = false, lat = "lat ", alt = "?", + speed = "speed ", hdop = "?", adelta = "adelta ", + tdelta = "tdelta "; + + if (cancel_gps) + return; + + let msg = ""; + if (fix && fix.fix && fix.lat) { + msg = "" + fix.speed.toFixed(1) + "km/h " + + fix.alt.toFixed(0) + "m"; + } else { + msg = "N/FIX " + + (getTime() - gps.gps_start).toFixed(0) + "s"; + } - msg += "\n" + updateTime(fix, now); + msg += "\n" + updateTime(fix, now); - g.reset().clear().setFont("Vector", 31) - .setColor(1,1,1) - .fillRect(0, 24, 176, 100) - .setColor(0,0,0) - .drawString(msg, 3, 25); + g.reset().clear().setFont("Vector", 31) + .setColor(1,1,1) + .fillRect(0, 24, 176, 100) + .setColor(0,0,0) + .drawString(msg, 3, 25); } function stopGps() { From b37a348c8bb1dd6e0e6c4ef7dea6cfcc2fe2b91b Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 11 Nov 2024 21:23:54 +0100 Subject: [PATCH 3/5] widadjust: remove trailing whitespace. --- apps/widadjust/widadjust.app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/widadjust/widadjust.app.js b/apps/widadjust/widadjust.app.js index 8cfaf38199..7b958e4e33 100644 --- a/apps/widadjust/widadjust.app.js +++ b/apps/widadjust/widadjust.app.js @@ -13,13 +13,13 @@ let fmt = { 2 .. DD MM'ss" */ geo_mode : 1, - + init: function() {}, fmtDist: function(km) { return km.toFixed(1) + this.icon_km; }, fmtSteps: function(n) { return fmtDist(0.001 * 0.719 * n); }, fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, draw_dot : 1, - add0: function(i) { + add0: function(i) { if (i > 9) { return ""+i; } else { @@ -83,7 +83,7 @@ let fmt = { let gps = { emulator: -1, init: function(x) { - this.emulator = (process.env.BOARD=="EMSCRIPTEN" + this.emulator = (process.env.BOARD=="EMSCRIPTEN" || process.env.BOARD=="EMSCRIPTEN2")?1:0; }, state: {}, @@ -141,10 +141,10 @@ function updateTime(fix, now) { let delta = (now - fix.time.getTime()/1000); let tdelta = "" + delta.toFixed(4); - + let is_fix = 1; // = fix.fix - + if (start_time < -1) { start_time ++; } @@ -183,9 +183,9 @@ function on_gps(fix) { fix.alt.toFixed(0) + "m"; } else { msg = "N/FIX " - + (getTime() - gps.gps_start).toFixed(0) + "s"; + + (getTime() - gps.gps_start).toFixed(0) + "s"; } - + msg += "\n" + updateTime(fix, now); g.reset().clear().setFont("Vector", 31) From 80096bafd96a879eba4ec2016aab51cb0c255984 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 11 Nov 2024 21:25:23 +0100 Subject: [PATCH 4/5] widadjust: switch to newer libraries to get rid of warnings. --- apps/widadjust/widadjust.app.js | 67 ++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/apps/widadjust/widadjust.app.js b/apps/widadjust/widadjust.app.js index 7b958e4e33..c17c70697d 100644 --- a/apps/widadjust/widadjust.app.js +++ b/apps/widadjust/widadjust.app.js @@ -1,12 +1,14 @@ /* Widadjust auto adjuster */ - -/* fmt library v0.1.2 */ +/* fmt library v0.2.2 */ let fmt = { icon_alt : "\0\x08\x1a\1\x00\x00\x00\x20\x30\x78\x7C\xFE\xFF\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", icon_m : "\0\x08\x1a\1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", icon_km : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\x00\x00\x00\x00\x00\x00\x00", icon_kph : "\0\x08\x1a\1\xC3\xC6\xCC\xD8\xF0\xD8\xCC\xC6\xC3\x00\xC3\xE7\xFF\xDB\xC3\xC3\xC3\xC3\x00\xFF\x00\xC3\xC3\xFF\xC3\xC3", icon_c : "\0\x08\x1a\1\x00\x00\x60\x90\x90\x60\x00\x7F\xFF\xC0\xC0\xC0\xC0\xC0\xFF\x7F\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + icon_hpa : "\x00\x08\x16\x01\x00\x80\xb0\xc8\x88\x88\x88\x00\xf0\x88\x84\x84\x88\xf0\x80\x8c\x92\x22\x25\x19\x00\x00", + icon_9 : "\x00\x08\x16\x01\x00\x00\x00\x00\x38\x44\x44\x4c\x34\x04\x04\x38\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + icon_10 : "\x00\x08\x16\x01\x00\x08\x18\x28\x08\x08\x08\x00\x00\x18\x24\x24\x24\x24\x18\x00\x00\x00\x00\x00\x00\x00", /* 0 .. DD.ddddd 1 .. DD MM.mmm' @@ -15,9 +17,23 @@ let fmt = { geo_mode : 1, init: function() {}, - fmtDist: function(km) { return km.toFixed(1) + this.icon_km; }, - fmtSteps: function(n) { return fmtDist(0.001 * 0.719 * n); }, + fmtDist: function(km) { + if (km >= 1.0) return km.toFixed(1) + this.icon_km; + return (km*1000).toFixed(0) + this.icon_m; + }, + fmtSteps: function(n) { return this.fmtDist(0.001 * 0.719 * n); }, fmtAlt: function(m) { return m.toFixed(0) + this.icon_alt; }, + fmtTemp: function(c) { return c.toFixed(1) + this.icon_c; }, + fmtPress: function(p) { + if (p < 900 || p > 1100) + return p.toFixed(0) + this.icon_hpa; + if (p < 1000) { + p -= 900; + return this.icon_9 + this.add0(p.toFixed(0)) + this.icon_hpa; + } + p -= 1000; + return this.icon_10 + this.add0(p.toFixed(0)) + this.icon_hpa; + }, draw_dot : 1, add0: function(i) { if (i > 9) { @@ -77,14 +93,46 @@ let fmt = { } return s + c + this.fmtAngle(x); }, + fmtFix: function(fix, t) { + if (fix && fix.fix && fix.lat) { + return this.fmtSpeed(fix.speed) + " " + + this.fmtAlt(fix.alt); + } else { + return "N/FIX " + this.fmtTimeDiff(t); + } + }, + fmtSpeed: function(kph) { + return kph.toFixed(1) + this.icon_kph; + }, + radians: function(a) { return a*Math.PI/180; }, + degrees: function(a) { return a*180/Math.PI; }, + // distance between 2 lat and lons, in meters, Mean Earth Radius = 6371km + // https://www.movable-type.co.uk/scripts/latlong.html + // (Equirectangular approximation) + // returns value in meters + distance: function(a,b) { + var x = this.radians(b.lon-a.lon) * Math.cos(this.radians((a.lat+b.lat)/2)); + var y = this.radians(b.lat-a.lat); + return Math.sqrt(x*x + y*y) * 6371000; + }, + // thanks to waypointer + bearing: function(a,b) { + var delta = this.radians(b.lon-a.lon); + var alat = this.radians(a.lat); + var blat = this.radians(b.lat); + var y = Math.sin(delta) * Math.cos(blat); + var x = Math.cos(alat) * Math.sin(blat) - + Math.sin(alat)*Math.cos(blat)*Math.cos(delta); + return Math.round(this.degrees(Math.atan2(y, x))); + }, }; -/* gps library v0.1.1 */ +/* gps library v0.1.4 */ let gps = { emulator: -1, init: function(x) { - this.emulator = (process.env.BOARD=="EMSCRIPTEN" - || process.env.BOARD=="EMSCRIPTEN2")?1:0; + this.emulator = (process.env.BOARD=="EMSCRIPTEN" + || process.env.BOARD=="EMSCRIPTEN2")?1:0; }, state: {}, on_gps: function(f) { @@ -105,7 +153,7 @@ let gps = { this.state.timeout = setTimeout(this.on_gps, 1000, f); }, off_gps: function() { - clearTimeout(gps_state.timeout); + clearTimeout(this.state.timeout); }, getGPSFix: function() { if (!this.emulator) @@ -113,7 +161,7 @@ let gps = { let fix = {}; fix.fix = 1; fix.lat = 50; - fix.lon = 14; + fix.lon = 14-(getTime()-this.gps_start) / 1000; /* Go West! */ fix.alt = 200; fix.speed = 5; fix.course = 30; @@ -132,6 +180,7 @@ let gps = { }, }; + var start_time = -5, start_delta; function updateTime(fix, now) { From af402261b902472ea3ee1a3bd37db00eb2dfbf5b Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Mon, 11 Nov 2024 21:28:29 +0100 Subject: [PATCH 5/5] widadjust: Fix rest of warnings. --- apps/widadjust/widadjust.app.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/apps/widadjust/widadjust.app.js b/apps/widadjust/widadjust.app.js index c17c70697d..38e595e591 100644 --- a/apps/widadjust/widadjust.app.js +++ b/apps/widadjust/widadjust.app.js @@ -219,9 +219,6 @@ var cancel_gps = 0; function on_gps(fix) { // Do this first so that we don't get extra jitter let now = getTime(); - let have = false, lat = "lat ", alt = "?", - speed = "speed ", hdop = "?", adelta = "adelta ", - tdelta = "tdelta "; if (cancel_gps) return; @@ -244,11 +241,6 @@ function on_gps(fix) { .drawString(msg, 3, 25); } -function stopGps() { - cancel_gps=true; - gps.stop_gps(); -} - fmt.init(); gps.init(); gps.start_gps();