diff --git a/apps/thunder/ChangeLog b/apps/thunder/ChangeLog new file mode 100644 index 000000000..5560f00bc --- /dev/null +++ b/apps/thunder/ChangeLog @@ -0,0 +1 @@ +0.01: New App! diff --git a/apps/thunder/README.md b/apps/thunder/README.md new file mode 100644 index 000000000..86607107e --- /dev/null +++ b/apps/thunder/README.md @@ -0,0 +1,20 @@ +# Come on Thunder + +Simple timer to calculate how far away lightning is. + +A tribute to [Flash Boom](https://archive.org/details/tucows_33513_Flash_Boom), the greatest app of all time! + +![](screenshot.png) + +## Usage + +Use the "Flash" button when you see the flash of lightning, and press the "Boom" button when you hear the rumble of thunder! + +## Creator + +James Taylor ([jt-nti](https://github.com/jt-nti)) + +## Icons + +- [Cloud Lightning](https://icons8.com/icon/41144/cloud-lightning) +- [Lightning](https://icons8.com/icon/60998/lightning-bolt") diff --git a/apps/thunder/app-icon.js b/apps/thunder/app-icon.js new file mode 100644 index 000000000..7a95e1390 --- /dev/null +++ b/apps/thunder/app-icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEwgn/AH4AO/uEkETxoWR/1QN4deC6HBgN89/suMB54WO/gqFsEcC53hg4GE/ECC51Qr4HFsF/RhsB94IF+MPC5n4IwoAB+8HscRk2vC5Hzhh/IAAUC34XH+UOBI8Dzv/7MwHo//+BWIYAf6gB9F/tziBuN4ELTgpSBI5AAE/TGE+kBvv/NJAAFmAPDsEtchwAByFvaYffC6HQl7KDKo5mBx6fHj7TChokHgEIW5AXC+KjHkAuII4gXH+ouJO4hHHwAuJU4h3G/YuKa4inG8IuK4ELAodwa4kwUoMAz6qCLIX5gF/CIf0gN8AgP2CwUKVQUGBQPZmDRGuASBp4FB2EB56qCt/0BgMCOoQAD/tziAXCkEdVQQuBHoMmCwwAF+0C96qCLoQAO4E+//8LoYAPmiqDFyP4r6qFUIgAK66qFhIvPUYJjDgGvMCLzDjYWU/EB74XU6EuCyn/oYWV/NPC6vnCyqqFAH4A//4A==")) diff --git a/apps/thunder/app.js b/apps/thunder/app.js new file mode 100644 index 000000000..d180bb720 --- /dev/null +++ b/apps/thunder/app.js @@ -0,0 +1,110 @@ +Bangle.loadWidgets(); +g.clear(true); +Bangle.drawWidgets(); + +Bangle.setLCDTimeout(undefined); + +let renderIntervalId; +let startTime; + +const DEFAULTS = { + units: 0, +}; + +const settings = require("Storage").readJSON("thunder.json", 1) || DEFAULTS; + +var Layout = require("Layout"); +var layout = new Layout( { + type:"v", c: [ + {type:"txt", font:"6x8:2", label:"", id:"time", fillx:1}, + {type:"txt", pad:8, font:"20%", label:"", id:"distance", fillx:1}, + {type:"h", c: [ + {type:"btn", font:"6x8:2", label:"Flash", cb: l=>flash() }, + {type:"img", pad:4, src:require("heatshrink").decompress(atob("h0awkBiMQBAQFBAxwdDAoIGKCYQGGFBQTCAyIAPgIGGIAoFCAxITDAxIFDAxATEJwIMEAw4TEAwo")) }, + {type:"btn", font:"6x8:2", label:"Boom", cb: l=>boom() } + ]}, + ] +}, { + lazy: true, + back: load, +}); + +const getTime = function(milliseconds) { + let hrs = Math.floor(milliseconds/3600000); + let mins = Math.floor(milliseconds/60000)%60; + let secs = Math.floor(milliseconds/1000)%60; + let tnth = Math.floor(milliseconds/100)%10; + let text; + + if (hrs === 0) { + text = ("0"+mins).slice(-2) + ":" + ("0"+secs).slice(-2) + "." + tnth; + } else { + text = ("0"+hrs) + ":" + ("0"+mins).slice(-2) + ":" + ("0"+secs).slice(-2); + } + + return text; +}; + +// Convert milliseconds to distance based on one km in 2.91 s or +// one mile in 4.69 s +// See https://en.wikipedia.org/wiki/Speed_of_sound +const getDistance = function(milliseconds) { + let secs = milliseconds/1000; + let distance; + + if (settings.units === 0) { + let kms = Math.round((secs / 2.91) * 10) / 10; + distance = kms.toFixed(1) + "km"; + } else { + let miles = Math.round((secs / 4.69) * 10) / 10; + distance = miles.toFixed(1) + "mi"; + } + + return distance; +}; + +const renderIntervalCallback = function() { + if (startTime === undefined) { + return; + } + + updateTimeAndDistance(); +}; + +const flash = function() { + Bangle.buzz(50, 0.5); + + startTime = startTime = Date.now(); + updateTimeAndDistance(); + renderIntervalId = setInterval(renderIntervalCallback, 100); +}; + +const boom = function() { + Bangle.buzz(50, 0.5); + + if (renderIntervalId !== undefined) { + clearInterval(renderIntervalId); + renderIntervalId = undefined; + } + + updateTimeAndDistance(); + startTime = undefined; +}; + +const updateTimeAndDistance = function() { + let t; + + if (startTime === undefined) { + t = 0; + } else { + t = Date.now() - startTime; + } + + layout.time.label = getTime(t); + layout.distance.label = getDistance(t); + + layout.render(); + // layout.debug(); +}; + +updateTimeAndDistance(); diff --git a/apps/thunder/app.png b/apps/thunder/app.png new file mode 100644 index 000000000..5767e9275 Binary files /dev/null and b/apps/thunder/app.png differ diff --git a/apps/thunder/metadata.json b/apps/thunder/metadata.json new file mode 100644 index 000000000..46696095e --- /dev/null +++ b/apps/thunder/metadata.json @@ -0,0 +1,17 @@ +{ "id": "thunder", + "name": "Come on Thunder", + "shortName":"Thunder", + "version":"0.01", + "description": "Simple timer to calculate how far away lightning is", + "icon": "app.png", + "tags": "tool,weather", + "supports" : ["BANGLEJS2"], + "readme": "README.md", + "allow_emulator": true, + "storage": [ + {"name":"thunder.app.js","url":"app.js"}, + {"name":"thunder.settings.js","url":"settings.js"}, + {"name":"thunder.img","url":"app-icon.js","evaluate":true} + ], + "data": [{"name":"thunder.json"}] +} diff --git a/apps/thunder/screenshot.png b/apps/thunder/screenshot.png new file mode 100644 index 000000000..3fc369976 Binary files /dev/null and b/apps/thunder/screenshot.png differ diff --git a/apps/thunder/settings.js b/apps/thunder/settings.js new file mode 100644 index 000000000..bbbf43c54 --- /dev/null +++ b/apps/thunder/settings.js @@ -0,0 +1,40 @@ +(function (back) { + const FILE = "thunder.json"; + const DEFAULTS = { + units: 0, + }; + + let settings = {}; + + const loadSettings = function() { + settings = require('Storage').readJSON(FILE, 1) || DEFAULTS; + }; + + const saveSettings = function() { + require('Storage').writeJSON(FILE, settings); + }; + + const showMenu = function() { + const unitOptions = ['kms','miles']; + + const menu = { + '': {'title': 'Thunder'}, + '< Back': back, + 'Units': { + value: 0|settings.units, + min: 0, + max: unitOptions.length-1, + format: v => unitOptions[v], + onchange: v => { + settings.units = 0 | v; + saveSettings(settings); + } + }, + }; + + E.showMenu(menu); + }; + + loadSettings(); + showMenu(); +});