Skip to content

Commit

Permalink
Merge 8d3435e into c81033f
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Puibaraud committed Jul 2, 2020
2 parents c81033f + 8d3435e commit 0060253
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/button.js
Expand Up @@ -182,13 +182,6 @@ class Button extends Emitter {
last: null
};

// Create a debounce boundary on event triggers
// this avoids button events firing on
// press noise and false positives
const trigger = Fn.debounce(key => {
aliases[key].forEach(type => this.emit(type));
}, 7);

let pinValue = typeof options === "object" ? options.pin : options;

Board.Component.call(
Expand All @@ -210,6 +203,11 @@ class Button extends Emitter {

this.pulldown = options.pulldown || options.isPulldown || false;

// `debounceTime` is a duration (milliseconds)
// to prevent button events firing on
// press noise and false positives
this.debounceTime = options.debounceTime || 7;

// Turns out some button circuits will send
// 0 for up and 1 for down, and some the inverse,
// so we can invert our function with this option.
Expand Down Expand Up @@ -275,6 +273,13 @@ class Button extends Emitter {
}
});

// Create a debounce boundary on event triggers
// this avoids button events firing on
// press noise and false positives
const trigger = Fn.debounce(key => {
aliases[key].forEach(type => this.emit(type));
}, this.debounceTime);

/* istanbul ignore else */
if (typeof this.initialize === "function") {
this.initialize(options, data => {
Expand Down

0 comments on commit 0060253

Please sign in to comment.