1
0
Fork 0

clkinfogps added screenshots, debug, consistant timer handling

master
Hugh Barney 2023-04-23 13:30:15 +01:00
parent 31c0f0059a
commit 8416f6e5c5
6 changed files with 101 additions and 21 deletions

View File

@ -1,5 +1,61 @@
# GPS Clock Info
![](app.png)
A clock info that displays the Ordanance Survey (OS) grid reference
- The primary use is for walking where a GPS fix that is 2 minutes old is
perfectly fine for providing an OS map grid reference.
- Saves power by only turning the GPS on for the time it takes to get a fix.
- It then switches the GPS off for 90 seconds before trying to get the next fix
- At the start of the walk update the GPS with using one of the AGPS apps. This will
significantly reduce the time to the first fix.
- Displays the GPS time and number of satelites while waiting for a fix.
- The fix is invalidated after 4 minutes and will display 00:00:00 0
or the gps time while the gps is powered on and searching for a fix.
- If the display is shows solid 00:00:00 0 then tap the clkinfo to restart it
as it will have timed out after 4 minutes
- I suggest installing the GPS power widget so that you can be assured
when the GPS is draining power.
- It is unlikley that this style of gps clock info will work well with the Recorder
app as that would hold the GPS power permantly on all the time during the
recording.
## Screenshots
![](screenshot0.png)
- Above: The GPS is powered on and waiting for a fix.
- The GPS widget shows yellow indicating powered on
- The time from the GPS chip is displayed with the satellite count
- The time from the GPS chip is incrementing approximately every second
- Note the time on the GPS is in UTC and not the current timezone
![](screenshot1.png)
- Above: The GPS has a fix
- The OS grid reference has been calculated
- The GPS has been turned off for 90 seconds
- The GPS widget is grey showing the GPS is off
- You will not see the GPS widget turn green as the GPS is turned off after a fix
![](screenshot2.png)
- Above: The GPS has been powered on after 90 seconds and is waiting for a fix
![](screenshot3.png)
- Above: The GPS has not had a fix for 4 minutes and the cycle has stopped
- The time from the GPS is 00:00:00 0, indicating that the GPS not on
- The GPS widget is grey showing the GPS is off
- Tap the clock_info to restart the GPS clock info
Written by: [Hugh Barney](https://github.com/hughbarney) For support and discussion please post in the [Bangle JS Forum](http://forum.espruino.com/microcosms/1424/)

View File

@ -4,6 +4,10 @@
var fixTs;
var geo = require("geotools");
var debug = function(o) {
console.log(o);
};
var resetLastFix = function() {
last_fix = {
fix: 0,
@ -26,6 +30,35 @@
}
};
var clearTimer = function() {
if (timeout) {
clearTimeout(timeout);
timeout = undefined;
debug("timer cleared");
}
};
var queueGPSon = function() {
clearTimer();
// power on the GPS again in 90 seconds
timeout = setTimeout(function() {
timeout = undefined;
Bangle.setGPSPower(1,"clkinfo");
}, 90000);
debug("gps on queued");
};
var queueGPSoff = function() {
// turn off after 5 minutes, sooner if we get a fix
clearTimer();
timeout = setTimeout(function() {
timeout = undefined;
Bangle.setGPSPower(0,"clkinfo");
resetLastFix();
}, 300000);
debug("gps off queued");
};
var onGPS = function(fix) {
//console.log(fix);
last_fix.time = fix.time;
@ -35,17 +68,10 @@
last_fix = fix;
fixTs = Math.round(getTime());
// cancel the timeout, if not already timed out
if (this.timeout) {
clearTimeout(timeout);
this.timeout = undefined;
}
clearTimer();
// power off the GPS
Bangle.setGPSPower(0,"clkinfo");
// power on the GPS again in 90 seconds
timeout = setTimeout(function() {
timeout = undefined;
Bangle.setGPSPower(1,"clkinfo");
}, 90000);
queueGPSon();
}
// if our last fix was more than 4 minutes ago, reset the fix to show gps time + satelites
@ -63,8 +89,8 @@
// show gps time and satelite count
if (!last_fix.fix)
return formatTime(last_fix.time) + '.' + last_fix.satelites;
return formatTime(last_fix.time) + ' ' + last_fix.satellites;
return geo.gpsToOSMapRef(last_fix);
};
@ -77,27 +103,25 @@
text: gpsText()
}); },
run : function() {
console.log("run");
// if the timer is already runnuing reset it, we can get multiple run calls by tapping
clearTimer();
Bangle.setGPSPower(1,"clkinfo");
/* turn off after 5 minutes, sooner if we get a fix */
this.timeout = setTimeout(function() {
this.timeout = undefined;
Bangle.setGPSPower(0,"clkinfo");
resetLastFix();
}, 300000);
// turn GPS off after 5 mins if we dont get a fix, sooner if we get a fix
queueGPSoff();
},
show: function () {
console.log("show");
resetLastFix();
fixTs = Math.round(getTime());
Bangle.on("GPS",onGPS);
this.run();
},
hide: function() {
console.log("hide");
clearTimer();
Bangle.setGPSPower(0,"clkinfo");
Bangle.removeListener("GPS", onGPS);
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = undefined;
}
resetLastFix();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB