forked from FOSS/BangleApps
Added settings. Changed size to better fit the screen of the physical device. Added date display.
parent
d4463e4379
commit
64a7a8f147
|
@ -887,14 +887,19 @@
|
|||
{ "id": "berlinc",
|
||||
"name": "Berlin Clock",
|
||||
"icon": "berlin-clock.png",
|
||||
"version":"0.02",
|
||||
"version":"0.03",
|
||||
"description": "Berlin Clock (see https://en.wikipedia.org/wiki/Mengenlehreuhr)",
|
||||
"tags": "clock",
|
||||
"type":"clock",
|
||||
"allow_emulator":true,
|
||||
"data": [
|
||||
{"name":"berlin-clock.json"}
|
||||
],
|
||||
"storage": [
|
||||
{"name":"berlinc.app.js","url":"berlin-clock.js"},
|
||||
{"name":"berlinc.img","url":"berlin-clock-icon.js","evaluate":true}
|
||||
{"name":"berlinc.img","url":"berlin-clock-icon.js","evaluate":true},
|
||||
{"name":"berlinc.settings.js","url":"settings.js"},
|
||||
|
||||
]
|
||||
},
|
||||
{ "id": "ctrclk",
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
0.02: Modified for use with new bootloader and firmware
|
||||
0.03: Shrinked size to avoid cut off edges on the physical device. Added date and settings.
|
||||
|
|
|
@ -1,29 +1,42 @@
|
|||
// place your const, vars, functions or classes here
|
||||
fields = [ 4 , 4 , 11 , 4 ];
|
||||
width = g.getWidth();
|
||||
height = g.getHeight();
|
||||
rowHeight = height/4;
|
||||
// Berlin Clock see https://en.wikipedia.org/wiki/Mengenlehreuhr
|
||||
const fields = [ 4 , 4 , 11 , 4 ];
|
||||
const offset = 20;
|
||||
const width = g.getWidth() - 2*offset;
|
||||
const height = g.getHeight() - 2*offset;
|
||||
const rowHeight = height/4;
|
||||
|
||||
//const settings = require("Storage").readJSON("berlin-clock.json", 1);
|
||||
const show_date = true; // settings.show_date || true;
|
||||
|
||||
rowlights = [];
|
||||
|
||||
function drawBerlinClock() {
|
||||
g.clear();
|
||||
|
||||
var now = new Date();
|
||||
if (show_date) {
|
||||
var yr = now.getFullYear();
|
||||
var month = now.getMonth()+1;
|
||||
var day = now.getDate();
|
||||
var dateString=`${yr}-${month<10?'0':''}${month}-${day<10?'0':''}${day}`;
|
||||
var strWidth = g.stringWidth(dateString);
|
||||
g.drawString(dateString,(g.getWidth()-strWidth)/2,height+offset+2);
|
||||
}
|
||||
rowlights[0] = Math.floor(now.getHours() / 5);
|
||||
rowlights[1] = now.getHours() % 5;
|
||||
rowlights[2] = Math.floor(now.getMinutes() / 5);
|
||||
rowlights[3] = now.getMinutes() % 5;
|
||||
|
||||
g.clear();
|
||||
|
||||
g.drawRect(0,0,width,height);
|
||||
|
||||
g.drawRect(offset,offset,width+offset,height+offset);
|
||||
for (row = 0 ; row < 4 ; row++) {
|
||||
nfields = fields[row];
|
||||
boxWidth = width/nfields;
|
||||
|
||||
for (col = 0 ; col < nfields ; col++) {
|
||||
x1 = col*boxWidth;
|
||||
y1 = row*rowHeight;
|
||||
x2 = (col+1)*boxWidth;
|
||||
y2 = (row+1)*rowHeight;
|
||||
x1 = col*boxWidth + offset ;
|
||||
y1 = row*rowHeight + offset;
|
||||
x2 = (col+1)*boxWidth + offset;
|
||||
y2 = (row+1)*rowHeight + offset;
|
||||
|
||||
g.setColor(1,1,1);
|
||||
g.drawRect(x1,y1,x2,y2);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"show_date" : false
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
(function(back) {
|
||||
let settings = require('Storage').readJSON('berlin-clock.json',1)||{};
|
||||
function save(key, value) {
|
||||
settings[key] = value;
|
||||
require('Storage').write('berlin-clock.json',settings);
|
||||
}
|
||||
const appMenu = {
|
||||
'': {'title': 'Berlin Clock Settings'},
|
||||
'< Back': back,
|
||||
'Show Date': {
|
||||
value: settings.show_date||false,
|
||||
onchange: (m) => {save('show_date', m)}
|
||||
}
|
||||
};
|
||||
E.showMenu(appMenu)
|
||||
})
|
Loading…
Reference in New Issue