diff --git a/apps.json b/apps.json index 0a41e7e91..42a3f0d2a 100644 --- a/apps.json +++ b/apps.json @@ -108,7 +108,7 @@ { "id": "mclock", "name": "Morphing Clock", "icon": "clock-morphing.png", - "version":"0.05", + "version":"0.06", "description": "7 segment clock that morphs between minutes and hours", "tags": "clock", "type":"clock", @@ -1720,5 +1720,17 @@ "data": [ {"name":"gallifr.json"} ] + }, + { "id": "rndmclk", + "name": "Random Clock Loader", + "icon": "rndmclk.png", + "version":"0.01", + "description": "Load a different clock whenever the LCD is switched on.", + "readme": "README.md", + "tags": "widget,clock", + "type":"widget", + "storage": [ + {"name":"rndmclk.wid.js","url":"widget.js"} + ] } ] diff --git a/apps/mclock/ChangeLog b/apps/mclock/ChangeLog index 98566f277..cca1b6e6b 100644 --- a/apps/mclock/ChangeLog +++ b/apps/mclock/ChangeLog @@ -3,3 +3,4 @@ 0.04: Improve performance, attempt to remove occasional glitch when LCD on (fix #279) 0.05: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast Fix issue where first digit could get stuck going from "2x:xx" to " x:xx" (fix #365) +0.06: Support 12 hour time diff --git a/apps/mclock/clock-morphing.js b/apps/mclock/clock-morphing.js index 8a2c62e28..32048cd60 100644 --- a/apps/mclock/clock-morphing.js +++ b/apps/mclock/clock-morphing.js @@ -1,3 +1,4 @@ +var is12Hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]; var locale = require("locale"); var CHARW = 34; // how tall are digits? var CHARP = 2; // how chunky are digits? @@ -146,7 +147,7 @@ function drawDigits(lastText,thisText,n) { x+=s+p+7; } } -function drawSeconds() { +function drawEverythingElse() { var x = (CHARW + CHARP + 6)*5; var y = Y + 2*CHARW + CHARP; var d = new Date(); @@ -154,6 +155,8 @@ function drawSeconds() { g.setFont("6x8"); g.setFontAlign(-1,-1); g.drawString(("0"+d.getSeconds()).substr(-2), x, y-8, true); + // meridian + if (is12Hour) g.drawString((d.getHours() < 12) ? "AM" : "PM", x, Y + 4, true); // date g.setFontAlign(0,-1); var date = locale.date(d,false); @@ -164,13 +167,15 @@ function drawSeconds() { function showTime() { if (animInterval) return; // in animation - quit var d = new Date(); - var t = (" "+d.getHours()).substr(-2)+":"+ + var hours = d.getHours(); + if (is12Hour) hours = ((hours + 11) % 12) + 1; + var t = (" "+hours).substr(-2)+":"+ ("0"+d.getMinutes()).substr(-2); var l = lastTime; // same - don't animate if (t==l || l=="-----") { drawDigits(l,t,0); - drawSeconds(); + drawEverythingElse(); lastTime = t; return; } diff --git a/apps/rndmclk/ChangeLog b/apps/rndmclk/ChangeLog new file mode 100644 index 000000000..55cda0f21 --- /dev/null +++ b/apps/rndmclk/ChangeLog @@ -0,0 +1 @@ +0.01: New widget diff --git a/apps/rndmclk/README.md b/apps/rndmclk/README.md new file mode 100644 index 000000000..3bfaf0e89 --- /dev/null +++ b/apps/rndmclk/README.md @@ -0,0 +1,6 @@ +# Summary + +Random Clock is a widget that will randomly show one of the installed watch faces each time the LCD is turned on. + +## Disclaimer +This is an early version and will load a clock each time the LCD is turned on no matter what app was running before the screen went to standby. Also the next watch face is only loaded after the last one is shown for a few tens of seconds. \ No newline at end of file diff --git a/apps/rndmclk/rndmclk.png b/apps/rndmclk/rndmclk.png new file mode 100644 index 000000000..9519b8d09 Binary files /dev/null and b/apps/rndmclk/rndmclk.png differ diff --git a/apps/rndmclk/widget.js b/apps/rndmclk/widget.js new file mode 100644 index 000000000..1c3b3d7bc --- /dev/null +++ b/apps/rndmclk/widget.js @@ -0,0 +1,29 @@ +(() => { + + /** + * Random value between zero (inclusive) and max (exclusive) + * @param {int} max + */ + function getRandomInt(max) { + return Math.floor(Math.random() * Math.floor(max)); + } + + function loadRandomClock() { + // Find available clock apps (same way as in the bootloader) + var clockApps = require("Storage").list(/\.info$/).map(app => require("Storage").readJSON(app, 1) || {}).filter(app => app.type == "clock").sort((a, b) => a.sortorder - b.sortorder); + + if (clockApps && clockApps.length > 0) { + var clockIndex = getRandomInt(clockApps.length); + + load(clockApps[clockIndex].src); + } + } + + Bangle.on('lcdPower', (on) => { + if (on) { + // TODO: Only run if the current app is a clock as well + loadRandomClock(); + } + }); + +})(); \ No newline at end of file