Merge pull request #1222 from HilmarSt/master

Update GPS Info App and "Battery Level Widget (with percentage)"
master
Gordon Williams 2022-01-06 08:54:05 +00:00 committed by GitHub
commit 657e72234e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 37 deletions

View File

@ -936,7 +936,7 @@
"id": "widbatpc",
"name": "Battery Level Widget (with percentage)",
"shortName": "Battery Widget",
"version": "0.15",
"version": "0.16",
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
"icon": "widget.png",
"type": "widget",
@ -1501,7 +1501,7 @@
{
"id": "gpsinfo",
"name": "GPS Info",
"version": "0.06",
"version": "0.07",
"description": "An application that displays information about altitude, lat/lon, satellites and time",
"icon": "gps-info.png",
"type": "app",

View File

@ -2,4 +2,5 @@
0.03: Show number of satellites while waiting for fix
0.04: Add Maidenhead readout of GPS location
0.05: Refactor to use 'layout' library for multi-device support
0.06: Added number of satellites in view and fixed crash with GPS time
0.06: Add number of satellites in view and fix crash with GPS time
0.07: Resolve one FIFO_FULL case and exit App with button press

View File

@ -19,6 +19,7 @@ var lastFix = {
var SATinView = 0;
var nofBD = 0;
var nofGP = 0;
var listenerGPSraw = 1;
function formatTime(now) {
if (now == undefined) {
@ -93,6 +94,10 @@ function onGPS(fix) {
}
lastFix = fix;
if (fix.fix) {
if (listenerGPSraw == 1) {
Bangle.removeListener('GPS-raw', onGPSraw);
listenerGPSraw = 0;
}
var locale = require("locale");
var satellites = fix.satellites;
var maidenhead = getMaidenHead(fix.lat,fix.lon);
@ -104,6 +109,10 @@ function onGPS(fix) {
layout.sat.label = "Satellites: "+satellites;
layout.maidenhead.label = "Maidenhead: "+maidenhead;
} else {
if (listenerGPSraw == 0) {
Bangle.on('GPS-raw', onGPSraw);
listenerGPSraw = 1;
}
layout.sat.label = fix.satellites;
layout.progress.label = "in view: " + SATinView;
}
@ -111,15 +120,26 @@ function onGPS(fix) {
}
function onGPSraw(nmea) {
if (nmea.slice(3,6) == "GSV") {
// console.log(nmea);
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;
}
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;
}
Bangle.loadWidgets();
Bangle.drawWidgets();
Bangle.on('GPS', onGPS);
Bangle.on('GPS-raw', onGPSraw);
function exitApp() {
Bangle.setGPSPower(0, "app");
Bangle.removeListener('GPS-raw', onGPSraw);
Bangle.removeListener('GPS', onGPS);
load();
}
setWatch(_=>exitApp(), BTN1);
if (global.BTN2) {
setWatch(_=>exitApp(), BTN2);
setWatch(_=>exitApp(), BTN3);
}

View File

@ -12,3 +12,4 @@
0.13: Fillbar setting added, see README
0.14: Fix drawing the bar when charging
0.15: Added option to always display the icon when charging (useful if 'hide if charge greater than' is enabled)
0.16: Increase screen update rate when charging

View File

@ -1,6 +1,9 @@
(function(){
const intervalLow = 60000; // update time when not charging
const intervalHigh = 2000; // update time when charging
let COLORS = {};
if (process.env.HWVERSION == 1) {
COLORS = {
'white': -1, // White
@ -17,13 +20,13 @@
'high': "#0f0", // Green
'ok': "#ff0", // Orange
'low': "#f00", // Red
};
};
}
const SETTINGS_FILE = 'widbatpc.json'
const SETTINGS_FILE = 'widbatpc.json';
let settings
let settings;
function loadSettings() {
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {}
settings = require('Storage').readJSON(SETTINGS_FILE, 1) || {};
const DEFAULTS = {
'color': 'By Level',
'percentage': true,
@ -32,17 +35,17 @@
'alwaysoncharge': false,
};
Object.keys(DEFAULTS).forEach(k=>{
if (settings[k]===undefined) settings[k]=DEFAULTS[k]
if (settings[k]===undefined) settings[k]=DEFAULTS[k];
});
}
function setting(key) {
if (!settings) { loadSettings() }
if (!settings) { loadSettings(); }
return settings[key];
}
const levelColor = (l) => {
// "charging" is very bright -> percentage is hard to read, "high" is ok(ish)
const green = setting('percentage') ? COLORS.high : COLORS.charging
const green = setting('percentage') ? COLORS.high : COLORS.charging;
switch (setting('color')) {
case 'Monochrome': return COLORS.white; // no chance of reading the percentage here :-(
case 'Green': return green;
@ -59,10 +62,11 @@
if (l >= 15) return COLORS.ok;
return COLORS.low;
}
}
};
const chargerColor = () => {
return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging
}
return (setting('color') === 'Monochrome') ? COLORS.white : COLORS.charging;
};
// sets width, returns true if it changed
function setWidth() {
var w = 40;
@ -77,6 +81,7 @@
WIDGETS["batpc"].width = w;
return changed;
}
function draw() {
// if hidden, don't draw
if (!WIDGETS["batpc"].width) return;
@ -106,11 +111,11 @@
if (!setting('percentage')) {
return;
}
let gfx = g
let gfx = g;
if (setting('color') === 'Monochrome') {
// draw text inverted on battery level
gfx = Graphics.createCallback(g.getWidth(),g.getHeight(), 1,
(x,y) => {g.setPixel(x,y,x<=xl?0:-1)})
(x,y) => {g.setPixel(x,y,x<=xl?0:-1);});
}
gfx.setFontAlign(-1,-1);
if (l >= 100) {
@ -122,19 +127,24 @@
gfx.drawString(l, x + 6, y + 4);
}
}
// reload widget, e.g. when settings have changed
function reload() {
loadSettings()
loadSettings();
// need to redraw all widgets, because changing the "charger" setting
// can affect the width and mess with the whole widget layout
setWidth()
setWidth();
g.clear();
Bangle.drawWidgets();
}
// update widget - redraw just widget, or all widgets if size changed
function update() {
if (setWidth()) Bangle.drawWidgets();
else WIDGETS["batpc"].draw();
if (Bangle.isCharging()) changeInterval(id, intervalHigh);
else changeInterval(id, intervalLow);
}
Bangle.on('charging',function(charging) {
@ -142,20 +152,13 @@
update();
g.flip();
});
var batteryInterval;
Bangle.on('lcdPower', function(on) {
if (on) {
update();
// refresh once a minute if LCD on
if (!batteryInterval)
batteryInterval = setInterval(update, 60000);
} else {
if (batteryInterval) {
clearInterval(batteryInterval);
batteryInterval = undefined;
}
}
if (on) update();
});
var id = setInterval(()=>WIDGETS["batpc"].draw(), intervalLow);
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
setWidth();
})()
})();