forked from FOSS/BangleApps
Merge pull request #2040 from myxor/widgps_0.07
GPS Widget: Alternative marker icon (configurable via settings)master
commit
2d2aff8a11
|
@ -4,3 +4,4 @@
|
|||
0.04: Show GPS fix status
|
||||
0.05: Don't poll for GPS status, override setGPSPower handler (fix #1456)
|
||||
0.06: Periodically update so the always on display does show current GPS fix
|
||||
0.07: Alternative marker icon (configurable via settings)
|
||||
|
|
|
@ -6,12 +6,19 @@ The GPS can quickly run the battery down if it is on all the time so
|
|||
it is useful to know if it has been switched on or not.
|
||||
|
||||
- Uses Bangle.isGPSOn()
|
||||
- Shows in grey when the GPS is off
|
||||
- Shows in amber when the GPS is on but has no fix
|
||||
- Shows in green when the GPS is on and has a fix
|
||||
|
||||
There are two icons which can be used to visualize the GPS/GNSS status:
|
||||
1. A cross colored depending on the GPS/GNSS status
|
||||
- Shows in grey when the GPS is off
|
||||
- Shows in amber when the GPS is on but has no fix
|
||||
- Shows in green when the GPS is on and has a fix
|
||||
2. Different place markers depending on GPS/GNSS status
|
||||
|
||||
|
||||
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/)
|
||||
|
||||
Extended by Marco ([myxor](https://github.com/myxor))
|
||||
|
||||
Place marker icons from [icons8.com](https://icons8.com/icon/set/maps/material-outlined).
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"crossIcon": "true"}
|
|
@ -1,14 +1,19 @@
|
|||
{
|
||||
"id": "widgps",
|
||||
"name": "GPS Widget",
|
||||
"version": "0.06",
|
||||
"description": "Tiny widget to show the power and fix status of the GPS",
|
||||
"version": "0.07",
|
||||
"description": "Tiny widget to show the power and fix status of the GPS/GNSS",
|
||||
"icon": "widget.png",
|
||||
"type": "widget",
|
||||
"tags": "widget,gps",
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"readme": "README.md",
|
||||
"storage": [
|
||||
{"name":"widgps.wid.js","url":"widget.js"}
|
||||
{"name":"widgps.wid.js","url":"widget.js"},
|
||||
{"name":"widgps.default.json","url":"default.json"},
|
||||
{"name":"widgps.settings.js","url":"settings.js"}
|
||||
],
|
||||
"data": [
|
||||
{"name":"widgps.json"}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
(function(back) {
|
||||
function writeSettings(key, value) {
|
||||
var s = require('Storage').readJSON(FILE, true) || {};
|
||||
s[key] = value;
|
||||
require('Storage').writeJSON(FILE, s);
|
||||
readSettings();
|
||||
}
|
||||
|
||||
function readSettings() {
|
||||
settings = Object.assign(
|
||||
require('Storage').readJSON("widgps.default.json", true) || {},
|
||||
require('Storage').readJSON(FILE, true) || {});
|
||||
}
|
||||
|
||||
var FILE = "widgps.json";
|
||||
var settings;
|
||||
readSettings();
|
||||
|
||||
var mainmenu = {
|
||||
'' : {'title' : 'GPS widget'},
|
||||
'< Back' : back,
|
||||
"Cross icon" : {
|
||||
value : !!settings.crossIcon ,
|
||||
onchange : v => { writeSettings("crossIcon", v); }
|
||||
},
|
||||
};
|
||||
E.showMenu(mainmenu);
|
||||
});
|
|
@ -1,36 +1,69 @@
|
|||
(function(){
|
||||
var interval;
|
||||
(function() {
|
||||
let settings =
|
||||
require("Storage").readJSON("widgps.json", 1) || {crossIcon : true};
|
||||
|
||||
// override setGPSPower so we know if GPS is on or off
|
||||
var oldSetGPSPower = Bangle.setGPSPower;
|
||||
Bangle.setGPSPower = function(on,id) {
|
||||
var isGPSon = oldSetGPSPower(on,id);
|
||||
WIDGETS.gps.draw();
|
||||
return isGPSon;
|
||||
}
|
||||
var interval;
|
||||
|
||||
WIDGETS.gps={area:"tr",width:24,draw:function() {
|
||||
// override setGPSPower so we know if GPS is on or off
|
||||
var oldSetGPSPower = Bangle.setGPSPower;
|
||||
Bangle.setGPSPower = function(on, id) {
|
||||
var isGPSon = oldSetGPSPower(on, id);
|
||||
WIDGETS.gps.draw();
|
||||
return isGPSon;
|
||||
};
|
||||
|
||||
WIDGETS.gps = {
|
||||
area : "tr",
|
||||
width : 24,
|
||||
draw : function() {
|
||||
g.reset();
|
||||
if (Bangle.isGPSOn()) {
|
||||
const gpsObject = Bangle.getGPSFix();
|
||||
if (gpsObject && gpsObject.fix > 0) {
|
||||
g.setColor("#0F0"); // on and has fix = green
|
||||
} else {
|
||||
g.setColor("#FD0"); // on but no fix = amber
|
||||
}
|
||||
} else {
|
||||
g.setColor("#888"); // off = grey
|
||||
}
|
||||
|
||||
// check if we need to update the widget periodically
|
||||
if (Bangle.isGPSOn() && interval === undefined) {
|
||||
interval = setInterval(function() {
|
||||
WIDGETS.gps.draw(WIDGETS.gps);
|
||||
}, 10*1000); // update every 10 seconds to show gps fix/no fix
|
||||
interval = setInterval(
|
||||
function() { WIDGETS.gps.draw(WIDGETS.gps); },
|
||||
10 * 1000); // update every 10 seconds to show gps fix/no fix
|
||||
} else if (!Bangle.isGPSOn() && interval !== undefined) {
|
||||
clearInterval(interval);
|
||||
interval = undefined;
|
||||
}
|
||||
g.drawImage(atob("GBiBAAAAAAAAAAAAAA//8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAAAAAA=="), this.x, 2+this.y);
|
||||
}};
|
||||
if (settings.crossIcon) {
|
||||
if (Bangle.isGPSOn()) {
|
||||
const gpsObject = Bangle.getGPSFix();
|
||||
if (gpsObject && gpsObject.fix > 0) {
|
||||
g.setColor("#0F0"); // on and has fix = green
|
||||
} else {
|
||||
g.setColor("#FD0"); // on but no fix = amber
|
||||
}
|
||||
} else {
|
||||
g.setColor("#888"); // off = grey
|
||||
}
|
||||
g.drawImage(
|
||||
atob(
|
||||
"GBiBAAAAAAAAAAAAAA//8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAAAAAA=="),
|
||||
this.x, 2 + this.y);
|
||||
} else { // marker icons
|
||||
if (Bangle.isGPSOn()) {
|
||||
const gpsObject = Bangle.getGPSFix();
|
||||
if (gpsObject && gpsObject.fix > 0) {
|
||||
// on and has fix
|
||||
g.drawImage(
|
||||
atob("GBiBAAAAAAAAAAB+AAD/AAHDgAMAwAcAwAY8YAY8YAY8YAY8YAMAwAMAwAOBwAGBgAHDgADDAABmAAB+AAA8AAAYAAAAAAAAAAAAAA=="),
|
||||
this.x, 2 + this.y);
|
||||
|
||||
} else {
|
||||
// GNSS on but no fix
|
||||
g.drawImage(
|
||||
atob("GBiBAAAAAAAAAAh+AA3/gA+B4A8AcA+AMAA8GAB+GADnDADDDADDDDDDADBmADB+ABg8ABgYAAwB8A4A8AeB8AH/sAB+EAAAAAAAAA=="),
|
||||
this.x, 2 + this.y);
|
||||
}
|
||||
} else {
|
||||
// GNSS off
|
||||
g.drawImage(
|
||||
atob("GBiBAAAAAAAAAAB+ABj/ABxDgA4AwAcAwAeMYAfEYAbgYAZwYAM4wAMcQAOOAAGHAAHDgADDwABm4AB+cAA8OAAYGAAAAAAAAAAAAA=="),
|
||||
this.x, 2 + this.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue