From 379da3d6dbe133b30d2dc86c9e3827d1fe9d531d Mon Sep 17 00:00:00 2001 From: Stefan Kuehnel Date: Sun, 24 May 2020 18:22:44 +0200 Subject: [PATCH] Final changes for new release. --- apps.json | 9 ++------ apps/berlinc/ChangeLog | 2 +- apps/berlinc/README.md | 10 +++++++++ apps/berlinc/berlin-clock.js | 39 ++++++++++++++++++++++++++-------- apps/berlinc/berlin-clock.json | 3 --- apps/berlinc/settings.js | 39 ---------------------------------- 6 files changed, 43 insertions(+), 59 deletions(-) create mode 100644 apps/berlinc/README.md delete mode 100644 apps/berlinc/berlin-clock.json delete mode 100644 apps/berlinc/settings.js diff --git a/apps.json b/apps.json index 6d841e358..3e6efb4cf 100644 --- a/apps.json +++ b/apps.json @@ -887,19 +887,14 @@ { "id": "berlinc", "name": "Berlin Clock", "icon": "berlin-clock.png", - "version":"0.03.09", + "version":"0.03", "description": "Berlin Clock (see https://en.wikipedia.org/wiki/Mengenlehreuhr)", "tags": "clock", "type":"clock", "allow_emulator":true, - "data": [ - { "name":"berlinc.json","storageFile":true} - ], "storage": [ {"name":"berlinc.app.js","url":"berlin-clock.js"}, - {"name":"berlinc.img","url":"berlin-clock-icon.js","evaluate":true}, - {"name":"berlinc.settings.js","url":"settings.js"}, - {"name":"berlinc.json","url":"berlin-clock.json"} + {"name":"berlinc.img","url":"berlin-clock-icon.js","evaluate":true} ] }, { "id": "ctrclk", diff --git a/apps/berlinc/ChangeLog b/apps/berlinc/ChangeLog index f333911b4..a33332bc4 100644 --- a/apps/berlinc/ChangeLog +++ b/apps/berlinc/ChangeLog @@ -1,2 +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. +0.03: Shrinked size to avoid cut-off edges on the physical device. BTN3: show date. BTN1: show time in decimal. diff --git a/apps/berlinc/README.md b/apps/berlinc/README.md new file mode 100644 index 000000000..f21efdf29 --- /dev/null +++ b/apps/berlinc/README.md @@ -0,0 +1,10 @@ +# Berlin Clock Watch Face + +This is a clock-face analogous to the [Berlin Clock][https://en.wikipedia.org/wiki/Mengenlehreuhr]. + +## Usage + +* BTN1: toggle displaying the time in decimal figures (24 hour format) in the minutes fields. The first two fields are used for the hour and the last two fields for the minute. This might be a help when you're still familarizig yourself with this new way to express the time. +* BTN2: start the launcher +* BTN3: toggle displaying the current date (in ISO 8601 format) below the actual clock-face. + diff --git a/apps/berlinc/berlin-clock.js b/apps/berlinc/berlin-clock.js index 12e5ff49f..66b25adb5 100644 --- a/apps/berlinc/berlin-clock.js +++ b/apps/berlinc/berlin-clock.js @@ -1,20 +1,22 @@ // Berlin Clock see https://en.wikipedia.org/wiki/Mengenlehreuhr +// https://github.com/eska-muc/BangleApps 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 storage = require("Storage"); -const settingsfile = 'berlinc.json'; var show_date = false; +var show_time = false; rowlights = []; +time_digit = []; function drawBerlinClock() { g.clear(); var now = new Date(); + // show date below the clock if (show_date) { var yr = now.getFullYear(); var month = now.getMonth() + 1; @@ -22,7 +24,8 @@ function drawBerlinClock() { var dateString = `${yr}-${month < 10 ? '0' : ''}${month}-${day < 10 ? '0' : ''}${day}`; var strWidth = g.stringWidth(dateString); g.setColor(1, 1, 1); - g.drawString(dateString, ( g.getWidth() - strWidth ) / 2, height + offset + 2); + g.setFontAlign(-1,-1); + g.drawString(dateString, ( g.getWidth() - strWidth ) / 2, height + offset + 4); } rowlights[0] = Math.floor(now.getHours() / 5); @@ -30,6 +33,11 @@ function drawBerlinClock() { rowlights[2] = Math.floor(now.getMinutes() / 5); rowlights[3] = now.getMinutes() % 5; + time_digit[0] = Math.floor(now.getHours() / 10); + time_digit[1] = now.getHours() % 10; + time_digit[2] = Math.floor(now.getMinutes() / 10); + time_digit[3] = now.getMinutes() % 10; + g.drawRect(offset, offset, width + offset, height + offset); for (row = 0; row < 4; row++) { nfields = fields[row]; @@ -44,7 +52,6 @@ function drawBerlinClock() { g.setColor(1, 1, 1); g.drawRect(x1, y1, x2, y2); if (col < rowlights[row]) { - if (row === 2) { if (((col + 1) % 3) === 0) { g.setColor(1, 0, 0); @@ -54,16 +61,26 @@ function drawBerlinClock() { } else { g.setColor(1, 0, 0); } - g.fillRect(x1 + 2, y1 + 2, x2 - 2, y2 - 2); + g.fillRect(x1 + 2, y1 + 2, x2 - 2, y2 - 2); + } + if (row == 3 && show_time) { + g.setColor(1,1,1); + g.setFontAlign(0,0); + g.drawString(time_digit[col],(x1+x2)/2,(y1+y2)/2); } } } } -// try to read settings -const settings = storage.readJSON(settingsfile,1) || { - "showdate" : true -} +function toggleDate() { + show_date = ! show_date; + drawBerlinClock(); +} + +function toggleTime() { + show_time = ! show_time; + drawBerlinClock(); +} // special function to handle display switch on Bangle.on('lcdPower', (on) => { @@ -82,5 +99,9 @@ g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); drawBerlinClock(); +// Toggle date display, when BTN3 is pressed +setWatch(toggleTime,BTN1, { repeat : true, edge: "falling"}); +// Toggle date display, when BTN3 is pressed +setWatch(toggleDate,BTN3, { repeat : true, edge: "falling"}); // Show launcher when middle button pressed setWatch(Bangle.showLauncher, BTN2, { repeat: false, edge: "falling" }); diff --git a/apps/berlinc/berlin-clock.json b/apps/berlinc/berlin-clock.json deleted file mode 100644 index ef4493569..000000000 --- a/apps/berlinc/berlin-clock.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "showdate" : true -} \ No newline at end of file diff --git a/apps/berlinc/settings.js b/apps/berlinc/settings.js deleted file mode 100644 index 7fc0fa6a5..000000000 --- a/apps/berlinc/settings.js +++ /dev/null @@ -1,39 +0,0 @@ -(function(back) { - - const SETTINGS_FILE = 'berlinc.json' - - // initialize structure - let s = { - 'showdate' : true - } - - const storage = require('Storage') - const savedsettings = storage.readJSON(SETTINGS_FILE,1) || { - "showdate" : true - } - // read values from storage (if any) - for (const key in savedsettings) { - s[key]=savedsettings[key] - } - - function save (key) { - return function(value) { - s[key]=value; - storage.write(SETTINGS_FILE,s); - } - } - - const booleanFormat = b => ( b ? 'on':'off' ) - - const menu = { - '' : { 'title' : 'Berlin Clock Settings'} , - '< Back' : back, - 'Show Date' : { - value : s.showdate, - format: booleanFormat, - onChange: save('showdate') - } - } - digitalWrite(LED1,0); - E.showMenu(menu) -}) \ No newline at end of file