mirror of https://github.com/espruino/BangleApps
Merge pull request #3678 from cbkerr/andark-fastload-queue
andark: queue redraws and enable fastloadpull/3682/head^2
commit
b01901c8b7
|
@ -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
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
const defaultSettings = {
|
||||
loadWidgets : false,
|
||||
textAboveHands : false,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -74,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);
|
||||
|
@ -84,9 +83,20 @@ function drawNumbers() {
|
|||
for(let i = 0;i<12;i++){
|
||||
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
|
||||
g.setColor(0,0,0);
|
||||
g.fillRect(10,10,2*c.x-10,2*c.x-10);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue