2023-02-19 20:48:35 +00:00
|
|
|
/* run widgets in their own function scope so they don't interfere with
|
|
|
|
currently-running apps */
|
|
|
|
(() => {
|
2023-02-20 18:14:02 +00:00
|
|
|
const GU = require("graphics_utils");
|
2023-02-19 20:48:35 +00:00
|
|
|
const APPROX_IDLE = 0.3;
|
|
|
|
const APPROX_HIGH_BW_BLE = 0.5;
|
|
|
|
const APPROX_COMPASS = process.HWVERSION == 2 ? 5.5 : 2;
|
|
|
|
const APPROX_HRM = process.HWVERSION == 2 ? 1 : 2.5;
|
|
|
|
const APPROX_CPU = 3;
|
|
|
|
const APPROX_GPS = process.HWVERSION == 2 ? 25 : 30;
|
|
|
|
const APPROX_TOUCH = 2.5;
|
|
|
|
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;
|
|
|
|
|
2023-02-20 18:39:31 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2023-02-19 20:48:35 +00:00
|
|
|
function draw() {
|
2023-02-20 18:14:02 +00:00
|
|
|
g.reset();
|
2023-02-20 18:39:31 +00:00
|
|
|
g.clearRect(this.x, this.y, this.x + 24, this.y + 24);
|
2023-02-19 20:48:35 +00:00
|
|
|
|
|
|
|
let current = APPROX_IDLE;
|
|
|
|
if (Bangle.isGPSOn()) current += APPROX_GPS;
|
|
|
|
if (Bangle.isHRMOn()) current += APPROX_HRM;
|
2023-02-20 18:39:31 +00:00
|
|
|
if (!Bangle.isLocked()) current += APPROX_TOUCH + brightness();
|
2023-02-19 20:48:35 +00:00
|
|
|
if (Bangle.isCompassOn()) current += APPROX_COMPASS;
|
2023-02-20 18:14:02 +00:00
|
|
|
|
2023-02-20 18:39:31 +00:00
|
|
|
current = current / MAX;
|
|
|
|
|
2023-02-19 20:48:35 +00:00
|
|
|
g.setColor(g.theme.fg);
|
2023-02-20 18:14:02 +00:00
|
|
|
|
2023-02-19 20:48:35 +00:00
|
|
|
g.setFont6x15();
|
2023-02-20 18:39:31 +00:00
|
|
|
g.setFontAlign(0, 0);
|
|
|
|
g.drawString("P", this.x + 12, this.y + 15);
|
2023-02-20 18:14:02 +00:00
|
|
|
|
2023-02-20 18:39:31 +00:00
|
|
|
let end = 135 + (current * (405 - 135));
|
2023-02-20 18:14:02 +00:00
|
|
|
g.setColor(current > 0.7 ? "#f00" : (current > 0.3 ? "#ff0" : "#0f0"));
|
|
|
|
GU.fillArc(g, this.x + 12, this.y + 12, 8, 12, GU.degreesToRadians(135), GU.degreesToRadians(end));
|
2023-02-19 20:48:35 +00:00
|
|
|
|
|
|
|
if (this.timeoutId !== undefined) {
|
|
|
|
clearTimeout(this.timeoutId);
|
|
|
|
}
|
2023-02-20 18:39:31 +00:00
|
|
|
this.timeoutId = setTimeout(() => {
|
2023-02-19 20:48:35 +00:00
|
|
|
this.timeoutId = undefined;
|
|
|
|
this.draw();
|
2023-02-20 18:14:02 +00:00
|
|
|
}, Bangle.isLocked() ? 60000 : 5000);
|
2023-02-19 20:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// add your widget
|
2023-02-20 18:39:31 +00:00
|
|
|
WIDGETS.powermanager = {
|
|
|
|
area: "tl",
|
2023-02-20 18:14:02 +00:00
|
|
|
width: 24,
|
2023-02-20 18:39:31 +00:00
|
|
|
draw: draw
|
2023-02-19 20:48:35 +00:00
|
|
|
};
|
2023-02-20 18:39:31 +00:00
|
|
|
|
|
|
|
// conserve memory
|
|
|
|
delete settings;
|
|
|
|
})();
|