[entonclk] Add timer function

pull/2425/head
Simon Weis 2022-12-25 20:03:14 +01:00
parent 1f1b8a20d5
commit 5fe225dc0b
4 changed files with 121 additions and 50 deletions

View File

@ -1 +1,2 @@
0.1: New App!
0.2: Now with timer function

View File

@ -7,3 +7,15 @@ Things I changed:
- The main font for the time is now Audiowide
- Removed the written out day name and replaced it with steps and bpm
- Changed the date string to a (for me) more readable string
Timer function:
- Touch the right side, to start the timer
- Initial timer timeout is 300s/5min
- Right touch again, add 300s/5min to timeout
- Left touch, decrease timeout by 60s/1min
- So it is easy, to add timeouts like 7min/3min or 12min
- Special thanks to the maintainer of the a_clock_timer app from which I borrowed the code.
Todo:
- Make displayed information configurable, after https://github.com/espruino/BangleApps/issues/2226
- Clean up code

View File

@ -65,3 +65,61 @@ Bangle.loadWidgets();
draw();
setTimeout(Bangle.drawWidgets,0);
}
// Timer function
var timervalue = 0;
var istimeron = false;
var timertick;
Bangle.on('touch',t => {
if (t == 1) {
// Touch on the left, reduce timervalue about 60s
Bangle.buzz(30);
if (timervalue < 60) { timervalue = 1 ; }
else { timervalue -= 60; }
}
// Touch on the right, raise timervaule about 300s
else if (t == 2) {
Bangle.buzz(30);
if (!istimeron) {
istimeron = true;
timertick = setInterval(countDown, 1000);
}
timervalue += 60*5;
}
});
function timeToString(duration) {
var hrs = ~~(duration / 3600);
var mins = ~~((duration % 3600) / 60);
var secs = ~~duration % 60;
var ret = "";
if (hrs > 0) {
ret += "" + hrs + ":" + (mins < 10 ? "0" : "");
}
ret += "" + mins + ":" + (secs < 10 ? "0" : "");
ret += "" + secs;
return ret;
}
function countDown() {
timervalue--;
g.reset().clearRect(0, 40, 44+99, g.getHeight()/2-25);
g.setFontAlign(0, -1, 0);
g.setFont("6x8", 2).drawString(timeToString(timervalue), 95, g.getHeight()/2-50);
if (timervalue <= 0) {
istimeron = false;
clearInterval(timertick);
Bangle.buzz().then(()=>{
return new Promise(resolve=>setTimeout(resolve, 500));
}).then(()=>{
return Bangle.buzz(1000);
});
}
else
if ((timervalue <= 30) && (timervalue % 10 == 0)) { Bangle.buzz(); }
}

View File

@ -1,8 +1,8 @@
{
"id": "entonclk",
"name": "Enton Clock",
"version": "0.1",
"description": "A simple clock using the Audiowide font. ",
"version": "0.2",
"description": "A simple clock using the Audiowide font with timer. ",
"icon": "app.png",
"screenshots": [{"url":"screenshot.png"}],
"type": "clock",