drained: make it clear when charging, via the clock

pull/3538/head
Rob Pilling 2024-08-16 12:15:23 +01:00
parent 84aabfade4
commit 32e3cc705d
4 changed files with 24 additions and 7 deletions

View File

@ -4,3 +4,4 @@
Also avoid polluting global scope. Also avoid polluting global scope.
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

View File

@ -37,14 +37,19 @@ var draw = function () {
require("locale").dow(date, 0).toUpperCase(); require("locale").dow(date, 0).toUpperCase();
var x2 = x + 6; var x2 = x + 6;
var y2 = y + 66; var y2 = y + 66;
var charging = Bangle.isCharging();
g.reset() g.reset()
.clearRect(Bangle.appRect) .clearRect(Bangle.appRect)
.setFont("Vector", 55) .setFont("Vector", 55)
.setFontAlign(0, 0) .setFontAlign(0, 0)
.setColor(charging ? "#0f0" : g.theme.fg)
.drawString(timeStr, x, y) .drawString(timeStr, x, y)
.setFont("Vector", 24) .setFont("Vector", 24)
.drawString(dateStr, x2, y2) .drawString(dateStr, x2, y2);
.drawString("".concat(E.getBattery(), "%"), x2, y2 + 48); if (charging)
g.drawString("charging: ".concat(E.getBattery(), "%"), x2, y2 + 48);
else
g.drawString("".concat(E.getBattery(), "%"), x2, y2 + 48);
if (nextDraw) if (nextDraw)
clearTimeout(nextDraw); clearTimeout(nextDraw);
nextDraw = setTimeout(function () { nextDraw = setTimeout(function () {
@ -96,8 +101,10 @@ function drainedRestore() {
load(); load();
} }
var checkCharge = function () { var checkCharge = function () {
if (E.getBattery() < restore) if (E.getBattery() < restore) {
draw();
return; return;
}
drainedRestore(); drainedRestore();
}; };
if (Bangle.isCharging()) if (Bangle.isCharging())

View File

@ -54,15 +54,21 @@ const draw = () => {
require("locale").dow(date, 0).toUpperCase(); require("locale").dow(date, 0).toUpperCase();
const x2 = x + 6; const x2 = x + 6;
const y2 = y + 66; const y2 = y + 66;
const charging = Bangle.isCharging();
g.reset() g.reset()
.clearRect(Bangle.appRect) .clearRect(Bangle.appRect)
.setFont("Vector", 55) .setFont("Vector", 55)
.setFontAlign(0, 0) .setFontAlign(0, 0)
.setColor(charging ? "#0f0" : g.theme.fg)
.drawString(timeStr, x, y) .drawString(timeStr, x, y)
.setFont("Vector", 24) .setFont("Vector", 24)
.drawString(dateStr, x2, y2) .drawString(dateStr, x2, y2);
.drawString(`${E.getBattery()}%`, x2, y2 + 48);
if(charging)
g.drawString(`charging: ${E.getBattery()}%`, x2, y2 + 48);
else
g.drawString(`${E.getBattery()}%`, x2, y2 + 48);
if(nextDraw) clearTimeout(nextDraw); if(nextDraw) clearTimeout(nextDraw);
nextDraw = setTimeout(() => { nextDraw = setTimeout(() => {
@ -125,7 +131,10 @@ function drainedRestore() { // "public", to allow users to call
} }
const checkCharge = () => { const checkCharge = () => {
if(E.getBattery() < restore) return; if(E.getBattery() < restore) {
draw();
return;
}
drainedRestore(); drainedRestore();
}; };

View File

@ -1,7 +1,7 @@
{ {
"id": "drained", "id": "drained",
"name": "Drained", "name": "Drained",
"version": "0.05", "version": "0.06",
"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",