increase readability by adding some spaces

master
czeppi 2024-12-31 13:24:17 +01:00
parent 99854df4df
commit ed58557824
2 changed files with 90 additions and 69 deletions

View File

@ -1,94 +1,110 @@
{ {
const defaultSettings = { const defaultSettings = {
loadWidgets : false, loadWidgets : false,
textAboveHands : false, textAboveHands : false,
shortHrHand : false, shortHrHand : false,
show24HourMode : true show24HourMode : false
}; };
const settings = Object.assign(defaultSettings, require('Storage').readJSON('cc_clock24.json',1)||{});
const c={"x":g.getWidth()/2,"y":g.getHeight()/2}; const settings = Object.assign(defaultSettings, require('Storage').readJSON('cc_clock24.json', 1) || {});
const zahlpos=(function() { const c = {
let z=[]; "x": g.getWidth()/2,
let sk=1; "y": g.getHeight()/2
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), const zahlpos = (function() {
ysk =c.y+2+Math.sin(win)*(c.x-10); let z = [];
if(sk==3){xsk-=10;} let sk = 1;
if(sk==6){ysk-=10;} for (let i = -10; i < 50; i += 5){
if(sk==9){xsk+=10;} let win = i * 2 * Math.PI / 60;
if(sk==12){ysk+=10;} let xsk = c.x + 2 + Math.cos(win) * (c.x - 10),
if(sk==10){xsk+=3;} ysk = c.y + 2 + Math.sin(win) * (c.x - 10);
z.push([sk,xsk,ysk]); if (sk==3){ xsk -=10; }
sk+=1; if (sk==6){ ysk -=10; }
if (sk==9){ xsk +=10; }
if (sk==12){ ysk +=10; }
if (sk==10){ xsk +=3; }
z.push([sk, xsk, ysk]);
sk += 1;
} }
return z; return z;
})(); })();
const zeiger = function(len,dia,tim) { const 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 = {
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]; "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; return pol;
}; };
const drawHands = function(d) { const drawHands = function(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);
let numHoursForHourHand = settings.show24HourMode? 24 : 12; let numHoursForHourHand = settings.show24HourMode? 24 : 12;
if(h>numHoursForHourHand){ if(h > numHoursForHourHand){
h=h-numHoursForHourHand; h = h - numHoursForHourHand;
} }
//calculates the position of the minute, second and hour hand // calculates the position of the minute, second and hour hand
h=2*Math.PI/numHoursForHourHand*(h+m/60)-Math.PI/2; h = 2 * Math.PI / numHoursForHourHand * (h + m/60) - Math.PI/2;
//more accurate m = 2 * Math.PI / 60 * m - Math.PI/2;
//m=2*Math.PI/60*(m+s/60)-Math.PI/2; s = 2 * Math.PI / 60 * s - Math.PI/2;
m=2*Math.PI/60*(m)-Math.PI/2;
s=2*Math.PI/60*s-Math.PI/2;
//g.setColor(1,0,0); //g.setColor(1,0,0);
const hz = zeiger(settings.shortHrHand?88:100,5,h); const hz = zeiger(settings.shortHrHand? 88 : 100, 5, h);
g.fillPoly(hz,true); g.fillPoly(hz, true);
//g.setColor(1,1,1); //g.setColor(1, 1, 1);
const minz = zeiger(150,5,m); const minz = zeiger(150, 5, m);
g.fillPoly(minz,true); g.fillPoly(minz, true);
if (unlock){ if (unlock){
const sekz = zeiger(150,2,s); const sekz = zeiger(150, 2, s);
g.fillPoly(sekz,true); g.fillPoly(sekz, true);
} }
g.fillCircle(c.x,c.y,4); g.fillCircle(c.x, c.y, 4);
}; };
const drawText = function(d) { const 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);
const dateStr = require("locale").date(d); const dateStr = require("locale").date(d);
g.drawString(dateStr, c.x, c.y+20, true); g.drawString(dateStr, c.x, c.y + 20, true);
const batStr = Math.round(E.getBattery()/5)*5+"%"; const batStr = Math.round(E.getBattery()/5) * 5 + "%";
if (Bangle.isCharging()) { if (Bangle.isCharging()) {
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);
}; };
const drawNumbers = function() { const 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);
g.setBgColor(0,0,0); g.setBgColor(0, 0, 0);
for(let i = 0;i<12;i++){ for(let i = 0; i < 12; i++){
hour = zahlpos[i][0] hour = zahlpos[i][0]
if (settings.show24HourMode){ if (settings.show24HourMode){
hour *= 2; hour *= 2;
} }
g.drawString(hour,zahlpos[i][1],zahlpos[i][2],true); g.drawString(hour, zahlpos[i][1], zahlpos[i][2], true);
} }
}; };
@ -122,13 +138,13 @@ const queueDraw = function() {
const draw = function() { const 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);
// prepare for drawing the text // prepare for drawing the text
g.setFontAlign(0,0); g.setFontAlign(0, 0);
// do drawing // do drawing
drawNumbers(); drawNumbers();
const d=new Date(); const d = new Date();
if (settings.textAboveHands) { if (settings.textAboveHands) {
drawHands(d); drawText(d); drawHands(d); drawText(d);
} else { } else {
@ -140,17 +156,17 @@ const draw = function() {
//draws the scale once the app is startet //draws the scale once the app is startet
const drawScale = function() { const drawScale = function() {
// clear the screen // clear the screen
g.setBgColor(0,0,0); g.setBgColor(0, 0, 0);
g.clear(); g.clear();
// draw the ticks of the scale // draw the ticks of the scale
for(let i=-14;i<47;i++){ for (let i = -14; i < 47; i++){
const win=i*2*Math.PI/60; const win= i * 2 * Math.PI/60;
let d=2; let d = 2;
if(i%5==0){d=5;} if (i % 5==0){ d =5; }
g.fillPoly(zeiger(300,d,win),true); g.fillPoly(zeiger(300, d, win), true);
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);
g.setColor(1,1,1); g.setColor(1, 1, 1);
} }
}; };
@ -163,17 +179,21 @@ Bangle.setUI({
Bangle.removeListener('lcdPower', updateState); Bangle.removeListener('lcdPower', updateState);
Bangle.removeListener('lock', updateState); Bangle.removeListener('lock', updateState);
Bangle.removeListener('charging', draw); Bangle.removeListener('charging', draw);
// We clear drawTimout after removing all listeners, because they can add one again // We clear drawTimout after removing all listeners, because they can add one again
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined; drawTimeout = undefined;
require("widget_utils").show(); 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();
}
// Stop updates when LCD is off, restart when on // Stop updates when LCD is off, restart when on
Bangle.on('lcdPower', updateState); Bangle.on('lcdPower', updateState);
@ -183,4 +203,5 @@ Bangle.on('charging', draw); // Immediately redraw when charger (dis)connected
updateState(); updateState();
drawScale(); drawScale();
draw(); draw();
} }

View File

@ -3,9 +3,9 @@
loadWidgets : false, loadWidgets : false,
textAboveHands : false, textAboveHands : false,
shortHrHand : false, shortHrHand : false,
show24HourMode : true show24HourMode : false
} }
let settings = Object.assign(defaultSettings, require('Storage').readJSON('cc_clock24.json',1)||{}); let settings = Object.assign(defaultSettings, require('Storage').readJSON('cc_clock24.json',1) || {});
const save = () => require('Storage').write('cc_clock24.json', settings); const save = () => require('Storage').write('cc_clock24.json', settings);