[buzz] Add support for ':' and '='
parent
ac5c80ff38
commit
019f635ad4
|
|
@ -1,14 +1,32 @@
|
||||||
/* Call this with a pattern like '.-.', '.. .' or '..' to buzz that pattern
|
const BUZZ_WEAK = 0.25;
|
||||||
out on the internal vibration motor. use buzz_menu to display a menu
|
const BUZZ_STRONG = 1;
|
||||||
where the patterns can be chosen. */
|
const SHORT_MS = 100;
|
||||||
|
const LONG_MS = 500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buzz the passed `pattern` out on the internal vibration motor.
|
||||||
|
*
|
||||||
|
* A pattern is a sequence of `.`, `:`, `-` and `=` where
|
||||||
|
* - `:` is one short and strong vibration
|
||||||
|
* - `.` is one short and weak vibration
|
||||||
|
* - `=` is one long and strong vibration
|
||||||
|
* - `-` is one long and weak vibration
|
||||||
|
*
|
||||||
|
* You can use the `buzz_menu` module to display a menu where some common patterns can be chosen.
|
||||||
|
*
|
||||||
|
* @param {string} pattern A string like `.-.`, `..=`, `:.:`, `..`, etc.
|
||||||
|
* @returns a Promise
|
||||||
|
*/
|
||||||
exports.pattern = pattern => new Promise(resolve => {
|
exports.pattern = pattern => new Promise(resolve => {
|
||||||
function b() {
|
function doBuzz() {
|
||||||
if (pattern == "") resolve();
|
if (pattern == "") resolve();
|
||||||
var c = pattern[0];
|
var c = pattern[0];
|
||||||
pattern = pattern.substr(1);
|
pattern = pattern.substr(1);
|
||||||
if (c==".") Bangle.buzz().then(()=>setTimeout(b,100));
|
if (c == ".") Bangle.buzz(SHORT_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100));
|
||||||
else if (c=="-") Bangle.buzz(500).then(()=>setTimeout(b,100));
|
else if (c == "-") Bangle.buzz(LONG_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100));
|
||||||
else setTimeout(b,100);
|
else if (c == ":") Bangle.buzz(SHORT_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100));
|
||||||
|
else if (c == "=") Bangle.buzz(LONG_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100));
|
||||||
|
else setTimeout(doBuzz, 100);
|
||||||
}
|
}
|
||||||
b();
|
doBuzz();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
/* Display a menu to select from various vibration patterns for use with buzz.js */
|
/**
|
||||||
|
* Display a menu to select from various common vibration patterns for use with buzz.js.
|
||||||
|
*
|
||||||
|
* @param {string} value The pre-selected pattern
|
||||||
|
* @param {*} callback A function called with the user selected pattern
|
||||||
|
*/
|
||||||
exports.pattern = function (value, callback) {
|
exports.pattern = function (value, callback) {
|
||||||
var vibPatterns = ["", ".", "..", "-", "--", "-.-", "---"];
|
var patterns = ["", ".", ":", "..", "::", "-", "=", "--", "==", "=.=", "---"];
|
||||||
return {
|
return {
|
||||||
value: Math.max(0,vibPatterns.indexOf(value)),
|
value: Math.max(0, patterns.indexOf(value)),
|
||||||
min: 0, max: vibPatterns.length-1,
|
min: 0,
|
||||||
format: v => vibPatterns[v]||/*LANG*/"Off",
|
max: patterns.length - 1,
|
||||||
|
format: v => patterns[v] || /*LANG*/"Off",
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
require("buzz").pattern(vibPatterns[v]);
|
require("buzz").pattern(patterns[v]);
|
||||||
callback(vibPatterns[v]);
|
callback(patterns[v]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue