Skip to content

Commit 4d64451

Browse files
committed
Ignoring bouncing on both button down and up
1 parent 58f7acd commit 4d64451

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

MMM-Buttons.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Module.register("MMM-Buttons", {
1616
buttons: [],
1717
minShortPressTime: 0,
1818
maxShortPressTime: 500,
19-
minLongPressTime: 3000
19+
minLongPressTime: 3000,
20+
bounceTimeout: 300
2021
},
2122

2223
// Define start sequence.

node_helper.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,31 @@ module.exports = NodeHelper.create({
3232

3333
return function (err, value) {
3434
if (value == 1) {
35-
self.buttons[index].pressed = new Date().getTime();
35+
var start = new Date().getTime();
36+
if (self.buttons[index].downBounceTimeoutEnd > start) {
37+
// We're bouncing!
38+
return;
39+
}
40+
41+
self.buttons[index].pressed = start;
42+
self.buttons[index].downBounceTimeoutEnd = start + self.config.bounceTimeout;
3643
self.sendSocketNotification("BUTTON_DOWN", {
3744
index: index
3845
});
39-
setTimeout(self.watchHandler(index), self.config.minLongPressTime, undefined, 0);
4046
return;
4147
}
4248
if (value == 0 && self.buttons[index].pressed !== undefined) {
4349
var start = self.buttons[index].pressed;
44-
var end = new Date().getTime();
45-
var time = end - start;
50+
var end = new Date().getTime();
51+
if (self.buttons[index].upBounceTimeoutEnd > end) {
52+
// We're bouncing!
53+
return;
54+
}
4655

4756
self.buttons[index].pressed = undefined;
57+
self.buttons[index].upBounceTimeoutEnd = end + self.config.bounceTimeout;
4858

59+
var time = end - start;
4960
self.sendSocketNotification("BUTTON_UP", {
5061
index: index,
5162
duration: time

0 commit comments

Comments
 (0)