Merge branch 'master' of github.com:espruino/BangleApps

pull/422/head
Gordon Williams 2020-05-13 11:25:22 +01:00
commit cb8fbd55a1
7 changed files with 58 additions and 4 deletions

View File

@ -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"}
]
}
]

View File

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

View File

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

1
apps/rndmclk/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New widget

6
apps/rndmclk/README.md Normal file
View File

@ -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.

BIN
apps/rndmclk/rndmclk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

29
apps/rndmclk/widget.js Normal file
View File

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