powermanager - Approximate LCD power use based on brightness

master
Martin Boonk 2023-02-20 19:39:31 +01:00
parent 999bef9f5d
commit ae81d93666
1 changed files with 28 additions and 12 deletions

View File

@ -12,6 +12,19 @@ currently-running apps */
const APPROX_BACKLIGHT = process.HWVERSION == 2 ? 16 : 40;
const MAX = APPROX_IDLE + APPROX_HIGH_BW_BLE + APPROX_COMPASS + APPROX_HRM + APPROX_CPU + APPROX_GPS + APPROX_TOUCH + APPROX_BACKLIGHT;
let settings = require("Storage").readJSON("setting.json") || {};
let brightnessSetting = settings.brightness || 1;
Bangle.setLCDBrightness = ((o) => (a) => {
brightnessSetting = a;
draw();
return o(a);
})(Bangle.setLCDBrightness);
let brightness = () => {
return process.HWVERSION == 2 ? (brightnessSetting * APPROX_BACKLIGHT) : (brightnessSetting * 0.9 * 33 + 7);
};
function draw() {
g.reset();
g.clearRect(this.x, this.y, this.x + 24, this.y + 24);
@ -19,7 +32,7 @@ currently-running apps */
let current = APPROX_IDLE;
if (Bangle.isGPSOn()) current += APPROX_GPS;
if (Bangle.isHRMOn()) current += APPROX_HRM;
if (!Bangle.isLocked()) current += APPROX_TOUCH + APPROX_BACKLIGHT;
if (!Bangle.isLocked()) current += APPROX_TOUCH + brightness();
if (Bangle.isCompassOn()) current += APPROX_COMPASS;
current = current / MAX;
@ -49,4 +62,7 @@ currently-running apps */
width: 24,
draw: draw
};
})()
// conserve memory
delete settings;
})();