Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

andark: Restore redraw on charging and small fixups #3692

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/andark/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
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
0.08: Restore redraw on charging event + fixup for safer fast-loading
72 changes: 37 additions & 35 deletions apps/andark/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const zahlpos=(function() {
let z=[];
let sk=1;
for(let i=-10;i<50;i+=5){
let win=i*2*Math.PI/60;
let xsk =c.x+2+Math.cos(win)*(c.x-10),
ysk =c.y+2+Math.sin(win)*(c.x-10);
let win=i*2*Math.PI/60;
let xsk =c.x+2+Math.cos(win)*(c.x-10),
ysk =c.y+2+Math.sin(win)*(c.x-10);
if(sk==3){xsk-=10;}
if(sk==6){ysk-=10;}
if(sk==9){xsk+=10;}
Expand All @@ -26,16 +26,15 @@ const zahlpos=(function() {
return z;
})();


let zeiger = function(len,dia,tim){
const 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;
};

let drawHands = function(d) {
const drawHands = function(d) {
let m=d.getMinutes(), h=d.getHours(), s=d.getSeconds();
g.setColor(1,1,1);

Expand All @@ -62,41 +61,58 @@ let drawHands = function(d) {
g.fillCircle(c.x,c.y,4);
};

let drawText = function(d) {
const drawText = function(d) {
g.setFont("Vector",10);
g.setBgColor(0,0,0);
g.setColor(1,1,1);
let dateStr = require("locale").date(d);
const dateStr = require("locale").date(d);
g.drawString(dateStr, c.x, c.y+20, true);
let batStr = Math.round(E.getBattery()/5)*5+"%";
const batStr = Math.round(E.getBattery()/5)*5+"%";
if (Bangle.isCharging()) {
g.setBgColor(1,0,0);
}
g.drawString(batStr, c.x, c.y+40, true);
};

let drawNumbers = function() {
const 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);
g.drawString(zahlpos[i][0],zahlpos[i][1],zahlpos[i][2],true);
}
};

let drawTimeout;
let queueMillis = 1000;
let unlock = true;

const 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;
}
};

let queueDraw = function() {
const queueDraw = function() {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = setTimeout(function() {
drawTimeout = undefined;
draw();
}, queueMillis - (Date.now() % queueMillis));
};

let draw = function(){
const 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 @@ -114,7 +130,7 @@ let draw = function(){
};

//draws the scale once the app is startet
let drawScale = function(){
const drawScale = function() {
// clear the screen
g.setBgColor(0,0,0);
g.clear();
Expand All @@ -136,40 +152,26 @@ let drawScale = function(){
Bangle.setUI({
mode: "clock",
remove: function() {
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
Bangle.removeListener('lcdPower', updateState);
Bangle.removeListener('lock', updateState);
Bangle.removeListener('charging', draw);
// We clear drawTimout after removing all listeners, because they can add one again
if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined;
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()) {
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', updateState);

Bangle.on('lock', updateState);
Bangle.on('charging', draw); // Immediately redraw when charger (dis)connected

let unlock = true;
updateState();
drawScale();
draw();
Expand Down
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.07",
"version":"0.08",
"description": "analog clock face without disturbing widgets",
"icon": "andark_icon.png",
"type": "clock",
Expand Down
Loading