barclock: add powerSave option, perform second updates in "ram"

pull/2047/head
Richard de Boer 2022-06-26 00:03:29 +02:00
parent fed49792de
commit 91e80cc3b2
No known key found for this signature in database
GPG Key ID: 8721727971871937
5 changed files with 30 additions and 11 deletions

View File

@ -12,3 +12,4 @@
0.12: Add settings to hide date,widgets 0.12: Add settings to hide date,widgets
0.13: Add font setting 0.13: Add font setting
0.14: Use ClockFace_menu.addItems 0.14: Use ClockFace_menu.addItems
0.15: Add Power saving option

View File

@ -7,4 +7,5 @@ A simple digital clock showing seconds as a horizontal bar.
## Settings ## Settings
* `Show date`: display date at the bottom of screen * `Show date`: display date at the bottom of screen
* `Font`: choose between bitmap or vector fonts * `Font`: choose between bitmap or vector fonts
* `Power saving`: (Bangle.js 2 only) don't draw the seconds bar while the watch is locked

View File

@ -14,12 +14,10 @@ let locale = require("locale");
} }
function renderBar(l) { function renderBar(l) {
if (!this.fraction) { "ram";
// zero-size fillRect stills draws one line of pixels, we don't want that if (!this.fraction) return; // zero-size fillRect stills draws one line of pixels, we don't want that
return; if (this.powerSave && Bangle.isLocked()) return;
} g.fillRect(l.x, l.y, l.x+this.fraction*l.w-1, l.y+l.height-1);
const width = this.fraction*l.w;
g.fillRect(l.x, l.y, l.x+width-1, l.y+l.height-1);
} }
@ -91,6 +89,7 @@ const ClockFace = require("ClockFace"),
this.layout.update(); this.layout.update();
}, },
update: function(date, c) { update: function(date, c) {
"ram";
if (c.m) this.layout.time.label = timeText(date); if (c.m) this.layout.time.label = timeText(date);
if (c.h) this.layout.ampm.label = ampmText(date); if (c.h) this.layout.ampm.label = ampmText(date);
if (c.d && this.showDate) this.layout.date.label = dateText(date); if (c.d && this.showDate) this.layout.date.label = dateText(date);
@ -102,4 +101,18 @@ const ClockFace = require("ClockFace"),
this.layout.forgetLazyState(); this.layout.forgetLazyState();
}, },
}); });
if (clock.powerSave) {
Bangle.on("lock", l => {
if (l) {
clock.precision = 60;
clock.tick();
const l = clock.layout.bar;
setTimeout(() => g.clearRect(l.x, l.y, l.x+l.w-1, l.y+l.height-1), 100);
} else {
clock.precision = 1;
clock.tick();
}
});
}
clock.start(); clock.start();

View File

@ -1,7 +1,7 @@
{ {
"id": "barclock", "id": "barclock",
"name": "Bar Clock", "name": "Bar Clock",
"version": "0.14", "version": "0.15",
"description": "A simple digital clock showing seconds as a bar", "description": "A simple digital clock showing seconds as a bar",
"icon": "clock-bar.png", "icon": "clock-bar.png",
"screenshots": [{"url":"screenshot.png"},{"url":"screenshot_pm.png"}], "screenshots": [{"url":"screenshot.png"},{"url":"screenshot_pm.png"}],

View File

@ -17,10 +17,14 @@
onchange: v => save("font", v), onchange: v => save("font", v),
}, },
}; };
require("ClockFace_menu").addItems(menu, save, { let items = {
showDate: s.showDate, showDate: s.showDate,
loadWidgets: s.loadWidgets, loadWidgets: s.loadWidgets,
}); };
// Power saving for Bangle.js 1 doesn't make sense (no updates while screen is off anyway)
if (process.env.HWVERSION>1) {
items.powerSave = s.powerSave;
}
require("ClockFace_menu").addItems(menu, save, items);
E.showMenu(menu); E.showMenu(menu);
}); });