Skip to content

[Power Manager] Round battery percentage #3904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions apps/powermanager/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require('Storage').readJSON("powermanager.default.json", true) || {},
require('Storage').readJSON("powermanager.json", true) || {}
);

if (settings.log) {
let logFile = require('Storage').open("powermanager.log","a");
let def = require('Storage').readJSON("powermanager.def.json", true) || {};
Expand All @@ -12,7 +12,7 @@
let hw = require('Storage').readJSON("powermanager.hw.json", true) || {};
if (!hw.start) hw.start = Date.now();
if (!hw.power) hw.power = {};

const saveEvery = 1000 * 60 * 5;
const TO_WRAP = ["GPS","Compass","Barometer","HRM","LCD"];

Expand All @@ -28,7 +28,9 @@
require('Storage').writeJSON("powermanager.hw.json", hw);
}
}




setInterval(save, saveEvery);

E.on("kill", ()=>{
Expand Down Expand Up @@ -75,7 +77,7 @@
})(Bangle[functionName]);
}

let functions = {};

let wrapDeferred = ((o,t) => (a) => {
if (a == eval || typeof a == "string") {
return o.apply(this, arguments);
Expand Down Expand Up @@ -131,15 +133,30 @@
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;
};
var percentToReturn;
if(Bangle.isCharging()){
//only go up
if(newPercent>savedBatPercent){
percentToReturn=newPercent;
savedBatPercent=newPercent;
}else{
percentToReturn=savedBatPercent;
}
}else{
if(newPercent<savedBatPercent){
percentToReturn=newPercent;
savedBatPercent=newPercent;
}else{
percentToReturn=savedBatPercent;
}
}
return percentToReturn;
};
}

if (settings.forceMonoVoltage){
Expand Down