[buzz] Add support for ',' and ';'

pull/1889/head
Alessandro Cocco 2022-05-28 23:30:59 +02:00
parent 019f635ad4
commit 091006e9c5
2 changed files with 10 additions and 8 deletions

View File

@ -1,16 +1,16 @@
const BUZZ_WEAK = 0.25; const BUZZ_WEAK = 0.25, BUZZ_STRONG = 1;
const BUZZ_STRONG = 1; const SHORT_MS = 100, MEDIUM_MS = 200, LONG_MS = 500;
const SHORT_MS = 100;
const LONG_MS = 500;
/** /**
* Buzz the passed `pattern` out on the internal vibration motor. * Buzz the passed `pattern` out on the internal vibration motor.
* *
* A pattern is a sequence of `.`, `:`, `-` and `=` where * A pattern is a sequence of `.`, `,`, `-`, `:`, `;` and `=` where
* - `:` is one short and strong vibration
* - `.` is one short and weak vibration * - `.` is one short and weak vibration
* - `=` is one long and strong vibration * - `,` is one medium and weak vibration
* - `-` is one long and weak vibration * - `-` is one long and weak vibration
* - `:` is one short and strong vibration
* - `;` is one medium and strong vibration
* - `=` is one long and strong vibration
* *
* You can use the `buzz_menu` module to display a menu where some common patterns can be chosen. * You can use the `buzz_menu` module to display a menu where some common patterns can be chosen.
* *
@ -23,8 +23,10 @@ exports.pattern = pattern => new Promise(resolve => {
var c = pattern[0]; var c = pattern[0];
pattern = pattern.substr(1); pattern = pattern.substr(1);
if (c == ".") Bangle.buzz(SHORT_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100)); if (c == ".") Bangle.buzz(SHORT_MS, BUZZ_WEAK).then(() => setTimeout(doBuzz, 100));
else if (c == ",") Bangle.buzz(MEDIUM_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(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(SHORT_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100));
else if (c == ";") Bangle.buzz(MEDIUM_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100));
else if (c == "=") Bangle.buzz(LONG_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100)); else if (c == "=") Bangle.buzz(LONG_MS, BUZZ_STRONG).then(() => setTimeout(doBuzz, 100));
else setTimeout(doBuzz, 100); else setTimeout(doBuzz, 100);
} }

View File

@ -5,7 +5,7 @@
* @param {*} callback A function called with the user selected pattern * @param {*} callback A function called with the user selected pattern
*/ */
exports.pattern = function (value, callback) { exports.pattern = function (value, callback) {
var patterns = ["", ".", ":", "..", "::", "-", "=", "--", "==", "=.=", "---"]; var patterns = ["", ".", ":", "..", "::", ",", ";", ",,", ";;", "-", "=", "--", "==", "...", ":::", "---", ";;;", "==="];
return { return {
value: Math.max(0, patterns.indexOf(value)), value: Math.max(0, patterns.indexOf(value)),
min: 0, min: 0,