diff --git a/apps.json b/apps.json index 01ad2eac4..846ab7efe 100644 --- a/apps.json +++ b/apps.json @@ -5067,7 +5067,7 @@ "id": "touchtimer", "name": "Touch Timer", "shortName": "Touch Timer", - "version": "0.01", + "version": "0.02", "description": "Quickly and easily create a timer with touch-only input. The time can be easily set with a number pad.", "icon": "app.png", "tags": "tools", @@ -5076,7 +5076,9 @@ "screenshots": [{"url":"0_light_timer_edit.png"},{"url":"1_light_timer_ready.png"},{"url":"2_light_timer_running.png"},{"url":"3_light_timer_finished.png"}], "storage": [ { "name": "touchtimer.app.js", "url": "app.js" }, + { "name":"touchtimer.settings.js", "url":"settings.js"}, { "name": "touchtimer.img", "url": "app-icon.js", "evaluate": true } - ] + ], + "data": [{"name":"touchtimer.data.json"}] } ] diff --git a/apps/touchtimer/ChangeLog b/apps/touchtimer/ChangeLog index 193a476aa..01904c6ea 100644 --- a/apps/touchtimer/ChangeLog +++ b/apps/touchtimer/ChangeLog @@ -1 +1,2 @@ -0.01: Initial creation of the touch timer app \ No newline at end of file +0.01: Initial creation of the touch timer app +0.02: Add settings menu \ No newline at end of file diff --git a/apps/touchtimer/README.md b/apps/touchtimer/README.md index c97e69afc..39afba8e5 100644 --- a/apps/touchtimer/README.md +++ b/apps/touchtimer/README.md @@ -9,7 +9,8 @@ Quickly and easily create a timer with touch-only input. The time can be easily - If the timer time is correct, press "OK". - If you have accidentially pressed "OK", press "STOP" to go cancel. - Press "START" to start the timer, if the time is correct. -- The timer will run the time until 0. Once it hits zero the watch will buzz for 1 second every 5 seconds for a total of 5 times, or until you press "STOP" +- The timer will run the time until 0. Once it hits zero the watch will buzz for 1 second every 1 seconds for a total of 3 times, or until you press "STOP" +- -> The number of buzzes, the buzz duration, and the pause between buzzes is configurable in the settings app ## Screenshots diff --git a/apps/touchtimer/app.js b/apps/touchtimer/app.js index c3200327d..ffa1af80a 100644 --- a/apps/touchtimer/app.js +++ b/apps/touchtimer/app.js @@ -1,6 +1,9 @@ var DEBUG = false; +var FILE = "touchtimer.data.json"; var main = () => { + var settings = readSettings(); + var button1 = new Button({ x1: 1, y1: 35, x2: 58, y2: 70 }, 1); var button2 = new Button({ x1: 60, y1: 35, x2: 116, y2: 70 }, 2); var button3 = new Button({ x1: 118, y1: 35, x2: 174, y2: 70 }, 3); @@ -132,18 +135,18 @@ var main = () => { timerIntervalId = undefined; } - var buzzCount = 0; - Bangle.buzz(1000, 1); + var buzzCount = 1; + Bangle.buzz(settings.buzzDuration * 1000, 1); buzzIntervalId = setInterval(() => { - if (buzzCount >= 5) { + if (buzzCount >= settings.buzzCount) { clearInterval(buzzIntervalId); buzzIntervalId = undefined; return; } else { - Bangle.buzz(1000, 1); + Bangle.buzz(settings.buzzDuration * 1000, 1); buzzCount++; } - }, 5000); + }, settings.buzzDuration * 1000 + settings.pauseBetween * 1000); } }, 1000); @@ -437,6 +440,17 @@ class TimerCountDown { } } +var readSettings = () => { + log("reading settings"); + var settings = require("Storage").readJSON(FILE, 1) || { + buzzCount: 3, + buzzDuration: 1, + pauseBetween: 1, + }; + log(settings); + return settings; +}; + // start main function main(); diff --git a/apps/touchtimer/settings.js b/apps/touchtimer/settings.js new file mode 100644 index 000000000..885670f57 --- /dev/null +++ b/apps/touchtimer/settings.js @@ -0,0 +1,77 @@ +(function (back) { + var DEBUG = false; + var FILE = "touchtimer.data.json"; + + var settings = {}; + + var showMainMenu = () => { + log("Loading main menu"); + + E.showMenu({ + "": { title: "Touch Timer" }, + "< Back": () => back(), + "Buzz Count": { + value: settings.buzzCount, + min: 1, + max: 3, + step: 1, + onchange: (value) => { + settings.buzzCount = value; + writeSettings(settings); + }, + }, + "Buzz Duration": { + value: settings.buzzDuration, + min: 1, + max: 10, + step: 0.5, + format: (value) => value + "s", + onchange: (value) => { + settings.buzzDuration = value; + writeSettings(settings); + }, + }, + "Pause Between": { + value: settings.pauseBetween, + min: 1, + max: 5, + step: 1, + format: (value) => value + "s", + onchange: (value) => { + settings.pauseBetween = value; + writeSettings(settings); + }, + }, + }); + }; + + // lib functions + + var log = (message) => { + if (DEBUG) { + console.log(JSON.stringify(message)); + } + }; + + var readSettings = () => { + log("reading settings"); + var settings = require("Storage").readJSON(FILE, 1) || { + buzzCount: 3, + buzzDuration: 1, + pauseBetween: 1, + }; + log(settings); + return settings; + }; + + var writeSettings = (settings) => { + log("writing settings"); + log(settings); + require("Storage").writeJSON(FILE, settings); + }; + + // start main function + + settings = readSettings(); + showMainMenu(); +});