Merge pull request #3337 from jt-nti/come-on-thunder

Add new thunder app
pull/3341/head
Martin Boonk 2024-04-07 22:12:08 +02:00 committed by GitHub
commit aff05dc4e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 189 additions and 0 deletions

1
apps/thunder/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: New App!

20
apps/thunder/README.md Normal file
View File

@ -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")

1
apps/thunder/app-icon.js Normal file
View File

@ -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=="))

110
apps/thunder/app.js Normal file
View File

@ -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();

BIN
apps/thunder/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

View File

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

BIN
apps/thunder/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

40
apps/thunder/settings.js Normal file
View File

@ -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();
});