1
0
Fork 0

drained: fix not restoring when charge threshold met

previously the assumption was that the `"changing"` event would be fired
periodically when charging.

fixes #3625
master
Rob Pilling 2024-10-28 18:03:45 +00:00
parent 8acffd521d
commit 8742e11581
4 changed files with 10 additions and 17 deletions

View File

@ -5,3 +5,4 @@
0.04: Enhance menu: enable bluetooth, visit settings & visit recovery 0.04: Enhance menu: enable bluetooth, visit settings & visit recovery
0.05: Enhance menu: permit toggling bluetooth 0.05: Enhance menu: permit toggling bluetooth
0.06: Display clock in green when charging, with "charging" text 0.06: Display clock in green when charging, with "charging" text
0.07: Correctly restore full power when the charged threshold is reached

View File

@ -88,7 +88,7 @@ var reload = function () {
}; };
reload(); reload();
Bangle.emit("drained", E.getBattery()); Bangle.emit("drained", E.getBattery());
var _a = require("Storage").readJSON("".concat(app, ".setting.json"), true) || {}, _b = _a.keepStartup, keepStartup = _b === void 0 ? true : _b, _c = _a.restore, restore = _c === void 0 ? 20 : _c, _d = _a.exceptions, exceptions = _d === void 0 ? ["widdst.0"] : _d; var _a = require("Storage").readJSON("".concat(app, ".setting.json"), true) || {}, _b = _a.keepStartup, keepStartup = _b === void 0 ? true : _b, _c = _a.restore, restore = _c === void 0 ? 20 : _c, _d = _a.exceptions, exceptions = _d === void 0 ? ["widdst.0"] : _d, _e = _a.interval, interval = _e === void 0 ? 10 : _e;
function drainedRestore() { function drainedRestore() {
if (!keepStartup) { if (!keepStartup) {
try { try {
@ -101,18 +101,14 @@ function drainedRestore() {
load(); load();
} }
var checkCharge = function () { var checkCharge = function () {
if (E.getBattery() < restore) { if (!Bangle.isCharging() || E.getBattery() < restore) {
draw(); draw();
return; return;
} }
drainedRestore(); drainedRestore();
}; };
if (Bangle.isCharging())
checkCharge(); checkCharge();
Bangle.on("charging", function (charging) { drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
if (charging)
checkCharge();
});
if (!keepStartup) { if (!keepStartup) {
var storage = require("Storage"); var storage = require("Storage");
for (var _i = 0, exceptions_1 = exceptions; _i < exceptions_1.length; _i++) { for (var _i = 0, exceptions_1 = exceptions; _i < exceptions_1.length; _i++) {

View File

@ -115,7 +115,7 @@ reload();
Bangle.emit("drained", E.getBattery()); Bangle.emit("drained", E.getBattery());
// restore normal boot on charge // restore normal boot on charge
const { keepStartup = true, restore = 20, exceptions = ["widdst.0"] }: DrainedSettings const { keepStartup = true, restore = 20, exceptions = ["widdst.0"], interval = 10 }: DrainedSettings
= require("Storage").readJSON(`${app}.setting.json`, true) || {}; = require("Storage").readJSON(`${app}.setting.json`, true) || {};
// re-enable normal boot code when we're above a threshold: // re-enable normal boot code when we're above a threshold:
@ -131,19 +131,15 @@ function drainedRestore() { // "public", to allow users to call
} }
const checkCharge = () => { const checkCharge = () => {
if(E.getBattery() < restore) { if(!Bangle.isCharging() || E.getBattery() < restore) {
draw(); draw();
return; return;
} }
drainedRestore(); drainedRestore();
}; };
if (Bangle.isCharging())
checkCharge(); checkCharge();
drainedInterval = setInterval(checkCharge, interval * 60 * 1000);
Bangle.on("charging", charging => {
if(charging) checkCharge();
});
if(!keepStartup){ if(!keepStartup){
const storage = require("Storage"); const storage = require("Storage");

View File

@ -1,7 +1,7 @@
{ {
"id": "drained", "id": "drained",
"name": "Drained", "name": "Drained",
"version": "0.06", "version": "0.07",
"description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals", "description": "Switches to displaying a simple clock when the battery percentage is low, and disables some peripherals",
"readme": "README.md", "readme": "README.md",
"icon": "icon.png", "icon": "icon.png",