mclock: support 12h time
parent
7a46ac82c8
commit
187798da70
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue