mirror of https://github.com/espruino/BangleApps
touchtimer: add settings
parent
3db8bd43c8
commit
3150fc7536
|
@ -5067,7 +5067,7 @@
|
||||||
"id": "touchtimer",
|
"id": "touchtimer",
|
||||||
"name": "Touch Timer",
|
"name": "Touch Timer",
|
||||||
"shortName": "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.",
|
"description": "Quickly and easily create a timer with touch-only input. The time can be easily set with a number pad.",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "tools",
|
"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"}],
|
"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": [
|
"storage": [
|
||||||
{ "name": "touchtimer.app.js", "url": "app.js" },
|
{ "name": "touchtimer.app.js", "url": "app.js" },
|
||||||
|
{ "name":"touchtimer.settings.js", "url":"settings.js"},
|
||||||
{ "name": "touchtimer.img", "url": "app-icon.js", "evaluate": true }
|
{ "name": "touchtimer.img", "url": "app-icon.js", "evaluate": true }
|
||||||
]
|
],
|
||||||
|
"data": [{"name":"touchtimer.data.json"}]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
0.01: Initial creation of the touch timer app
|
0.01: Initial creation of the touch timer app
|
||||||
|
0.02: Add settings menu
|
|
@ -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 the timer time is correct, press "OK".
|
||||||
- If you have accidentially pressed "OK", press "STOP" to go cancel.
|
- If you have accidentially pressed "OK", press "STOP" to go cancel.
|
||||||
- Press "START" to start the timer, if the time is correct.
|
- 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
|
## Screenshots
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
var DEBUG = false;
|
var DEBUG = false;
|
||||||
|
var FILE = "touchtimer.data.json";
|
||||||
|
|
||||||
var main = () => {
|
var main = () => {
|
||||||
|
var settings = readSettings();
|
||||||
|
|
||||||
var button1 = new Button({ x1: 1, y1: 35, x2: 58, y2: 70 }, 1);
|
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 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);
|
var button3 = new Button({ x1: 118, y1: 35, x2: 174, y2: 70 }, 3);
|
||||||
|
@ -132,18 +135,18 @@ var main = () => {
|
||||||
timerIntervalId = undefined;
|
timerIntervalId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var buzzCount = 0;
|
var buzzCount = 1;
|
||||||
Bangle.buzz(1000, 1);
|
Bangle.buzz(settings.buzzDuration * 1000, 1);
|
||||||
buzzIntervalId = setInterval(() => {
|
buzzIntervalId = setInterval(() => {
|
||||||
if (buzzCount >= 5) {
|
if (buzzCount >= settings.buzzCount) {
|
||||||
clearInterval(buzzIntervalId);
|
clearInterval(buzzIntervalId);
|
||||||
buzzIntervalId = undefined;
|
buzzIntervalId = undefined;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
Bangle.buzz(1000, 1);
|
Bangle.buzz(settings.buzzDuration * 1000, 1);
|
||||||
buzzCount++;
|
buzzCount++;
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, settings.buzzDuration * 1000 + settings.pauseBetween * 1000);
|
||||||
}
|
}
|
||||||
}, 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
|
// start main function
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
|
@ -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();
|
||||||
|
});
|
Loading…
Reference in New Issue