1
0
Fork 0

Merge pull request #1896 from nxdefiant/master

Added widshipbell
master
Gordon Williams 2022-06-06 12:11:57 +01:00 committed by GitHub
commit bd08b00d13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 95 additions and 0 deletions

View File

@ -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"}]
}

View File

@ -0,0 +1,27 @@
(function(back) {
var FILE = "widshipbell.json";
// Load settings
var settings = Object.assign({
strength: 1,
}, require('Storage').readJSON(FILE, true) || {});
function writeSettings() {
require('Storage').writeJSON(FILE, settings);
}
// Show the menu
E.showMenu({
"" : { "title" : "Ship's bell" },
"< Back" : () => back(),
'Strength': {
value: settings.strength,
min: 0, max: 2,
format: v => ["Off", "Weak", "Strong"][v],
onchange: v => {
settings.strength = v;
writeSettings();
}
},
});
})

View File

@ -0,0 +1,52 @@
(() => {
const strength = Object.assign({
strength: 1,
}, require('Storage').readJSON("widshipbell.json", true) || {}).strength;
function replaceAll(target, search, replacement) {
return target.split(search).join(replacement);
}
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 = '.. .. .. .';
}
pattern = replaceAll(pattern, ' ', ' '); // 4x pause
pattern = replaceAll(pattern, '.', '. '); // pause between bells
if (strength === 2) { // strong selected
pattern = replaceAll(pattern, '.', ':');
}
require("buzz").pattern(pattern);
}
const etaSecond = etaMinute*60-currentSecond;
setTimeout(check, etaSecond*1000);
}
if (strength !== 0) {
check();
}
})();

BIN
apps/widshipbell/widget.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB