Merge pull request #3678 from cbkerr/andark-fastload-queue

andark: queue redraws and enable fastload
pull/3682/head^2
Rob Pilling 2024-12-03 12:17:57 +00:00 committed by GitHub
commit b01901c8b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 35 deletions

View File

@ -5,3 +5,4 @@
0.05: Fix support for dark theme + support widgets + 0.05: Fix support for dark theme + support widgets +
add settings for widgets, order of drawing and hour hand length add settings for widgets, order of drawing and hour hand length
0.06: Fix issue showing widgets when app is fast-loaded into from launcher with widgets disabled 0.06: Fix issue showing widgets when app is fast-loaded into from launcher with widgets disabled
0.07: Enable fast loading and queue updates to the second

View File

@ -1,3 +1,4 @@
{
const defaultSettings = { const defaultSettings = {
loadWidgets : false, loadWidgets : false,
textAboveHands : false, textAboveHands : false,
@ -25,18 +26,16 @@ const zahlpos=(function() {
return z; return z;
})(); })();
let unlock = false;
function zeiger(len,dia,tim){ let zeiger = function(len,dia,tim){
const x=c.x+ Math.cos(tim)*len/2, const x=c.x+ Math.cos(tim)*len/2,
y=c.y + Math.sin(tim)*len/2, y=c.y + Math.sin(tim)*len/2,
d={"d":3,"x":dia/2*Math.cos(tim+Math.PI/2),"y":dia/2*Math.sin(tim+Math.PI/2)}, d={"d":3,"x":dia/2*Math.cos(tim+Math.PI/2),"y":dia/2*Math.sin(tim+Math.PI/2)},
pol=[c.x-d.x,c.y-d.y,c.x+d.x,c.y+d.y,x+d.x,y+d.y,x-d.x,y-d.y]; pol=[c.x-d.x,c.y-d.y,c.x+d.x,c.y+d.y,x+d.x,y+d.y,x-d.x,y-d.y];
return pol; return pol;
};
} let drawHands = function(d) {
function drawHands(d) {
let m=d.getMinutes(), h=d.getHours(), s=d.getSeconds(); let m=d.getMinutes(), h=d.getHours(), s=d.getSeconds();
g.setColor(1,1,1); g.setColor(1,1,1);
@ -61,9 +60,9 @@ function drawHands(d) {
g.fillPoly(sekz,true); g.fillPoly(sekz,true);
} }
g.fillCircle(c.x,c.y,4); g.fillCircle(c.x,c.y,4);
} };
function drawText(d) { let drawText = function(d) {
g.setFont("Vector",10); g.setFont("Vector",10);
g.setBgColor(0,0,0); g.setBgColor(0,0,0);
g.setColor(1,1,1); g.setColor(1,1,1);
@ -74,9 +73,9 @@ function drawText(d) {
g.setBgColor(1,0,0); g.setBgColor(1,0,0);
} }
g.drawString(batStr, c.x, c.y+40, true); g.drawString(batStr, c.x, c.y+40, true);
} };
function drawNumbers() { let drawNumbers = function() {
//draws the numbers on the screen //draws the numbers on the screen
g.setFont("Vector",20); g.setFont("Vector",20);
g.setColor(1,1,1); g.setColor(1,1,1);
@ -84,9 +83,20 @@ function drawNumbers() {
for(let i = 0;i<12;i++){ for(let i = 0;i<12;i++){
g.drawString(zahlpos[i][0],zahlpos[i][1],zahlpos[i][2],true); g.drawString(zahlpos[i][0],zahlpos[i][1],zahlpos[i][2],true);
} }
} };
function draw(){ let drawTimeout;
let queueMillis = 1000;
let queueDraw = function() {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = setTimeout(function() {
drawTimeout = undefined;
draw();
}, queueMillis - (Date.now() % queueMillis));
};
let draw = function(){
// draw black rectangle in the middle to clear screen from scale and hands // draw black rectangle in the middle to clear screen from scale and hands
g.setColor(0,0,0); g.setColor(0,0,0);
g.fillRect(10,10,2*c.x-10,2*c.x-10); g.fillRect(10,10,2*c.x-10,2*c.x-10);
@ -100,10 +110,11 @@ function draw(){
} else { } else {
drawText(d); drawHands(d); drawText(d); drawHands(d);
} }
} queueDraw();
};
//draws the scale once the app is startet //draws the scale once the app is startet
function drawScale(){ let drawScale = function(){
// clear the screen // clear the screen
g.setBgColor(0,0,0); g.setBgColor(0,0,0);
g.clear(); g.clear();
@ -117,36 +128,49 @@ function drawScale(){
g.fillRect(10,10,2*c.x-10,2*c.x-10); g.fillRect(10,10,2*c.x-10,2*c.x-10);
g.setColor(1,1,1); g.setColor(1,1,1);
} }
} };
//// main running sequence //// //// main running sequence ////
// Show launcher when middle button pressed, and widgets that we're clock // Show launcher when middle button pressed, and widgets that we're clock
Bangle.setUI("clock"); Bangle.setUI({
mode: "clock",
remove: function() {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
Bangle.removeListener('lcdPower', updateState);
Bangle.removeListener('lock', updateState);
require("widget_utils").show();
}});
// Load widgets if needed, and make them show swipeable // Load widgets if needed, and make them show swipeable
if (settings.loadWidgets) { if (settings.loadWidgets) {
Bangle.loadWidgets(); Bangle.loadWidgets();
require("widget_utils").swipeOn(); require("widget_utils").swipeOn();
} else if (global.WIDGETS) require("widget_utils").hide(); } else if (global.WIDGETS) require("widget_utils").hide();
// Clear the screen once, at startup
drawScale();
draw();
let secondInterval = setInterval(draw, 1000); let updateState = function() {
if (Bangle.isLCDOn()) {
if (!Bangle.isLocked()) {
queueMillis = 1000;
unlock = true;
} else {
queueMillis = 60000;
unlock = false;
}
draw();
} else {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
}
};
// Stop updates when LCD is off, restart when on // Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{ Bangle.on('lcdPower', updateState);
if (secondInterval) clearInterval(secondInterval);
secondInterval = undefined; Bangle.on('lock', updateState);
if (on) {
secondInterval = setInterval(draw, 1000); let unlock = true;
draw(); // draw immediately updateState();
} drawScale();
}); draw();
Bangle.on('lock',on=>{ }
unlock = !on;
if (secondInterval) clearInterval(secondInterval);
secondInterval = setInterval(draw, unlock ? 1000 : 60000);
draw(); // draw immediately
});
Bangle.on('charging',on=>{draw();});

View File

@ -1,7 +1,7 @@
{ "id": "andark", { "id": "andark",
"name": "Analog Dark", "name": "Analog Dark",
"shortName":"AnDark", "shortName":"AnDark",
"version":"0.06", "version":"0.07",
"description": "analog clock face without disturbing widgets", "description": "analog clock face without disturbing widgets",
"icon": "andark_icon.png", "icon": "andark_icon.png",
"type": "clock", "type": "clock",