BangleApps/apps/slomoclock/app.js

119 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2021-10-23 08:33:23 +00:00
/*
2021-10-23 08:55:48 +00:00
Simple watch [slomoclock]
2021-10-23 08:33:23 +00:00
Mike Bennett mike[at]kereru.com
0.01 : Initial
2021-10-23 21:26:28 +00:00
0.03 : Use Layout library
2021-10-23 08:33:23 +00:00
*/
2024-03-04 20:34:50 +00:00
//var v='0.10';
2021-10-23 23:59:42 +00:00
// Colours
const col = [];
2021-10-25 04:06:26 +00:00
col[2] = 0xF800;
col[3] = 0xFAE0;
col[4] = 0xF7E0;
col[5] = 0x4FE0;
col[6] = 0x019F;
col[7] = 0x681F;
col[8] = 0xFFFF;
2021-10-24 20:09:21 +00:00
const colH = [];
colH[0]= 0x001F;
colH[1]= 0x023F;
colH[2]= 0x039F;
colH[3]= 0x051F;
colH[4]= 0x067F;
colH[5]= 0x07FD;
colH[6]= 0x07F6;
colH[7]= 0x07EF;
colH[8]= 0x07E8;
colH[9]= 0x07E3;
colH[10]= 0x07E0;
colH[11]= 0x5FE0;
colH[12]= 0x97E0;
colH[13]= 0xCFE0;
colH[14]= 0xFFE0;
colH[15]= 0xFE60;
colH[16]= 0xFC60;
colH[17]= 0xFAA0;
colH[18]= 0xF920;
colH[19]= 0xF803;
colH[20]= 0xF80E;
colH[21]= 0x981F;
colH[22]= 0x681F;
colH[23]= 0x301F;
2021-10-23 23:29:58 +00:00
2021-10-25 04:06:26 +00:00
// Colour incremented with every 10 sec timer event
var colNum = 0;
2021-10-25 04:25:43 +00:00
var lastMin = -1;
2021-10-25 04:06:26 +00:00
2021-10-23 21:26:28 +00:00
var Layout = require("Layout");
var layout = new Layout( {
2021-10-23 23:59:42 +00:00
type:"h", c: [
2021-10-23 21:26:28 +00:00
{type:"v", c: [
{type:"txt", font:"40%", label:"", id:"hour", valign:1},
{type:"txt", font:"40%", label:"", id:"min", valign:-1},
]},
{type:"v", c: [
{type:"txt", font:"10%", label:"", id:"day", col:0xEFE0, halign:1},
{type:"txt", font:"10%", label:"", id:"mon", col:0xEFE0, halign:1},
]}
2021-10-23 23:59:42 +00:00
]
2021-10-23 21:26:28 +00:00
}, {lazy:true});
2021-10-23 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
// update the screen
function draw() {
2021-10-23 08:33:23 +00:00
var date = new Date();
2021-10-23 21:26:28 +00:00
// Update time
2021-10-23 08:33:23 +00:00
var timeStr = require("locale").time(date,1);
2021-10-23 23:59:42 +00:00
var hh = parseFloat(timeStr.substring(0,2));
2021-10-25 04:25:43 +00:00
var mm = parseFloat(timeStr.substring(3,5));
// Surprise colours
if ( lastMin != mm ) colNum = Math.floor(Math.random() * 24);
lastMin = mm;
2021-10-23 09:52:09 +00:00
2021-10-23 21:26:28 +00:00
layout.hour.label = timeStr.substring(0,2);
layout.min.label = timeStr.substring(3,5);
2021-10-25 04:06:26 +00:00
// Mysterion (0) different colour each hour. Surprise (1) different colour every 10 secs.
2021-10-25 04:45:31 +00:00
layout.hour.col = cfg.colour==0 ? colH[hh] : cfg.colour==1 ? colH[colNum] : col[cfg.colour];
layout.min.col = cfg.colour==0 ? colH[hh] : cfg.colour==1 ? colH[colNum] :col[cfg.colour];
2021-10-23 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
// Update date
layout.day.label = date.getDate();
layout.mon.label = require("locale").month(date,1);
layout.render();
2021-10-23 08:33:23 +00:00
}
2021-10-23 21:26:28 +00:00
// Events
2021-10-23 08:33:23 +00:00
// Stop updates when LCD is off, restart when on
Bangle.on('lcdPower',on=>{
2021-10-23 21:26:28 +00:00
if (secondInterval) clearInterval(secondInterval);
secondInterval = undefined;
2021-10-23 08:33:23 +00:00
if (on) {
2021-10-23 21:26:28 +00:00
secondInterval = setInterval(draw, 10000);
draw(); // draw immediately
2021-10-23 08:33:23 +00:00
}
});
2021-10-23 21:26:28 +00:00
var secondInterval = setInterval(draw, 10000);
2021-10-24 20:09:21 +00:00
// Configuration
let cfg = require('Storage').readJSON('slomoclock.json',1)||{};
cfg.colour = cfg.colour||0; // Colours
2021-10-23 21:26:28 +00:00
// update time and draw
g.clear();
draw();
2021-10-23 08:33:23 +00:00
// Show launcher when middle button pressed
Bangle.setUI("clock");
// Load widgets
Bangle.loadWidgets();
Bangle.drawWidgets();