widbatpc remove jitter option

Add option 'Remove Jitter'='Drop only' to prevent percentage from getting up again when not charging
pull/2536/head
Erik Andresen 2023-01-28 10:06:01 +01:00
parent 134f258d39
commit 3287106ed7
6 changed files with 36 additions and 10 deletions

View File

@ -9,6 +9,7 @@
"readme": "README.md", "readme": "README.md",
"description": "Simple and slim battery widget with charge status and percentage", "description": "Simple and slim battery widget with charge status and percentage",
"tags": "widget,battery", "tags": "widget,battery",
"provides_widgets" : ["battery"],
"storage": [ "storage": [
{"name":"hwid_a_battery_widget.wid.js","url":"widget.js"} {"name":"hwid_a_battery_widget.wid.js","url":"widget.js"}
] ]

View File

@ -9,6 +9,7 @@
"readme": "README.md", "readme": "README.md",
"description": "Simple and slim battery widget with charge status and percentage", "description": "Simple and slim battery widget with charge status and percentage",
"tags": "widget,battery", "tags": "widget,battery",
"provides_widgets" : ["battery"],
"storage": [ "storage": [
{"name":"wid_a_battery_widget.wid.js","url":"widget.js"} {"name":"wid_a_battery_widget.wid.js","url":"widget.js"}
] ]

View File

@ -13,3 +13,4 @@
0.14: Fix drawing the bar when charging 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.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 0.16: Increase screen update rate when charging
0.17: Add option 'Remove Jitter'='Drop only' to prevent percentage from getting up again when not charging

View File

@ -2,7 +2,7 @@
"id": "widbatpc", "id": "widbatpc",
"name": "Battery Level Widget (with percentage)", "name": "Battery Level Widget (with percentage)",
"shortName": "Battery Widget", "shortName": "Battery Widget",
"version": "0.16", "version": "0.17",
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage", "description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
"icon": "widget.png", "icon": "widget.png",
"type": "widget", "type": "widget",

View File

@ -5,6 +5,7 @@
(function(back) { (function(back) {
const SETTINGS_FILE = 'widbatpc.json' const SETTINGS_FILE = 'widbatpc.json'
const COLORS = ['By Level', 'Green', 'Monochrome'] const COLORS = ['By Level', 'Green', 'Monochrome']
const RM_JITTER_OPTIONS = [/*LANG*/'Off', /*LANG*/'Drop only'];
// initialize with default settings... // initialize with default settings...
let s = { let s = {
@ -14,6 +15,7 @@
'charger': true, 'charger': true,
'hideifmorethan': 100, 'hideifmorethan': 100,
'alwaysoncharge': false, 'alwaysoncharge': false,
'removejitter': 0,
} }
// ...and overwrite them with any saved values // ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings // This way saved values are preserved if a new version adds more settings
@ -28,7 +30,9 @@
return function (value) { return function (value) {
s[key] = value; s[key] = value;
storage.write(SETTINGS_FILE, s); storage.write(SETTINGS_FILE, s);
WIDGETS["batpc"].reload(); if ("WIDGETS" in global && WIDGETS["batpc"] !== undefined) {
WIDGETS["batpc"].reload();
}
} }
} }
@ -36,17 +40,17 @@
const menu = { const menu = {
'': { 'title': 'Battery Widget' }, '': { 'title': 'Battery Widget' },
'< Back': back, '< Back': back,
'Percentage': { /*LANG*/'Percentage': {
value: s.percentage, value: s.percentage,
format: onOffFormat, format: onOffFormat,
onchange: save('percentage'), onchange: save('percentage'),
}, },
'Charging Icon': { /*LANG*/'Charging Icon': {
value: s.charger, value: s.charger,
format: onOffFormat, format: onOffFormat,
onchange: save('charger'), onchange: save('charger'),
}, },
'Color': { /*LANG*/'Color': {
format: () => s.color, format: () => s.color,
onchange: function () { onchange: function () {
// cycles through options // cycles through options
@ -56,12 +60,12 @@
save('color')(s.color) save('color')(s.color)
} }
}, },
'Fill Bar': { /*LANG*/'Fill Bar': {
value: s.fillbar, value: s.fillbar,
format: onOffFormat, format: onOffFormat,
onchange: save('fillbar'), onchange: save('fillbar'),
}, },
'Hide if >': { /*LANG*/'Hide if >': {
value: s.hideifmorethan||100, value: s.hideifmorethan||100,
min: 10, min: 10,
max : 100, max : 100,
@ -69,11 +73,17 @@
format: x => x+"%", format: x => x+"%",
onchange: save('hideifmorethan'), onchange: save('hideifmorethan'),
}, },
'Show on charge': { // Not sure if this is readable enough in the 'big' menu /*LANG*/'Show on charge': { // Not sure if this is readable enough in the 'big' menu
value: s.alwaysoncharge, value: s.alwaysoncharge,
format: onOffFormat, format: onOffFormat,
onchange: save('alwaysoncharge'), onchange: save('alwaysoncharge'),
}, },
/*LANG*/'Remove Jitter': {
value: s.removejitter,
min: 0, max: 1,
format: v => RM_JITTER_OPTIONS[v],
onchange: save('removejitter'),
},
} }
E.showMenu(menu) E.showMenu(menu)
}) })

View File

@ -2,6 +2,8 @@
const intervalLow = 60000; // update time when not charging const intervalLow = 60000; // update time when not charging
const intervalHigh = 2000; // update time when charging const intervalHigh = 2000; // update time when charging
let prevMin = 100;
let COLORS = {}; let COLORS = {};
if (process.env.HWVERSION == 1) { if (process.env.HWVERSION == 1) {
@ -33,6 +35,7 @@
'charger': true, 'charger': true,
'hideifmorethan': 100, 'hideifmorethan': 100,
'alwaysoncharge': false, 'alwaysoncharge': false,
'removejitter': 0, // 0 == off, 1 == downwards only
}; };
Object.keys(DEFAULTS).forEach(k=>{ Object.keys(DEFAULTS).forEach(k=>{
if (settings[k]===undefined) settings[k]=DEFAULTS[k]; if (settings[k]===undefined) settings[k]=DEFAULTS[k];
@ -88,8 +91,18 @@
// else... // else...
var s = 39; var s = 39;
var x = this.x, y = this.y; var x = this.x, y = this.y;
const l = E.getBattery(), let l = E.getBattery();
c = levelColor(l); if (setting('removejitter') === 1) {
// if we have seen a battery percentage that was lower than current, use lower
if (Bangle.isCharging()) {
prevMin = l; // charging is the only way to increase percentage
} else if (prevMin >= l) {
prevMin = l;
} else {
l = prevMin;
}
}
const c = levelColor(l);
if (Bangle.isCharging() && setting('charger')) { if (Bangle.isCharging() && setting('charger')) {
g.setColor(chargerColor()).drawImage(atob( g.setColor(chargerColor()).drawImage(atob(