From 71228efb4ba118f8c4c2145174008ca02f329b1c Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Wed, 5 Jan 2022 23:12:16 +0100 Subject: [PATCH 1/7] Update gps-info.js Resolve one FIFO_FULL case and exit App with button press --- apps/gpsinfo/gps-info.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/gpsinfo/gps-info.js b/apps/gpsinfo/gps-info.js index a16d4a04e..467d12a95 100644 --- a/apps/gpsinfo/gps-info.js +++ b/apps/gpsinfo/gps-info.js @@ -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); +} From b2f844f32704d1863f18409f4da9898cef21f416 Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Wed, 5 Jan 2022 23:15:27 +0100 Subject: [PATCH 2/7] Update apps.json --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index ebafa9c97..7e3d29cdc 100644 --- a/apps.json +++ b/apps.json @@ -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", From 97200f4ac566881ffa01b245c0da6cab61d08904 Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Wed, 5 Jan 2022 23:16:33 +0100 Subject: [PATCH 3/7] Update ChangeLog --- apps/gpsinfo/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/gpsinfo/ChangeLog b/apps/gpsinfo/ChangeLog index 3ff284cb8..284ff7999 100644 --- a/apps/gpsinfo/ChangeLog +++ b/apps/gpsinfo/ChangeLog @@ -3,3 +3,4 @@ 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.07: Resolve one FIFO_FULL case and exit App with button press From f167ab829bf4f6fc1e78437cccbfadcfc984310a Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Wed, 5 Jan 2022 23:17:04 +0100 Subject: [PATCH 4/7] Update ChangeLog --- apps/gpsinfo/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/gpsinfo/ChangeLog b/apps/gpsinfo/ChangeLog index 284ff7999..a3a2fc89a 100644 --- a/apps/gpsinfo/ChangeLog +++ b/apps/gpsinfo/ChangeLog @@ -2,5 +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 From d305de0bdc274c8c82a4a76556c506b9c6bfcff8 Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Thu, 6 Jan 2022 01:59:22 +0100 Subject: [PATCH 5/7] Update widget.js Increase screen update rate when charging, as requested by issue https://github.com/espruino/BangleApps/issues/1137 --- apps/widbatpc/widget.js | 59 ++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/apps/widbatpc/widget.js b/apps/widbatpc/widget.js index 5386ffe22..529923386 100644 --- a/apps/widbatpc/widget.js +++ b/apps/widbatpc/widget.js @@ -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(); -})() +})(); From d343de172ea4a4a8e8a7b35c1d61af1435ac957e Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Thu, 6 Jan 2022 02:01:54 +0100 Subject: [PATCH 6/7] Update ChangeLog --- apps/widbatpc/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/widbatpc/ChangeLog b/apps/widbatpc/ChangeLog index 273e611a4..e70093659 100644 --- a/apps/widbatpc/ChangeLog +++ b/apps/widbatpc/ChangeLog @@ -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 From 50ae67fcd7127d52ebc7d1eda834a02e91e44da2 Mon Sep 17 00:00:00 2001 From: Hilmar Strauch <56518493+HilmarSt@users.noreply.github.com> Date: Thu, 6 Jan 2022 02:03:30 +0100 Subject: [PATCH 7/7] Update apps.json --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 7e3d29cdc..e37326674 100644 --- a/apps.json +++ b/apps.json @@ -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",