1
0
Fork 0

update v005 - Use settings

master
Michael Bengfort 2020-05-15 13:53:30 +02:00
parent 4fa752397f
commit c7aed0d192
4 changed files with 37 additions and 25 deletions

View File

@ -1403,7 +1403,7 @@
"id": "metronome",
"name": "Metronome",
"icon": "metronome_icon.png",
"version": "0.04",
"version": "0.05",
"readme": "README.md",
"description": "Makes the watch blinking and vibrating with a given rate",
"tags": "tool",
@ -1417,7 +1417,8 @@
"name": "metronome.img",
"url": "metronome-icon.js",
"evaluate": true
}
},
{"name":"metronome.settings.js","url":"settings.js"}
]
},
{ "id": "blackjack",

View File

@ -2,3 +2,4 @@
0.02: Watch vibrates with every beat
0.03: Uses mean of three time intervalls to calculate bmp
0.04: App shows instructions, Widgets remain visible, color changed
0.05: Buzz intensity and beats per bar can be changed via settings-app

View File

@ -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 `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`.
* 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

View File

@ -6,32 +6,40 @@ var tindex=0; //index to iterate through time_diffs
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() {
const maxColors = 2;
const colors = {
0: { value: 0xF800, name: "Red" },
1: { value: 0xFFFF, name: "White" },
2: { value: 0x03E0, name: "DarkGreen" },
3: { value: 0xFFFF, name: "White" },
4: { value: 0x03E0, name: "DarkGreen" },
5: { value: 0xFFFF, name: "White" },
6: { value: 0x03E0, name: "DarkGreen" },
const colors = {
0: { value: 0xF800, name: "Red" },
1: { value: 0xFFFF, name: "White" },
2: { value: 0x9492, name: "gray" },
3: { value: 0xFFFF, name: "White" },
4: { value: 0x9492, name: "gray" },
5: { value: 0xFFFF, name: "White" },
6: { value: 0x9492, name: "gray" },
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);
if (cindex == maxColors-1) {
if (cindex == setting('beatsperbar')-1) {
cindex = 0;
}
else {
@ -44,7 +52,7 @@ function updateScreen() {
g.clearRect(0, 50, 250, 150);
changecolor();
try {
Bangle.buzz(50, 0.75);
Bangle.buzz(50, setting('buzzintens'));
}
catch(err) {
}
@ -52,6 +60,7 @@ function updateScreen() {
g.drawString(Math.floor(bpm)+"bpm", 5, 60);
}
Bangle.on('touch', function(button) {
// setting bpm by tapping the screen. Uses the mean time difference between several tappings.
if (tindex < time_diffs.length) {