[buzz] Add support for ':' and '='
parent
ac5c80ff38
commit
019f635ad4
|
|
@ -1,14 +1,32 @@
|
|||
/* Call this with a pattern like '.-.', '.. .' or '..' to buzz that pattern
|
||||
out on the internal vibration motor. use buzz_menu to display a menu
|
||||
where the patterns can be chosen. */
|
||||
const BUZZ_WEAK = 0.25;
|
||||
const BUZZ_STRONG = 1;
|
||||
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 => {
|
||||
function b() {
|
||||
if (pattern=="") resolve();
|
||||
function doBuzz() {
|
||||
if (pattern == "") resolve();
|
||||
var c = pattern[0];
|
||||
pattern = pattern.substr(1);
|
||||
if (c==".") Bangle.buzz().then(()=>setTimeout(b,100));
|
||||
else if (c=="-") Bangle.buzz(500).then(()=>setTimeout(b,100));
|
||||
else setTimeout(b,100);
|
||||
if (c == ".") Bangle.buzz(SHORT_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100));
|
||||
else if (c == "-") Bangle.buzz(LONG_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 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 */
|
||||
|
||||
exports.pattern = function(value, callback) {
|
||||
var vibPatterns = ["", ".", "..", "-", "--", "-.-", "---"];
|
||||
/**
|
||||
* 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) {
|
||||
var patterns = ["", ".", ":", "..", "::", "-", "=", "--", "==", "=.=", "---"];
|
||||
return {
|
||||
value: Math.max(0,vibPatterns.indexOf(value)),
|
||||
min: 0, max: vibPatterns.length-1,
|
||||
format: v => vibPatterns[v]||/*LANG*/"Off",
|
||||
value: Math.max(0, patterns.indexOf(value)),
|
||||
min: 0,
|
||||
max: patterns.length - 1,
|
||||
format: v => patterns[v] || /*LANG*/"Off",
|
||||
onchange: v => {
|
||||
require("buzz").pattern(vibPatterns[v]);
|
||||
callback(vibPatterns[v]);
|
||||
require("buzz").pattern(patterns[v]);
|
||||
callback(patterns[v]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue