Skip to content

Commit

Permalink
Merge pull request #3678 from cbkerr/andark-fastload-queue
Browse files Browse the repository at this point in the history
andark: queue redraws and enable fastload
  • Loading branch information
bobrippling authored Dec 3, 2024
2 parents 22078e8 + aea8ff9 commit b01901c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 35 deletions.
1 change: 1 addition & 0 deletions apps/andark/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +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 and queue updates to the second
92 changes: 58 additions & 34 deletions apps/andark/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
const defaultSettings = {
loadWidgets : false,
textAboveHands : false,
Expand Down Expand Up @@ -25,18 +26,16 @@ const zahlpos=(function() {
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,
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);

Expand All @@ -61,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);
Expand All @@ -74,19 +73,30 @@ 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);
g.setBgColor(0,0,0);
for(let i = 0;i<12;i++){
g.drawString(zahlpos[i][0],zahlpos[i][1],zahlpos[i][2],true);
}
}
};

let drawTimeout;
let queueMillis = 1000;

function draw(){
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
g.setColor(0,0,0);
g.fillRect(10,10,2*c.x-10,2*c.x-10);
Expand All @@ -100,10 +110,11 @@ function draw(){
} else {
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();
Expand All @@ -117,36 +128,49 @@ 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();
// 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();
}
2 changes: 1 addition & 1 deletion apps/andark/metadata.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit b01901c

Please sign in to comment.