mirror of https://github.com/espruino/BangleApps
Merge pull request #938 from bengwalker/master
Add Bangle.js 2 support for metronome apppull/942/head
commit
cea51d06d0
|
@ -2151,12 +2151,12 @@
|
|||
{
|
||||
"id": "metronome",
|
||||
"name": "Metronome",
|
||||
"version": "0.06",
|
||||
"version": "0.07",
|
||||
"readme": "README.md",
|
||||
"description": "Makes the watch blinking and vibrating with a given rate",
|
||||
"icon": "metronome_icon.png",
|
||||
"tags": "tool",
|
||||
"supports": ["BANGLEJS"],
|
||||
"readme": "README.md",
|
||||
"allow_emulator": true,
|
||||
"screenshots": [{"url":"bangle1-metronome-screenshot.png"}],
|
||||
"storage": [
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
0.04: App shows instructions, Widgets remain visible, color changed
|
||||
0.05: Buzz intensity and beats per bar can be changed via settings-app
|
||||
0.06: Correct string position
|
||||
0.07: Add support for Bangle.sjs2
|
|
@ -4,11 +4,12 @@ This metronome makes your watch blink and vibrate with a given rate.
|
|||
|
||||
## Usage
|
||||
|
||||
* Tap the screen at least three times. The app calculates the mean rate of your tapping. This rate is displayed in bmp while the text blinks and the watch softly vibrates with every beat.
|
||||
* Use `BTN1` to increase the bmp value by one.
|
||||
* Use `BTN3` to decrease the bmp value by one.
|
||||
* Tap the screen at least three times. The app calculates the mean rate of your tapping. This rate is displayed in bpm while the text blinks and the watch softly vibrates with every beat.
|
||||
* Use `BTN1` to increase the bpm value by one.
|
||||
* Use `BTN3` to decrease the bpm 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.
|
||||
* On Bangle.js 2 tapping the center of the screen initiates bpm. in- or decreasing bpm can by 1 can be done by tapping left or right site of the screen.
|
||||
|
||||
## Attributions
|
||||
|
||||
|
|
|
@ -3,10 +3,9 @@ var cindex=0; // index to iterate through colous
|
|||
var bpm=60; // ininital bpm value
|
||||
var time_diffs = [1000, 1000, 1000]; //array to calculate mean bpm
|
||||
var tindex=0; //index to iterate through time_diffs
|
||||
|
||||
|
||||
Bangle.setLCDTimeout(undefined); //do not deaktivate display while running this app
|
||||
|
||||
// set background colour
|
||||
g.setTheme({bg:"#000"});
|
||||
Bangle.setLCDTimeout(undefined); //do not deactivate display while running this app
|
||||
const storage = require("Storage");
|
||||
const SETTINGS_FILE = 'metronome.settings.json';
|
||||
|
||||
|
@ -15,7 +14,7 @@ function setting(key) {
|
|||
//define default settings
|
||||
const DEFAULTS = {
|
||||
'beatsperbar': 4,
|
||||
'buzzintens': 0.75,
|
||||
'buzzintens': 1.0,
|
||||
};
|
||||
if (!settings) { loadSettings(); }
|
||||
return (key in settings) ? settings[key] : DEFAULTS[key];
|
||||
|
@ -40,6 +39,10 @@ function changecolor() {
|
|||
7: { value: 0xFFFF, name: "White" },
|
||||
};
|
||||
g.setColor(colors[cindex].value);
|
||||
if ((process.env.HWVERSION==2 )) {
|
||||
g.drawLine(39,0,39,g.getWidth()/3);
|
||||
g.drawLine(136,0,136,g.getWidth()/3);
|
||||
}
|
||||
if (cindex == setting('beatsperbar')-1) {
|
||||
cindex = 0;
|
||||
}
|
||||
|
@ -50,43 +53,73 @@ function changecolor() {
|
|||
}
|
||||
|
||||
function updateScreen() {
|
||||
g.reset().clearRect(0, 50, 250, 150);
|
||||
g.reset().clearRect(0, 50, 250, 120);
|
||||
changecolor();
|
||||
try {
|
||||
Bangle.buzz(50, setting('buzzintens'));
|
||||
} catch(err) {
|
||||
}
|
||||
g.setFont("Vector",40).setFontAlign(0,0);
|
||||
g.drawString(Math.floor(bpm)+"bpm", g.getWidth()/2, 100);
|
||||
g.drawString(Math.floor(bpm)+"bpm", g.getWidth()/2, g.getWidth()/2);
|
||||
}
|
||||
|
||||
Bangle.on('touch', function(button) {
|
||||
// setting bpm by tapping the screen. Uses the mean time difference between several tappings.
|
||||
if (tindex < time_diffs.length) {
|
||||
if (Date.now()-tStart < 5000) {
|
||||
time_diffs[tindex] = Date.now()-tStart;
|
||||
}
|
||||
} else {
|
||||
tindex=0;
|
||||
time_diffs[tindex] = Date.now()-tStart;
|
||||
}
|
||||
tindex += 1;
|
||||
mean_time = 0.0;
|
||||
for(count = 0; count < time_diffs.length; count++) {
|
||||
mean_time += time_diffs[count];
|
||||
}
|
||||
time_diff = mean_time/count;
|
||||
//Write user instructuins to screen
|
||||
function printInstructions() {
|
||||
g.clear(1).setFont("4x6");
|
||||
g.setColor(-1); //set color to white
|
||||
g.drawString('Drum the beat on the center\nof the screen to set tempo.', 30, g.getWidth()/3*2+15);
|
||||
if(process.env.HWVERSION==1) {
|
||||
g.drawString('Use BTN1 to increase, and\nBTN3 to decrease bpm value by 1.', 30, g.getWidth()/3*2+30);
|
||||
}
|
||||
else {
|
||||
g.drawString('Touch left part of the screen\nto decrease, or the right site\nto increase bpm value by 1.', 30, g.getWidth()/3*2+30);
|
||||
}
|
||||
}
|
||||
|
||||
tStart = Date.now();
|
||||
clearInterval(time_diff);
|
||||
bpm = (60 * 1000/(time_diff));
|
||||
updateScreen();
|
||||
clearInterval(interval);
|
||||
interval = setInterval(updateScreen, 60000 / bpm);
|
||||
return bpm;
|
||||
Bangle.on('touch', function(zone, e) {
|
||||
// setting bpm by tapping the screen. Uses the mean time difference between several tappings.
|
||||
if ((process.env.HWVERSION==2 && e.x > 39 && e.x < 136) || process.env.HWVERSION==1){
|
||||
if (tindex < time_diffs.length) {
|
||||
if (Date.now()-tStart < 5000) {
|
||||
time_diffs[tindex] = Date.now()-tStart;
|
||||
}
|
||||
} else {
|
||||
tindex=0;
|
||||
time_diffs[tindex] = Date.now()-tStart;
|
||||
}
|
||||
tindex += 1;
|
||||
mean_time = 0.0;
|
||||
for (count = 0; count < time_diffs.length; count++) {
|
||||
mean_time += time_diffs[count];
|
||||
}
|
||||
time_diff = mean_time/count;
|
||||
|
||||
tStart = Date.now();
|
||||
clearInterval(time_diff);
|
||||
bpm = (60 * 1000/(time_diff));
|
||||
updateScreen();
|
||||
clearInterval(interval);
|
||||
interval = setInterval(updateScreen, 60000 / bpm);
|
||||
return bpm;
|
||||
}
|
||||
else if (e.x < 39) {
|
||||
if (bpm > 1) {
|
||||
bpm -= 1;
|
||||
clearInterval(interval);
|
||||
interval = setInterval(updateScreen, 60000 / bpm);
|
||||
}
|
||||
}
|
||||
else if (e.x > 136) {
|
||||
if (bpm > 1) {
|
||||
bpm += 1;
|
||||
clearInterval(interval);
|
||||
interval = setInterval(updateScreen, 60000 / bpm);
|
||||
}}
|
||||
});
|
||||
|
||||
// enable bpm finetuning via buttons.
|
||||
|
||||
// enable bpm finetuning
|
||||
if ((process.env.HWVERSION==1)) {
|
||||
setWatch(() => {
|
||||
bpm += 1;
|
||||
clearInterval(interval);
|
||||
|
@ -101,10 +134,10 @@ setWatch(() => {
|
|||
}
|
||||
}, BTN3, {repeat:true});
|
||||
|
||||
}
|
||||
interval = setInterval(updateScreen, 60000 / bpm);
|
||||
printInstructions();
|
||||
|
||||
g.clear(1).setFont("6x8");
|
||||
g.drawString('Touch the screen to set tempo.\nUse BTN1 to increase, and\nBTN3 to decrease bpm value by 1.', 25, 200);
|
||||
|
||||
Bangle.loadWidgets();
|
||||
Bangle.drawWidgets();
|
||||
|
|
Loading…
Reference in New Issue