Merge pull request #3904 from RKBoss6/PowerManager

[Power Manager] Round battery percentage
master
Rob Pilling 2025-08-01 08:30:10 +01:00 committed by GitHub
commit 07ba704afb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 16 deletions

View File

@ -13,3 +13,4 @@
0.10: Use charging state on boot for auto calibration
Log additional timestamp for trace log
0.11: Minor code improvements
0.12: Round monotonic percentage, rename to stable percentage/voltage

View File

@ -29,6 +29,8 @@
}
}
setInterval(save, saveEvery);
E.on("kill", ()=>{
@ -75,7 +77,7 @@
})(Bangle[functionName]);
}
let functions = {};
let wrapDeferred = ((o,t) => (a) => {
if (a == eval || typeof a == "string") {
return o.apply(this, arguments);
@ -131,19 +133,25 @@
handleCharging(Bangle.isCharging());
}
var savedBatPercent=E.getBattery();
if (settings.forceMonoPercentage){
var p = (E.getBattery()+E.getBattery()+E.getBattery()+E.getBattery())/4;
var op = E.getBattery;
var newPercent =Math.round((E.getBattery()+E.getBattery()+E.getBattery()+E.getBattery()+E.getBattery()+E.getBattery())/6);
E.getBattery = function() {
var current = Math.round((op()+op()+op()+op())/4);
if (Bangle.isCharging() && current > p) p = current;
if (!Bangle.isCharging() && current < p) p = current;
return p;
if(Bangle.isCharging()){
if(newPercent > savedBatPercent)
savedBatPercent = newPercent;
}else{
if(newPercent < savedBatPercent)
savedBatPercent = newPercent;
}
return savedBatPercent;
};
}
if (settings.forceMonoVoltage){
var v = (NRF.getBattery()+NRF.getBattery()+NRF.getBattery()+NRF.getBattery())/4;
var v = (NRF.getBattery()+NRF.getBattery()+NRF.getBattery()+NRF.getBattery()+NRF.getBattery()+NRF.getBattery())/6;
var ov = NRF.getBattery;
NRF.getBattery = function() {
var current = (ov()+ov()+ov()+ov())/4;

View File

@ -2,8 +2,8 @@
"id": "powermanager",
"name": "Power Manager",
"shortName": "Power Manager",
"version": "0.11",
"description": "Allow configuration of warnings and thresholds for battery charging and display.",
"version": "0.12",
"description": "Allow configuration of warnings for battery charging, stabilization of voltage, stabilization of battery percentage, and battery logging.",
"icon": "app.png",
"type": "bootloader",
"tags": "tool",

View File

@ -27,13 +27,13 @@
'Widget': function() {
E.showMenu(submenu_widget);
},
'Monotonic percentage': {
'Stable Percentage': {
value: !!settings.forceMonoPercentage,
onchange: v => {
writeSettings("forceMonoPercentage", v);
}
},
'Monotonic voltage': {
'Stable Voltage': {
value: !!settings.forceMonoVoltage,
onchange: v => {
writeSettings("forceMonoVoltage", v);