Added widshipbell
A widget that buzzes according to a nautical bell, one strike at 04:30, two strikes at 05:00, up to eight strikes at 08:00 and so on.master
parent
ac5c80ff38
commit
c1e9600c1a
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"id": "widshipbell",
|
||||||
|
"name": "Ship's bell Widget",
|
||||||
|
"shortName": "Ship's bell",
|
||||||
|
"version": "0.01",
|
||||||
|
"description": "A widget that buzzes according to a nautical bell, one strike at 04:30, two strikes at 05:00, up to eight strikes at 08:00 and so on.",
|
||||||
|
"icon": "widget.png",
|
||||||
|
"type": "widget",
|
||||||
|
"tags": "widget",
|
||||||
|
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||||
|
"storage": [
|
||||||
|
{"name":"widshipbell.wid.js","url":"widget.js"},
|
||||||
|
{"name":"widshipbell.settings.js","url":"settings.js"}
|
||||||
|
],
|
||||||
|
"data": [{"name":"widshipbell.json"}]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
(function(back) {
|
||||||
|
var FILE = "widshipbell.json";
|
||||||
|
// Load settings
|
||||||
|
var settings = Object.assign({
|
||||||
|
enabled: true,
|
||||||
|
}, require('Storage').readJSON(FILE, true) || {});
|
||||||
|
|
||||||
|
function writeSettings() {
|
||||||
|
require('Storage').writeJSON(FILE, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the menu
|
||||||
|
E.showMenu({
|
||||||
|
"" : { "title" : "Ship's bell" },
|
||||||
|
"< Back" : () => back(),
|
||||||
|
'Enable?': {
|
||||||
|
value: !!settings.enabled, // !! converts undefined to false
|
||||||
|
format: v => v?"Yes":"No",
|
||||||
|
onchange: v => {
|
||||||
|
settings.enabled = v;
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
(() => {
|
||||||
|
var settings = Object.assign({
|
||||||
|
enabled: true,
|
||||||
|
}, require('Storage').readJSON("widshipbell.json", true) || {});
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
const now = new Date();
|
||||||
|
const currentMinute = now.getMinutes();
|
||||||
|
const currentSecond = now.getSeconds();
|
||||||
|
const etaMinute = 30-(currentMinute % 30);
|
||||||
|
|
||||||
|
if (etaMinute === 30 && currentSecond === 0) {
|
||||||
|
const strikeHour = now.getHours() % 4;
|
||||||
|
// buzz now
|
||||||
|
let pattern='';
|
||||||
|
if (strikeHour === 0 && currentMinute == 0) {
|
||||||
|
pattern = '.. .. .. ..';
|
||||||
|
} else if (strikeHour === 0 && currentMinute == 30) {
|
||||||
|
pattern = '.';
|
||||||
|
} else if (strikeHour === 1 && currentMinute == 0) {
|
||||||
|
pattern = '..';
|
||||||
|
} else if (strikeHour === 1 && currentMinute == 30) {
|
||||||
|
pattern = '.. .';
|
||||||
|
} else if (strikeHour === 2 && currentMinute == 0) {
|
||||||
|
pattern = '.. ..';
|
||||||
|
} else if (strikeHour === 2 && currentMinute == 30) {
|
||||||
|
pattern = '.. .. .';
|
||||||
|
} else if (strikeHour === 3 && currentMinute == 0) {
|
||||||
|
pattern = '.. .. ..';
|
||||||
|
} else if (strikeHour === 3 && currentMinute == 30) {
|
||||||
|
pattern = '.. .. .. .';
|
||||||
|
}
|
||||||
|
require("buzz").pattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
const etaSecond = etaMinute*60-currentSecond;
|
||||||
|
setTimeout(check, etaSecond*1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.enabled === true) {
|
||||||
|
check();
|
||||||
|
}
|
||||||
|
})();
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue