diff --git a/apps/chronosimplewid/README.md b/apps/chronosimplewid/README.md deleted file mode 100644 index 6f3b417c0..000000000 --- a/apps/chronosimplewid/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Simple Chronometer Widget - -A fork of the awesome Chronometer Widget, but with a simple UI to set -a timer faster using only a tab events. Also very useful if combined -with the Pattern Launcher. - -# Contributors -Originally from [Purple-Tentacle](https://github.com/Purple-Tentacle) - -Forked and adapted by [David Peer](https://github.com/peerdavid) \ No newline at end of file diff --git a/apps/chronosimplewid/metadata.json b/apps/chronosimplewid/metadata.json deleted file mode 100644 index 72cc13e32..000000000 --- a/apps/chronosimplewid/metadata.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "id": "chronosimplewid", - "name": "Simple Chrono", - "shortName": "Simple Chrono", - "version": "0.01", - "description": "Chrono Widget Fork. Implements a simpler UI.", - "icon": "app.png", - "tags": "tool,widget", - "supports": ["BANGLEJS","BANGLEJS2"], - "screenshots": [{"url":"screenshot.png"}], - "readme": "README.md", - "storage": [ - {"name":"chronosimplewid.wid.js","url":"widget.js"}, - {"name":"chronosimplewid.app.js","url":"app.js"}, - {"name":"chronosimplewid.img","url":"app-icon.js","evaluate":true} - ] -} diff --git a/apps/chronosimplewid/ChangeLog b/apps/widtmr/ChangeLog similarity index 100% rename from apps/chronosimplewid/ChangeLog rename to apps/widtmr/ChangeLog diff --git a/apps/widtmr/README.md b/apps/widtmr/README.md new file mode 100644 index 000000000..0694a13cc --- /dev/null +++ b/apps/widtmr/README.md @@ -0,0 +1,12 @@ +# Simple Chronometer Widget + +This is a fork of the Chrono Widget, but implements a +simpler UI which to be able to set a timer faster with +less interaction. Additionally, it exposes some functions +that can be used by other apps or clocks to easily +implement a timer. It is used e.g. by lcars or notanalog. + +# Contributors +Originally from [Purple-Tentacle](https://github.com/Purple-Tentacle) + +Forked and adapted by [David Peer](https://github.com/peerdavid) \ No newline at end of file diff --git a/apps/chronosimplewid/app-icon.js b/apps/widtmr/app-icon.js similarity index 100% rename from apps/chronosimplewid/app-icon.js rename to apps/widtmr/app-icon.js diff --git a/apps/chronosimplewid/app.js b/apps/widtmr/app.js similarity index 58% rename from apps/chronosimplewid/app.js rename to apps/widtmr/app.js index d3293bc90..311e0d3ea 100644 --- a/apps/chronosimplewid/app.js +++ b/apps/widtmr/app.js @@ -1,8 +1,19 @@ +/* + * This is a fork of the Chrono Widget, but implements a + * simpler UI which to be able to set a timer faster with + * less interaction. Additionally, it exposes some functions + * that can be used by other apps or clocks to easily + * implement a timer. It is used e.g. by lcars or notanalog. + * + * Creator: David Peer + * Date: 02/2022 + */ + Bangle.loadWidgets(); const storage = require('Storage'); -let settingsChronowid; +let settings; const screenWidth = g.getWidth(); const screenHeight = g.getHeight(); @@ -13,15 +24,15 @@ const cy = parseInt(screenHeight/2); function updateSettings() { var now = new Date(); const goal = new Date(now.getFullYear(), now.getMonth(), now.getDate(), - now.getHours(), now.getMinutes() + settingsChronowid.minutes, now.getSeconds()); - settingsChronowid.goal = goal.getTime(); - storage.writeJSON('chronosimplewid.json', settingsChronowid); - if (WIDGETS["chronowid"]) WIDGETS["chronowid"].reload(); + now.getHours(), now.getMinutes() + settings.minutes, now.getSeconds()); + settings.goal = goal.getTime(); + storage.writeJSON('widtmr.json', settings); + if (WIDGETS["widtmr"]) WIDGETS["widtmr"].reload(); } function resetSettings() { - settingsChronowid = { + settings = { hours : 0, minutes : 0, seconds : 0, @@ -33,8 +44,8 @@ function resetSettings() { } -settingsChronowid = storage.readJSON('chronosimplewid.json',1); -if (!settingsChronowid) resetSettings(); +settings = storage.readJSON('widtmr.json',1); +if (!settings) resetSettings(); setWatch(_=>load(), BTN1); @@ -44,10 +55,10 @@ function draw(){ g.setFontAlign(0, 0, 0); g.setFont("Vector", 32).setFontAlign(0,-1); - var text = settingsChronowid.minutes + " min."; + var text = settings.minutes + " min."; var rectWidth = parseInt(g.stringWidth(text) / 2); - if(settingsChronowid.started){ + if(settings.started){ g.setColor("#ff0000"); } else { g.setColor(g.theme.fg); @@ -70,25 +81,25 @@ Bangle.on('touch', function(btn, e){ var isLower = e.y > lower; if(isRight){ - settingsChronowid.minutes += 1; + settings.minutes += 1; Bangle.buzz(40, 0.3); } else if(isLeft){ - settingsChronowid.minutes -= 1; + settings.minutes -= 1; Bangle.buzz(40, 0.3); } else if(isUpper){ - settingsChronowid.minutes += 5; + settings.minutes += 5; Bangle.buzz(40, 0.3); } else if(isLower){ - settingsChronowid.minutes -= 5; + settings.minutes -= 5; Bangle.buzz(40, 0.3); } else { - settingsChronowid.started = !settingsChronowid.started; + settings.started = !settings.started; Bangle.buzz(120, 0.6); } - if(settingsChronowid.minutes <= 0){ - settingsChronowid.minutes = 0; - settingsChronowid.started = false; + if(settings.minutes <= 0){ + settings.minutes = 0; + settings.started = false; } updateSettings(); diff --git a/apps/chronosimplewid/app.png b/apps/widtmr/app.png similarity index 100% rename from apps/chronosimplewid/app.png rename to apps/widtmr/app.png diff --git a/apps/widtmr/metadata.json b/apps/widtmr/metadata.json new file mode 100644 index 000000000..9645cc00c --- /dev/null +++ b/apps/widtmr/metadata.json @@ -0,0 +1,17 @@ +{ + "id": "widtmr", + "name": "Timer Widget", + "shortName": "Timer Widget", + "version": "0.01", + "description": "Fork from Chrono Widget with a simpler UI and a lib for other apps.", + "icon": "app.png", + "tags": "tool,widget", + "supports": ["BANGLEJS","BANGLEJS2"], + "screenshots": [{"url":"screenshot.png"}], + "readme": "README.md", + "storage": [ + {"name":"widtmr.wid.js","url":"widget.js"}, + {"name":"widtmr.app.js","url":"app.js"}, + {"name":"widtmr.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/chronosimplewid/screenshot.png b/apps/widtmr/screenshot.png similarity index 100% rename from apps/chronosimplewid/screenshot.png rename to apps/widtmr/screenshot.png diff --git a/apps/chronosimplewid/widget.js b/apps/widtmr/widget.js similarity index 60% rename from apps/chronosimplewid/widget.js rename to apps/widtmr/widget.js index 3fc5888b1..c918a52e1 100644 --- a/apps/chronosimplewid/widget.js +++ b/apps/widtmr/widget.js @@ -1,8 +1,11 @@ (() => { - var settingsChronowid; + let storage = require('Storage'); + + var settings; var interval = 0; //used for the 1 second interval timer var diff; + //Convert ms to time function getTime(t) { var milliseconds = parseInt((t % 1000) / 100), @@ -12,37 +15,35 @@ return hours.toString().padStart(2,0) + ":" + minutes.toString().padStart(2,0) + ":" + seconds.toString().padStart(2,0); } - /*function printDebug() { - print ("Goaltime: " + getTime(settingsChronowid.goal)); - print ("Goal: " + settingsChronowid.goal); - print("Difftime: " + getTime(diff)); - print("Diff: " + diff); - print ("Started: " + settingsChronowid.started); - print ("----"); - }*/ //counts down, calculates and displays function countDown() { var now = new Date(); - diff = settingsChronowid.goal - now; //calculate difference + diff = settings.goal - now; //calculate difference // time is up - if (settingsChronowid.started && diff < 1000) { + if (settings.started && diff < 1000) { Bangle.buzz(1500); //write timer off to file - settingsChronowid.started = false; - require('Storage').writeJSON('chronosimplewid.json', settingsChronowid); + settings.started = false; + storage.writeJSON('widtmr.json', settings); clearInterval(interval); //stop interval interval = undefined; } // calculates width and redraws accordingly - WIDGETS["chronowid"].redraw(); + WIDGETS["widtmr"].redraw(); } - // add the widget - WIDGETS["chronowid"]={area:"tl",width:0,draw:function() { - if (!this.width) return; + + /* + * Add the widgets and functions for other apps + */ + WIDGETS["widtmr"]={area:"tl",width:0,draw:function() { + if (!this.width) { + return; + } + g.reset().setFontAlign(0,0).clearRect(this.x,this.y,this.x+this.width,this.y+23); - //g.drawRect(this.x,this.y,this.x+this.width-1, this.y+23); + var scale; var timeStr; if (diff < 3600000) { //less than 1 hour left @@ -54,26 +55,47 @@ scale = 1; timeStr = getTime(diff); //display hour 00:00:00 but small } + // Font5x9Numeric7Seg - just build this in as it's tiny g.setFontCustom(atob("AAAAAAAAAAIAAAQCAQAAAd0BgMBdwAAAAAAAdwAB0RiMRcAAAERiMRdwAcAQCAQdwAcERiMRBwAd0RiMRBwAAEAgEAdwAd0RiMRdwAcERiMRdwAFAAd0QiEQdwAdwRCIRBwAd0BgMBAAABwRCIRdwAd0RiMRAAAd0QiEQAAAAAAAAAA="), 32, atob("BgAAAAAAAAAAAAAAAAYCAAYGBgYGBgYGBgYCAAAAAAAABgYGBgYG"), 9 + (scale<<8)); g.drawString(timeStr, this.x+this.width/2, this.y+12); + }, redraw:function() { var last = this.width; - if (!settingsChronowid.started) this.width = 0; - else this.width = (diff < 3600000) ? 58 : 48; - if (last != this.width) Bangle.drawWidgets(); - else this.draw(); + if (!settings.started) { + this.width = 0; + } else { + this.width = (diff < 3600000) ? 58 : 48; + } + + if (last != this.width) { + Bangle.drawWidgets(); + } else { + this.draw(); + } + }, reload:function() { - settingsChronowid = require('Storage').readJSON("chronosimplewid.json",1)||{}; - if (interval) clearInterval(interval); + settings = storage.readJSON("widtmr.json",1)||{}; + if (interval) { + clearInterval(interval); + } interval = undefined; + // start countdown each second - if (settingsChronowid.started) interval = setInterval(countDown, 1000); + if (settings.started) { + interval = setInterval(countDown, 1000); + } + // reset everything countDown(); - }}; - //printDebug(); + }, isStarted: function(){ + settings = storage.readJSON("widtmr.json",1)||{started: false}; + return settings.started; + } + +}; + // set width correctly, start countdown each second - WIDGETS["chronowid"].reload(); + WIDGETS["widtmr"].reload(); })();