Merge pull request #177 from marcocastignoli/master

Timer app
pull/179/head
Gordon Williams 2020-04-01 14:50:48 +01:00 committed by GitHub
commit 6b775da0c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 0 deletions

View File

@ -939,5 +939,17 @@
"storage": [
{"name":"widtbat.wid.js","url":"widget.js"}
]
},
{ "id": "chrono",
"name": "Chrono",
"shortName":"Chrono",
"icon": "chrono.png",
"version":"0.01",
"description": "Single click BTN1 to add 5 minutes. Single click BTN2 to add 30 seconds. Single click BTN3 to add 5 seconds. Tap to pause or play to timer. Double click BTN1 to reset. When timer finishes the watch vibrates.",
"tags": "Tools",
"storage": [
{"name":"chrono.app.js","url":"chrono.js"},
{"name":"chrono.img","url":"chrono-icon.js","evaluate":true}
]
}
]

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwwglihGIxAWUwADBDCYTDhAXSFwQEGIxowBL4QXTx///AXWF6qnBwCTDO6EIF4KnEDwLWO/4QFx7FNdwQQEGwP4GBYUB/4QBDIYXMIgQAEDIIKCVwItJFggFEx4uKCAQUBX4QDC/B2KhASCAQP/AQQcDLpQlCLgQsCCoIGBC5IkCFon/xwxCDgIXJFwYxFHIR3ILwIkBCIeIFwQHBHgReIJAgCBOoP+MYZIHhB1EDgIRBA4ZIJC4LrEMYvoAgQXJxHvI4gtDC5OIF4QSDbYY3EC5QAKG4QXNPwg0BSBAJCIQhLCDwgXKIAwXUMo4XPFwrwKC4YOCUooVCR453DIxIXJU4IqDxwXJa45FDdgxnEC40IC4TbINQYXIRQZwDAAXv/xuBCwoXBVAgXDA4wXGSARcEC4o7BRwx4DOon+C4YiCLwxIDDAobDEYJGIGAYYBxDAD9AJDC5IwCDIYACJARGIDAapDaooWLDAZhEAoIWNMggADCqAAPA"))

73
apps/chrono/chrono.js Normal file
View File

@ -0,0 +1,73 @@
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds;
}
var counter = 0;
var started = false;
function drawInterface() {
g.clear();
g.setFontAlign(0, 0);
g.setFont("6x8", 2);
g.drawString("+5m", g.getWidth() - 30, 30);
g.drawString("+30s", g.getWidth() - 30, g.getHeight() / 2);
g.drawString("+5s", g.getWidth() - 30, g.getHeight() - 30);
g.setFontAlign(0, 0); // center font
g.setFont("6x8", 3);
// draw the current counter value
g.drawString(msToTime(counter * 1000), g.getWidth() / 2 - 30, g.getHeight() / 2);
// optional - this keeps the watch LCD lit up
g.flip();
}
function countDown() {
if (counter > 0) {
if (started) {
counter--;
drawInterface();
}
} else {
if (started) {
Bangle.buzz();
}
}
}
setWatch((p) => {
if (p.time - p.lastTime < 0.1) {
counter = 0;
started = false;
} else {
counter += 60 * 5;
}
drawInterface();
}, BTN1, { repeat: true });
setWatch(() => {
counter += 30;
drawInterface();
}, BTN2, { repeat: true });
setWatch(() => {
counter += 5;
drawInterface();
}, BTN3, { repeat: true });
Bangle.on('touch', function (button) {
started = !started;
});
var interval = setInterval(countDown, 1000);
drawInterface();

BIN
apps/chrono/chrono.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB