From c1e9600c1a0ff3d3079410b3afbae33c51fd8095 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Sat, 28 May 2022 08:50:12 +0200 Subject: [PATCH] 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. --- apps/widshipbell/metadata.json | 16 ++++++++++++ apps/widshipbell/settings.js | 26 ++++++++++++++++++++ apps/widshipbell/widget.js | 43 +++++++++++++++++++++++++++++++++ apps/widshipbell/widget.png | Bin 0 -> 1358 bytes 4 files changed, 85 insertions(+) create mode 100644 apps/widshipbell/metadata.json create mode 100644 apps/widshipbell/settings.js create mode 100644 apps/widshipbell/widget.js create mode 100644 apps/widshipbell/widget.png diff --git a/apps/widshipbell/metadata.json b/apps/widshipbell/metadata.json new file mode 100644 index 000000000..c130b04ee --- /dev/null +++ b/apps/widshipbell/metadata.json @@ -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"}] +} diff --git a/apps/widshipbell/settings.js b/apps/widshipbell/settings.js new file mode 100644 index 000000000..e14a84a90 --- /dev/null +++ b/apps/widshipbell/settings.js @@ -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(); + } + }, + }); +}) + diff --git a/apps/widshipbell/widget.js b/apps/widshipbell/widget.js new file mode 100644 index 000000000..7f0716201 --- /dev/null +++ b/apps/widshipbell/widget.js @@ -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(); + } +})(); diff --git a/apps/widshipbell/widget.png b/apps/widshipbell/widget.png new file mode 100644 index 0000000000000000000000000000000000000000..891679f7d6c79d2bebb4883546c51fa2284e9e3f GIT binary patch literal 1358 zcmV-U1+n^xP)V<(Q zdS^5SqJeOwBw!+3P}Ia2L)Ab;;++^sh<^bAfl`bjh>{SXUWcWqeEi$W zK=WF2xxiaMB-@k%T|IeKa$T;N+r~h1y}3}7ZGf$+I{-xF3Fl81Oj;S=K3H7I%@nD7 zLsJo%4^$zTAngQ49jCNv&zbE<*EsztOQyV$_!!{K+UR0MH`uCcfLmuk8zZ%-y$)n1 z0FenWaympNf)N2bq2nG2>7R!VlhU3of5)Zcp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