1
0
Fork 0

Added settings. Changed size to better fit the screen of the physical device. Added date display.

master
Stefan Kuehnel 2020-05-23 18:42:52 +02:00
parent d4463e4379
commit 64a7a8f147
5 changed files with 53 additions and 15 deletions

View File

@ -887,14 +887,19 @@
{ "id": "berlinc", { "id": "berlinc",
"name": "Berlin Clock", "name": "Berlin Clock",
"icon": "berlin-clock.png", "icon": "berlin-clock.png",
"version":"0.02", "version":"0.03",
"description": "Berlin Clock (see https://en.wikipedia.org/wiki/Mengenlehreuhr)", "description": "Berlin Clock (see https://en.wikipedia.org/wiki/Mengenlehreuhr)",
"tags": "clock", "tags": "clock",
"type":"clock", "type":"clock",
"allow_emulator":true, "allow_emulator":true,
"data": [
{"name":"berlin-clock.json"}
],
"storage": [ "storage": [
{"name":"berlinc.app.js","url":"berlin-clock.js"}, {"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", { "id": "ctrclk",

View File

@ -1 +1,2 @@
0.02: Modified for use with new bootloader and firmware 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.

View File

@ -1,29 +1,42 @@
// place your const, vars, functions or classes here // Berlin Clock see https://en.wikipedia.org/wiki/Mengenlehreuhr
fields = [ 4 , 4 , 11 , 4 ]; const fields = [ 4 , 4 , 11 , 4 ];
width = g.getWidth(); const offset = 20;
height = g.getHeight(); const width = g.getWidth() - 2*offset;
rowHeight = height/4; 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 = []; rowlights = [];
function drawBerlinClock() { function drawBerlinClock() {
g.clear();
var now = new Date(); 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[0] = Math.floor(now.getHours() / 5);
rowlights[1] = now.getHours() % 5; rowlights[1] = now.getHours() % 5;
rowlights[2] = Math.floor(now.getMinutes() / 5); rowlights[2] = Math.floor(now.getMinutes() / 5);
rowlights[3] = now.getMinutes() % 5; rowlights[3] = now.getMinutes() % 5;
g.clear(); g.drawRect(offset,offset,width+offset,height+offset);
g.drawRect(0,0,width,height);
for (row = 0 ; row < 4 ; row++) { for (row = 0 ; row < 4 ; row++) {
nfields = fields[row]; nfields = fields[row];
boxWidth = width/nfields; boxWidth = width/nfields;
for (col = 0 ; col < nfields ; col++) { for (col = 0 ; col < nfields ; col++) {
x1 = col*boxWidth; x1 = col*boxWidth + offset ;
y1 = row*rowHeight; y1 = row*rowHeight + offset;
x2 = (col+1)*boxWidth; x2 = (col+1)*boxWidth + offset;
y2 = (row+1)*rowHeight; y2 = (row+1)*rowHeight + offset;
g.setColor(1,1,1); g.setColor(1,1,1);
g.drawRect(x1,y1,x2,y2); g.drawRect(x1,y1,x2,y2);

View File

@ -0,0 +1,3 @@
{
"show_date" : false
}

16
apps/berlinc/settings.js Normal file
View File

@ -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)
})