clkinfogps clear fixTime/display if no fix for 4 minutes

master
Hugh Barney 2023-04-22 14:33:31 +01:00
parent 84a85b6de9
commit 03f5b12cf2
1 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,7 @@
(function () { (function () {
var timeout; var timeout;
var last_fix; var last_fix;
var fixTs;
var geo = require("geotools"); var geo = require("geotools");
var resetLastFix = function() { var resetLastFix = function() {
@ -32,6 +33,7 @@
// we got a fix // we got a fix
if (fix.fix) { if (fix.fix) {
last_fix = fix; last_fix = fix;
fixTs = Math.round(getTime());
// cancel the timeout, if not already timed out // cancel the timeout, if not already timed out
if (this.timeout) { if (this.timeout) {
clearTimeout(timeout); clearTimeout(timeout);
@ -45,6 +47,13 @@
Bangle.setGPSPower(1,"clkinfo"); Bangle.setGPSPower(1,"clkinfo");
}, 90000); }, 90000);
} }
// if our last fix was more than 4 minutes ago, reset the fix to show gps time + satelites
if (Math.round(getTime()) - fixTs > 240) {
resetLastFix();
fixTs = Math.round(getTime());
}
info.items[0].emit("redraw"); info.items[0].emit("redraw");
}; };
@ -52,8 +61,9 @@
if (last_fix === undefined) if (last_fix === undefined)
return ''; return '';
// show gps time and satelite count
if (!last_fix.fix) if (!last_fix.fix)
return formatTime(last_fix.time); return formatTime(last_fix.time) + '.' + formatTime(last_fix.satelites);
return geo.gpsToOSMapRef(last_fix); return geo.gpsToOSMapRef(last_fix);
}; };
@ -72,10 +82,12 @@
this.timeout = setTimeout(function() { this.timeout = setTimeout(function() {
this.timeout = undefined; this.timeout = undefined;
Bangle.setGPSPower(0,"clkinfo"); Bangle.setGPSPower(0,"clkinfo");
resetLastFix();
}, 300000); }, 300000);
}, },
show: function () { show: function () {
resetLastFix(); resetLastFix();
fixTs = Math.round(getTime());
Bangle.on("GPS",onGPS); Bangle.on("GPS",onGPS);
this.run(); this.run();
}, },