BangleApps/apps/slomoclock/app.js

87 lines
1.9 KiB
JavaScript
Raw 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
*/
2021-10-23 21:26:28 +00:00
var v='0.03';
2021-10-23 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
var Layout = require("Layout");
var layout = new Layout( {
type:"v", c: [
{type:undefined, height:40 }, // Widgets top
2021-10-23 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
{type:"h", c: [
{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 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
{type:undefined, height:40 }, // Widgets bottom
2021-10-23 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
]
2021-10-23 08:33:23 +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 09:52:09 +00:00
var t = parseFloat(timeStr);
2021-10-23 21:26:28 +00:00
var colTime;
2021-10-23 09:52:09 +00:00
if ( t < 24 ) colTime = 0x01BD;
if ( t < 19 ) colTime = 0x701F;
if ( t < 18 ) colTime = 0xEC80;
if ( t < 17 ) colTime = 0xF780;
if ( t < 12 ) colTime = 0xAEC2;
if ( t < 7 ) colTime = 0x1EC2;
2021-10-23 21:26:28 +00:00
if ( t < 6 ) colTime = 0x01BD;
2021-10-23 08:33:23 +00:00
2021-10-23 21:26:28 +00:00
layout.hour.label = timeStr.substring(0,2);
layout.min.label = timeStr.substring(3,5);
layout.hour.col = colTime;
layout.min.col = colTime;
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);
// 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();