mirror of https://github.com/espruino/BangleApps
update v005 - Use settings
parent
4fa752397f
commit
c7aed0d192
|
@ -1403,7 +1403,7 @@
|
||||||
"id": "metronome",
|
"id": "metronome",
|
||||||
"name": "Metronome",
|
"name": "Metronome",
|
||||||
"icon": "metronome_icon.png",
|
"icon": "metronome_icon.png",
|
||||||
"version": "0.04",
|
"version": "0.05",
|
||||||
"readme": "README.md",
|
"readme": "README.md",
|
||||||
"description": "Makes the watch blinking and vibrating with a given rate",
|
"description": "Makes the watch blinking and vibrating with a given rate",
|
||||||
"tags": "tool",
|
"tags": "tool",
|
||||||
|
@ -1417,7 +1417,8 @@
|
||||||
"name": "metronome.img",
|
"name": "metronome.img",
|
||||||
"url": "metronome-icon.js",
|
"url": "metronome-icon.js",
|
||||||
"evaluate": true
|
"evaluate": true
|
||||||
}
|
},
|
||||||
|
{"name":"metronome.settings.js","url":"settings.js"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ "id": "blackjack",
|
{ "id": "blackjack",
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
0.02: Watch vibrates with every beat
|
0.02: Watch vibrates with every beat
|
||||||
0.03: Uses mean of three time intervalls to calculate bmp
|
0.03: Uses mean of three time intervalls to calculate bmp
|
||||||
0.04: App shows instructions, Widgets remain visible, color changed
|
0.04: App shows instructions, Widgets remain visible, color changed
|
||||||
|
0.05: Buzz intensity and beats per bar can be changed via settings-app
|
||||||
|
|
|
@ -8,6 +8,7 @@ This metronome makes your watch blink and vibrate with a given rate.
|
||||||
* Use `BTN1` to increase the bmp value by one.
|
* Use `BTN1` to increase the bmp value by one.
|
||||||
* Use `BTN3` to decrease the bmp value by one.
|
* Use `BTN3` to decrease the bmp value by one.
|
||||||
* You can change the bpm value any time by tapping the screen or using `BTN1` and `BTN3`.
|
* You can change the bpm value any time by tapping the screen or using `BTN1` and `BTN3`.
|
||||||
|
* Intensity of buzzing and the beats per bar (default 4) can be changed with the settings-app. The first beat per bar will be marked in red.
|
||||||
|
|
||||||
## Attributions
|
## Attributions
|
||||||
|
|
||||||
|
|
|
@ -6,32 +6,40 @@ var tindex=0; //index to iterate through time_diffs
|
||||||
|
|
||||||
Bangle.setLCDTimeout(undefined); //do not deaktivate display while running this app
|
Bangle.setLCDTimeout(undefined); //do not deaktivate display while running this app
|
||||||
|
|
||||||
|
const storage = require("Storage");
|
||||||
|
const SETTINGS_FILE = 'metronome.settings.json';
|
||||||
|
|
||||||
|
//return setting
|
||||||
|
function setting(key) {
|
||||||
|
//define default settings
|
||||||
|
const DEFAULTS = {
|
||||||
|
'beatsperbar': 4,
|
||||||
|
'buzzintens': 0.75,
|
||||||
|
};
|
||||||
|
if (!settings) { loadSettings(); }
|
||||||
|
return (key in settings) ? settings[key] : DEFAULTS[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
//load settings
|
||||||
|
let settings;
|
||||||
|
|
||||||
|
function loadSettings() {
|
||||||
|
settings = storage.readJSON(SETTINGS_FILE, 1) || {};
|
||||||
|
}
|
||||||
|
|
||||||
function changecolor() {
|
function changecolor() {
|
||||||
const maxColors = 2;
|
const colors = {
|
||||||
const colors = {
|
0: { value: 0xF800, name: "Red" },
|
||||||
0: { value: 0xF800, name: "Red" },
|
1: { value: 0xFFFF, name: "White" },
|
||||||
1: { value: 0xFFFF, name: "White" },
|
2: { value: 0x9492, name: "gray" },
|
||||||
2: { value: 0x03E0, name: "DarkGreen" },
|
3: { value: 0xFFFF, name: "White" },
|
||||||
3: { value: 0xFFFF, name: "White" },
|
4: { value: 0x9492, name: "gray" },
|
||||||
4: { value: 0x03E0, name: "DarkGreen" },
|
5: { value: 0xFFFF, name: "White" },
|
||||||
5: { value: 0xFFFF, name: "White" },
|
6: { value: 0x9492, name: "gray" },
|
||||||
6: { value: 0x03E0, name: "DarkGreen" },
|
|
||||||
7: { value: 0xFFFF, name: "White" },
|
7: { value: 0xFFFF, name: "White" },
|
||||||
8: { value: 0x7BEF, name: "DarkGrey" },
|
|
||||||
// 9: { value: 0x001F, name: "Blue" },
|
|
||||||
// 9: { value: 0x001F, name: "Blue" },
|
|
||||||
// 10: { value: 0x07E0, name: "Green" },
|
|
||||||
// 11: { value: 0x07FF, name: "Cyan" },
|
|
||||||
1: { value: 0xF800, name: "Red" },
|
|
||||||
// 13: { value: 0xF81F, name: "Magenta" },
|
|
||||||
// 14: { value: 0xFFE0, name: "Yellow" },
|
|
||||||
// 15: { value: 0xFFFF, name: "White" },
|
|
||||||
// 16: { value: 0xFD20, name: "Orange" },
|
|
||||||
// 17: { value: 0xAFE5, name: "GreenYellow" },
|
|
||||||
// 18: { value: 0xF81F, name: "Pink" },
|
|
||||||
};
|
};
|
||||||
g.setColor(colors[cindex].value);
|
g.setColor(colors[cindex].value);
|
||||||
if (cindex == maxColors-1) {
|
if (cindex == setting('beatsperbar')-1) {
|
||||||
cindex = 0;
|
cindex = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -44,7 +52,7 @@ function updateScreen() {
|
||||||
g.clearRect(0, 50, 250, 150);
|
g.clearRect(0, 50, 250, 150);
|
||||||
changecolor();
|
changecolor();
|
||||||
try {
|
try {
|
||||||
Bangle.buzz(50, 0.75);
|
Bangle.buzz(50, setting('buzzintens'));
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
}
|
}
|
||||||
|
@ -52,6 +60,7 @@ function updateScreen() {
|
||||||
g.drawString(Math.floor(bpm)+"bpm", 5, 60);
|
g.drawString(Math.floor(bpm)+"bpm", 5, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Bangle.on('touch', function(button) {
|
Bangle.on('touch', function(button) {
|
||||||
// setting bpm by tapping the screen. Uses the mean time difference between several tappings.
|
// setting bpm by tapping the screen. Uses the mean time difference between several tappings.
|
||||||
if (tindex < time_diffs.length) {
|
if (tindex < time_diffs.length) {
|
||||||
|
|
Loading…
Reference in New Issue