From a89545e02a89871591955cd4dfcc479884d45ff7 Mon Sep 17 00:00:00 2001 From: hughbarney Date: Wed, 20 Oct 2021 18:35:03 +0100 Subject: [PATCH] Stopwatch: touch based stopwatch for Bangle 2 --- apps.json | 13 ++ apps/stopwatch/ChangeLog | 1 + apps/stopwatch/README.md | 20 +++ apps/stopwatch/pause-24.png | Bin 0 -> 161 bytes apps/stopwatch/pause-24a.png | Bin 0 -> 123 bytes apps/stopwatch/play-24.png | Bin 0 -> 297 bytes apps/stopwatch/stop-24.png | Bin 0 -> 177 bytes apps/stopwatch/stop-24a.png | Bin 0 -> 192 bytes apps/stopwatch/stopwatch.app.js | 222 +++++++++++++++++++++++++++++++ apps/stopwatch/stopwatch.icon.js | 1 + apps/stopwatch/stopwatch.png | Bin 0 -> 1566 bytes 11 files changed, 257 insertions(+) create mode 100644 apps/stopwatch/ChangeLog create mode 100644 apps/stopwatch/README.md create mode 100644 apps/stopwatch/pause-24.png create mode 100644 apps/stopwatch/pause-24a.png create mode 100644 apps/stopwatch/play-24.png create mode 100644 apps/stopwatch/stop-24.png create mode 100644 apps/stopwatch/stop-24a.png create mode 100644 apps/stopwatch/stopwatch.app.js create mode 100644 apps/stopwatch/stopwatch.icon.js create mode 100644 apps/stopwatch/stopwatch.png diff --git a/apps.json b/apps.json index 269e9577e..84e95330c 100644 --- a/apps.json +++ b/apps.json @@ -3612,5 +3612,18 @@ {"name":"ffcniftya.app.js","url":"app.js"}, {"name":"ffcniftya.img","url":"app-icon.js","evaluate":true} ] +}, +{ "id": "stopwatch", + "name": "Stopwatch", + "shortName":"Stopwatch", + "icon": "stopwatch.png", + "version":"0.01", + "description": "A touch controlled stopwatch for Bangle 2", + "readme": "README.md", + "tags": "tool, b2", + "storage": [ + {"name":"stopwatch.app.js","url":"stopwatch.js"}, + {"name":"stopwatch.img","url":"stopwatch.icon.js","evaluate":true} + ] } ] diff --git a/apps/stopwatch/ChangeLog b/apps/stopwatch/ChangeLog new file mode 100644 index 000000000..9db0e26c5 --- /dev/null +++ b/apps/stopwatch/ChangeLog @@ -0,0 +1 @@ +0.01: first release diff --git a/apps/stopwatch/README.md b/apps/stopwatch/README.md new file mode 100644 index 000000000..1924cc343 --- /dev/null +++ b/apps/stopwatch/README.md @@ -0,0 +1,20 @@ +# Stopwatch + +A touch screen based stop watch for Bangle 2 + +## Screenshots + +## Features + +* Feature A +* Feature B + +## Future features + +I'm keen to complete this project with + +* Ability to dismiss the app and leave it running in the background +* A small widget to show the elapsed time on the curren active clock +* Laptimes, with a way to view all the laptimes on a scrollable screen + + diff --git a/apps/stopwatch/pause-24.png b/apps/stopwatch/pause-24.png new file mode 100644 index 0000000000000000000000000000000000000000..eb3d8feaa578ddf2868ca2ebfe6c1016b89076b6 GIT binary patch literal 161 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjY)RhkE)4%caKYZ?lYt^(o-U3d z9-YYv609r?%6x@>Y;0_-CL6c&@bIi(kYfnsC7S$X2lDQBZoM(BvGJk3)I0Y{?~g0x zcb`>IOUhLd?};+VI=F&$u~<)(1Fu1X=sArBW(KQ1!Ho<&4aPtl7(8A5T-G@yGywo& C|1Q-4 literal 0 HcmV?d00001 diff --git a/apps/stopwatch/pause-24a.png b/apps/stopwatch/pause-24a.png new file mode 100644 index 0000000000000000000000000000000000000000..7838ef640b48c569532e978aa4ea89960d1b0533 GIT binary patch literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjY)RhkE)4%caKYZ?lYt@zo-U3d z9-YYv60C>i3?5DV?eCzgSjh$gYC*9sS`u3mt~3R5yXi{si1joHGB8XvWs;ff*UPx#<4Ht8R7gv;*0D;&KoADtFVAWvTu`u3ff&Q zddffoheq6(ovFkBk;%?%8p+ip=j#J@@r2_VcpvbIcRXMd*JGgHfc4CCOxm~l7>bnu zk@<#w%y2gZDFwRBN1S4cml9|w5Sc5yVh=}uA^!o^Gw-p1+qR8Ayso-U3d z9-YYv609mr{A_G($9Z^o{+~S3zaZ@aOTUJJ%uS&=49hxV8Wzs)WIEizWU{@XmBX~9 zsYh`BlMDQd0=eB9SdTnm-t%&ffW$Aymb`<>8oqgfy*X@Q4-Ps+&UM&uNRk!kj6GuR V;!)cRW&mwu@O1TaS?83{1OQ$|I{5$q literal 0 HcmV?d00001 diff --git a/apps/stopwatch/stop-24a.png b/apps/stopwatch/stop-24a.png new file mode 100644 index 0000000000000000000000000000000000000000..e89ddae054cbda36b088abab6577f064049dbdf9 GIT binary patch literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjY)RhkE)4%caKYZ?lYt_oo-U3d z9-VKedh<0X@VLyE^E>)`zQZ1Ny$-idk)JA?UU=`)n(L`3>2NZIRp$ZMX(l(L6@vEJ zySe!q8&BV{IJVT%o@zpKGUG`7qs_<9thpacs;)sXzG!+_r}04vQBZNXTE1 nxpdjV=apyUC!A4#dXRD61xvr9nF3)z2QYZL`njxgN@xNA(C= this.x && x<= (this.x + this.w) && y>= this.y && y<= (this.y + this.h)) { + log_debug(this.name + ":callback\n"); + this.callback(); + return true; + } + return false; +}; + +BUTTON.prototype.draw = function() { + g.setColor(this.color); + g.fillRect(this.x, this.y, this.x + this.w, this.y + this.h); + g.setColor("#000"); // the icons and boxes are drawn black + if (this.img != undefined) { + let iw = iconScale * 24; // the images were loaded as 24 pixels, we will scale + let ix = this.x + ((this.w - iw) /2); + let iy = this.y + ((this.h - iw) /2); + log_debug("g.drawImage(" + ix + "," + iy + "{scale: " + iconScale + "})"); + g.drawImage(this.img, ix, iy, {scale: iconScale}); + } + g.drawRect(this.x, this.y, this.x + this.w, this.y + this.h); +}; + + +var bigPlayPauseBtn = new BUTTON("big",0, 3*h/4 ,w, h/4, "#0ff", stopStart, play_img); +var smallPlayPauseBtn = new BUTTON("small",w/2, 3*h/4 ,w/2, h/4, "#0ff", stopStart, play_img); +var resetBtn = new BUTTON("rst",0, 3*h/4, w/2, h/4, "#ff0", lapReset, pause_img); + +bigPlayPauseBtn.setImage(play_img); +smallPlayPauseBtn.setImage(play_img); +resetBtn.setImage(pause_img); + + +Bangle.on('touch', function(button, xy) { + // not running, and reset + if (!running && tCurrent == tTotal && bigPlayPauseBtn.check(xy.x, xy.y)) return; + + // paused and hit play + if (!running && tCurrent != tTotal && smallPlayPauseBtn.check(xy.x, xy.y)) return; + + // paused and press reset + if (!running && tCurrent != tTotal && resetBtn.check(xy.x, xy.y)) return; + + // must be running + if (running && bigPlayPauseBtn.check(xy.x, xy.y)) return; +}); + +// Stop updates when LCD is off, restart when on +Bangle.on('lcdPower',on=>{ + if (on) { + draw(); // draw immediately, queue redraw + } else { // stop draw timer + if (drawTimeout) clearTimeout(drawTimeout); + drawTimeout = undefined; + } +}); + +// Clear the screen once, at startup +g.setTheme({bg:"#000",fg:"#fff",dark:true}).clear(); +// above not working, hence using next 2 lines +g.setColor("#000"); +g.fillRect(0,0,w,h); + +Bangle.loadWidgets(); +Bangle.drawWidgets(); +draw(); +Bangle.setUI("clock"); // Show launcher when button pressed diff --git a/apps/stopwatch/stopwatch.icon.js b/apps/stopwatch/stopwatch.icon.js new file mode 100644 index 000000000..867b95bd2 --- /dev/null +++ b/apps/stopwatch/stopwatch.icon.js @@ -0,0 +1 @@ +require("heatshrink").decompress(atob("mEw4UA///vvvvEF/muH+cDHgPABf4AElWoKhILClALH1WqAQIWHBYIABwAKEgQKD1WgBYkK1X1r4XHlWtqtVvQLG1XVBYNXHYsC1YJBBoPqC4kKEQILCvQ7EhW1BYdeBYkqytVqwCCQwkqCgILCq4LFIoILCqoLEIwIsBGQJIBBZ+pA4Na0oDBtQLGvSFCBaYjIHYR3CI5AADBYhrCAAaDHAASDGQASGCBYizCAASzFZYQACZYrjCIwb7QHgIkCvQ6EGAWq+tf1QuEGAWqAAQuFEgQKBEQw9DHIwAuA=")); diff --git a/apps/stopwatch/stopwatch.png b/apps/stopwatch/stopwatch.png new file mode 100644 index 0000000000000000000000000000000000000000..92ffe73b7f172f7019486231d5bc0ba327c13a67 G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