From b5fdb79b7f5aa42bf9969fcd6e6654e4440213ad Mon Sep 17 00:00:00 2001 From: Corwin Kerr Date: Sat, 23 Nov 2024 14:12:49 -0500 Subject: [PATCH 1/4] andark: queue draw to the exact second --- apps/andark/app.js | 57 +++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/apps/andark/app.js b/apps/andark/app.js index e6b5204f0..613265f2a 100644 --- a/apps/andark/app.js +++ b/apps/andark/app.js @@ -25,7 +25,6 @@ const zahlpos=(function() { return z; })(); -let unlock = false; function zeiger(len,dia,tim){ const x=c.x+ Math.cos(tim)*len/2, @@ -33,7 +32,6 @@ function zeiger(len,dia,tim){ 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]; return pol; - } function drawHands(d) { @@ -86,6 +84,17 @@ function drawNumbers() { } } +let drawTimeout; +let queueMillis = 1000; + +let queueDraw = function() { + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = setTimeout(function() { + drawTimeout = undefined; + draw(); + }, queueMillis - (Date.now() % queueMillis)); +}; + function draw(){ // draw black rectangle in the middle to clear screen from scale and hands g.setColor(0,0,0); @@ -100,6 +109,7 @@ function draw(){ } else { drawText(d); drawHands(d); } + queueDraw(); } //draws the scale once the app is startet @@ -128,25 +138,30 @@ if (settings.loadWidgets) { Bangle.loadWidgets(); require("widget_utils").swipeOn(); } 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 -Bangle.on('lcdPower',on=>{ - if (secondInterval) clearInterval(secondInterval); - secondInterval = undefined; - if (on) { - secondInterval = setInterval(draw, 1000); - draw(); // draw immediately - } -}); -Bangle.on('lock',on=>{ - unlock = !on; - if (secondInterval) clearInterval(secondInterval); - secondInterval = setInterval(draw, unlock ? 1000 : 60000); - draw(); // draw immediately -}); -Bangle.on('charging',on=>{draw();}); +Bangle.on('lcdPower', updateState); + +Bangle.on('lock', updateState); + +let unlock = true; +updateState(); +drawScale(); +draw(); From 3bbb156468da380bf1c3ed085be7beb976bb1fb3 Mon Sep 17 00:00:00 2001 From: Corwin Kerr Date: Sat, 23 Nov 2024 14:39:57 -0500 Subject: [PATCH 2/4] andark: enable fast loading --- apps/andark/app.js | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/andark/app.js b/apps/andark/app.js index 613265f2a..b607e3698 100644 --- a/apps/andark/app.js +++ b/apps/andark/app.js @@ -1,3 +1,4 @@ +{ const defaultSettings = { loadWidgets : false, textAboveHands : false, @@ -26,15 +27,15 @@ const zahlpos=(function() { })(); -function zeiger(len,dia,tim){ +let zeiger = function(len,dia,tim){ const x=c.x+ Math.cos(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)}, 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; -} +}; -function drawHands(d) { +let drawHands = function(d) { let m=d.getMinutes(), h=d.getHours(), s=d.getSeconds(); g.setColor(1,1,1); @@ -59,9 +60,9 @@ function drawHands(d) { g.fillPoly(sekz,true); } g.fillCircle(c.x,c.y,4); -} +}; -function drawText(d) { +let drawText = function(d) { g.setFont("Vector",10); g.setBgColor(0,0,0); g.setColor(1,1,1); @@ -72,9 +73,9 @@ function drawText(d) { g.setBgColor(1,0,0); } g.drawString(batStr, c.x, c.y+40, true); -} +}; -function drawNumbers() { +let drawNumbers = function() { //draws the numbers on the screen g.setFont("Vector",20); g.setColor(1,1,1); @@ -82,7 +83,7 @@ function drawNumbers() { for(let i = 0;i<12;i++){ g.drawString(zahlpos[i][0],zahlpos[i][1],zahlpos[i][2],true); } -} +}; let drawTimeout; let queueMillis = 1000; @@ -95,7 +96,7 @@ let queueDraw = function() { }, queueMillis - (Date.now() % queueMillis)); }; -function draw(){ +let draw = function(){ // draw black rectangle in the middle to clear screen from scale and hands g.setColor(0,0,0); g.fillRect(10,10,2*c.x-10,2*c.x-10); @@ -110,10 +111,10 @@ function draw(){ drawText(d); drawHands(d); } queueDraw(); -} +}; //draws the scale once the app is startet -function drawScale(){ +let drawScale = function(){ // clear the screen g.setBgColor(0,0,0); g.clear(); @@ -127,19 +128,26 @@ function drawScale(){ g.fillRect(10,10,2*c.x-10,2*c.x-10); g.setColor(1,1,1); } -} +}; //// main running sequence //// // 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 if (settings.loadWidgets) { Bangle.loadWidgets(); require("widget_utils").swipeOn(); } else if (global.WIDGETS) require("widget_utils").hide(); - let updateState = function() { if (Bangle.isLCDOn()) { if (!Bangle.isLocked()) { @@ -165,3 +173,4 @@ let unlock = true; updateState(); drawScale(); draw(); +} From 177e624a71dd3dcc68194cd9dc4c5309e22d0fab Mon Sep 17 00:00:00 2001 From: Corwin Kerr Date: Fri, 29 Nov 2024 16:14:29 -0500 Subject: [PATCH 3/4] andark: update version and changelog --- apps/andark/ChangeLog | 2 ++ apps/andark/metadata.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/andark/ChangeLog b/apps/andark/ChangeLog index 7d7f9567b..22cc21e33 100644 --- a/apps/andark/ChangeLog +++ b/apps/andark/ChangeLog @@ -5,3 +5,5 @@ 0.05: Fix support for dark theme + support widgets + 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.07: Enable fast loading + Queue updates to the second diff --git a/apps/andark/metadata.json b/apps/andark/metadata.json index fc8872f4b..19e3c95dc 100644 --- a/apps/andark/metadata.json +++ b/apps/andark/metadata.json @@ -1,7 +1,7 @@ { "id": "andark", "name": "Analog Dark", "shortName":"AnDark", - "version":"0.06", + "version":"0.07", "description": "analog clock face without disturbing widgets", "icon": "andark_icon.png", "type": "clock", From aea8ff9001517736a4ec703428452a8919668be6 Mon Sep 17 00:00:00 2001 From: Corwin Kerr Date: Fri, 29 Nov 2024 16:53:14 -0500 Subject: [PATCH 4/4] andark: move changelog to one line --- apps/andark/ChangeLog | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/andark/ChangeLog b/apps/andark/ChangeLog index 22cc21e33..0dd44154e 100644 --- a/apps/andark/ChangeLog +++ b/apps/andark/ChangeLog @@ -5,5 +5,4 @@ 0.05: Fix support for dark theme + support widgets + 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.07: Enable fast loading - Queue updates to the second +0.07: Enable fast loading and queue updates to the second