From 3615d7fe4c65992acb38c110728d501eab245543 Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Wed, 22 Dec 2021 22:57:05 +0100 Subject: [PATCH 1/4] Update gps-info.js 1. (bugfix) Workaround for a crash in toUTCString() if fix.time has the value "undefined", see https://github.com/espruino/BangleApps/issues/1155 2. (improvement) The 4-dot progress indicator is replaced by the number of satellites in view. Tested on Bangle.js 2 with firmware 2v11 --- apps/gpsinfo/gps-info.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/apps/gpsinfo/gps-info.js b/apps/gpsinfo/gps-info.js index df888651a..cca7e8e0f 100644 --- a/apps/gpsinfo/gps-info.js +++ b/apps/gpsinfo/gps-info.js @@ -16,13 +16,17 @@ var lastFix = { time: 0, satellites: 0 }; -var nofix = 0; +var SATinView = 0; function formatTime(now) { - var fd = now.toUTCString().split(" "); - var time = fd[4].substr(0, 5); - var date = [fd[0], fd[1], fd[2]].join(" "); - return time + " - " + date; + if (now == undefined) { + return "no GPS time available"; + } else { + var fd = now.toUTCString().split(" "); + var time = fd[4].substr(0, 5); + var date = [fd[0], fd[1], fd[2]].join(" "); + return time + " - " + date; + } } function getMaidenHead(param1,param2){ var lat=-100.0; @@ -77,9 +81,9 @@ function onGPS(fix) { {type:"txt", font:"6x8", label:"Waiting for GPS" }, {type:"h", c: [ {type:"txt", font:"10%", label:fix.satellites, pad:2, id:"sat" }, - {type:"txt", font:"6x8", pad:3, label:"Satellites" } + {type:"txt", font:"6x8", pad:3, label:"Satellites used" } ]}, - {type:"txt", font:"6x8", label:"", id:"progress" } + {type:"txt", font:"6x8", label:"", fillx:true, id:"progress" } ]},{lazy:true}); } g.clearRect(0,24,g.getWidth(),g.getHeight()); @@ -87,7 +91,6 @@ function onGPS(fix) { } lastFix = fix; if (fix.fix) { - nofix = 0; var locale = require("locale"); var satellites = fix.satellites; var maidenhead = getMaidenHead(fix.lat,fix.lon); @@ -100,12 +103,18 @@ function onGPS(fix) { layout.maidenhead.label = "Maidenhead: "+maidenhead; } else { layout.sat.label = fix.satellites; - nofix = (nofix+1) % 4; - layout.progress.label = ".".repeat(nofix) + " ".repeat(4-nofix); + layout.progress.label = "in view: " + SATinView; } layout.render(); } +function onGPSraw(nmea) { + if (nmea.slice(3,6) == "GSV") { + SATinView = nmea.slice(11,13); + } +} + Bangle.loadWidgets(); Bangle.drawWidgets(); Bangle.on('GPS', onGPS); +Bangle.on('GPS-raw', onGPSraw); From d76a89b89acdb55aa25059c2522492302854e9e4 Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Fri, 24 Dec 2021 12:42:25 +0100 Subject: [PATCH 2/4] Update gps-info.js Sum up number of GPS and Beidou satellites in view. --- apps/gpsinfo/gps-info.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/gpsinfo/gps-info.js b/apps/gpsinfo/gps-info.js index cca7e8e0f..4c935b61a 100644 --- a/apps/gpsinfo/gps-info.js +++ b/apps/gpsinfo/gps-info.js @@ -109,8 +109,13 @@ function onGPS(fix) { } function onGPSraw(nmea) { + var nofBD = 0; + var nofGP = 0; if (nmea.slice(3,6) == "GSV") { - SATinView = nmea.slice(11,13); + // console.log(nmea); + if (nmea.slice(0,7) == "$BDGSV,") nofBD = nmea.slice(11,13); + if (nmea.slice(0,7) == "$GPGSV,") nofGP = nmea.slice(11,13); + SATinView = nofBD + nofGP; } } From 495ee69251126350d174b3785117626693d03e3e Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:08:32 +0100 Subject: [PATCH 3/4] Update apps/gpsinfo/gps-info.js (nofBD and/or nofGP are not recognized as numbers) Co-authored-by: BartS23 <10829389+BartS23@users.noreply.github.com> --- apps/gpsinfo/gps-info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gpsinfo/gps-info.js b/apps/gpsinfo/gps-info.js index 4c935b61a..3c8bd42ea 100644 --- a/apps/gpsinfo/gps-info.js +++ b/apps/gpsinfo/gps-info.js @@ -113,8 +113,8 @@ function onGPSraw(nmea) { var nofGP = 0; if (nmea.slice(3,6) == "GSV") { // console.log(nmea); - if (nmea.slice(0,7) == "$BDGSV,") nofBD = nmea.slice(11,13); - if (nmea.slice(0,7) == "$GPGSV,") nofGP = nmea.slice(11,13); + if (nmea.slice(0,7) == "$BDGSV,") nofBD = Number(nmea.slice(11,13)); + if (nmea.slice(0,7) == "$GPGSV,") nofGP = Number(nmea.slice(11,13)); SATinView = nofBD + nofGP; } } From aa45ecdb961dab07cd74b992f44fe5692f69aafc Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Mon, 3 Jan 2022 11:49:43 +0100 Subject: [PATCH 4/4] Update gps-info.js : make nofBD and nofGP global ...otherwise one of them is always zero. Thanks, BartS23 --- apps/gpsinfo/gps-info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/gpsinfo/gps-info.js b/apps/gpsinfo/gps-info.js index 3c8bd42ea..a16d4a04e 100644 --- a/apps/gpsinfo/gps-info.js +++ b/apps/gpsinfo/gps-info.js @@ -17,6 +17,8 @@ var lastFix = { satellites: 0 }; var SATinView = 0; +var nofBD = 0; +var nofGP = 0; function formatTime(now) { if (now == undefined) { @@ -109,8 +111,6 @@ function onGPS(fix) { } function onGPSraw(nmea) { - var nofBD = 0; - var nofGP = 0; if (nmea.slice(3,6) == "GSV") { // console.log(nmea); if (nmea.slice(0,7) == "$BDGSV,") nofBD = Number(nmea.slice(11,13));