2021-03-20 19:53:53 +00:00
|
|
|
(function() {
|
|
|
|
// 0: off, 1: buzz, 2: beep, 3: both
|
2021-03-24 10:53:24 +00:00
|
|
|
const type = (require("Storage").readJSON("widchime.json", 1) || {type: 1}).type;
|
|
|
|
if (!type) return;
|
2021-03-20 19:53:53 +00:00
|
|
|
|
|
|
|
function chime() {
|
2021-03-24 10:53:24 +00:00
|
|
|
if ((require("Storage").readJSON("setting.json", 1) || {}).quiet) return;
|
|
|
|
if (type&1) Bangle.buzz(100);
|
|
|
|
if (type&2) Bangle.beep();
|
2021-03-20 19:53:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 10:53:24 +00:00
|
|
|
let lastHour = (new Date()).getHours(); // don't chime when (re)loaded at a whole hour
|
2021-03-20 19:53:53 +00:00
|
|
|
function check() {
|
|
|
|
const now = new Date(),
|
|
|
|
h = now.getHours(), m = now.getMinutes(),
|
2021-03-24 10:53:24 +00:00
|
|
|
s = now.getSeconds(), ms = now.getMilliseconds();
|
|
|
|
if (h!==lastHour && m===0) chime();
|
|
|
|
lastHour = h;
|
2021-03-20 19:53:53 +00:00
|
|
|
// check again when this hour is over
|
2021-03-24 10:53:24 +00:00
|
|
|
const mLeft = 60-m, sLeft = (mLeft*60)-s, msLeft = (sLeft*1000)-ms;
|
|
|
|
setTimeout(check, msLeft);
|
2021-03-20 19:53:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 10:53:24 +00:00
|
|
|
check();
|
2021-03-20 19:53:53 +00:00
|
|
|
})
|
2021-03-24 10:53:24 +00:00
|
|
|
();
|