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] 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);