Skip to content

Commit

Permalink
Fix timer app
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocastignoli committed Apr 1, 2020
1 parent edd1c0c commit ef391ce
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 77 deletions.
6 changes: 3 additions & 3 deletions apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -943,13 +943,13 @@
{ "id": "timer",
"name": "Timer",
"shortName":"Timer",
"icon": "app.png",
"icon": "timer.png",
"version":"0.01",
"description": "BTN1 => +5min, BTN2 => +30sec, BTN3 => +5sec, TOUCH => pause,play, BTN1(double click) => reset",
"tags": "Tools",
"storage": [
{"name":"timer.app.js","url":"app.js"},
{"name":"timer.img","url":"app-icon.js","evaluate":true}
{"name":"timer.app.js","url":"timer.js"},
{"name":"timer.img","url":"timer-icon.js","evaluate":true}
]
}
]
1 change: 0 additions & 1 deletion apps/timer/app-icon.js

This file was deleted.

73 changes: 0 additions & 73 deletions apps/timer/app.js

This file was deleted.

1 change: 1 addition & 0 deletions apps/timer/timer-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions apps/timer/timer.js
Original file line number Diff line number Diff line change
@@ -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();
Binary file added apps/timer/timer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ef391ce

Please sign in to comment.