Merge pull request #423 from bengwalker/master

new pull request motronome v0.05
master
Gordon Williams 2020-05-15 13:34:52 +01:00 committed by GitHub
commit 50412f256d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 90 additions and 25 deletions

View File

@ -1421,7 +1421,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",
@ -1435,7 +1435,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,31 +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: 0xFFFF, name: "White" },
// 1: { value: 0x000F, name: "Navy" },
// 2: { value: 0x03E0, name: "DarkGreen" },
// 3: { value: 0x03EF, name: "DarkCyan" },
// 4: { value: 0x7800, name: "Maroon" },
// 5: { value: 0x780F, name: "Purple" },
// 6: { value: 0x7BE0, name: "Olive" },
// 7: { value: 0xC618, name: "LightGray" },
// 8: { value: 0x7BEF, name: "DarkGrey" },
// 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" },
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" },
};
g.setColor(colors[cindex].value);
if (cindex == maxColors-1) {
if (cindex == setting('beatsperbar')-1) {
cindex = 0;
}
else {
@ -42,11 +51,16 @@ function changecolor() {
function updateScreen() {
g.clearRect(0, 50, 250, 150);
changecolor();
Bangle.buzz(50, 0.75);
try {
Bangle.buzz(50, setting('buzzintens'));
}
catch(err) {
}
g.setFont("Vector",48);
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) {

View File

@ -0,0 +1,48 @@
// This file should contain exactly one function, which shows the app's settings
/**
* @param {function} back Use back() to return to settings menu
*/
(function(back) {
const SETTINGS_FILE = 'metronome.settings.json';
// initialize with default settings...
let s = {
'beatsperbar': 4,
'buzzintens': 0.75,
};
// ...and overwrite them with any saved values
// This way saved values are preserved if a new version adds more settings
const storage = require('Storage');
const saved = storage.readJSON(SETTINGS_FILE, 1) || {};
for (const key in saved) {
s[key] = saved[key];
}
// creates a function to safe a specific setting, e.g. save('color')(1)
function save(key) {
return function(value) {
s[key] = value;
storage.write(SETTINGS_FILE, s);
};
}
const menu = {
'': { 'title': 'Metronome' },
'< Back': back,
'beats per bar': {
value: s.beatsperbar,
min: 1,
max: 8,
step: 1,
onchange: save('beatsperbar'),
},
'buzz intensity': {
value: s.buzzintens,
min: 0.0,
max: 1.0,
step: 0.25,
onchange: save('buzzintens'),
},
};
E.showMenu(menu);
});