Skip to content
This repository was archived by the owner on Dec 14, 2025. It is now read-only.

Commit f201a10

Browse files
authored
Merge pull request #1 from Jopyth/develop
Merge develop to master
2 parents 58f7acd + 4c3a85d commit f201a10

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.0.1] - Unreleased
8+
### Fixed
9+
- Module is able to send notifications in Midori browser again
10+
711
## [1.0.0] - 2017-01-28
812
### Initial release of the Buttons module.

MMM-Buttons.js

Lines changed: 3 additions & 2 deletions
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.
@@ -83,7 +84,7 @@ Module.register("MMM-Buttons", {
8384
}
8485
},
8586

86-
sendAction(description) {
87+
sendAction: function(description) {
8788
this.sendNotification(description.notification, description.payload);
8889
},
8990

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Here is full documentation of options for the modules configuration:
7070
| `minShortPressTime` | Minimum duration to trigger a short press in `ms`. Default is `0`. |
7171
| `maxShortPressTime` | Maximum duration to trigger a short press in `ms`. Default is `500`. |
7272
| `minLongPressTime` | Minimum time needed to trigger a long press in `ms`. Default is `3000`. Any press duration between `maxShortPressTime` and `minLongPressTime` does not do anything. |
73+
| `bounceTimeout` | Duration to ignore bouncing (unintentional doubble press on the button). |
7374

7475
### Button Configuration
7576

node_helper.js

Lines changed: 16 additions & 5 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
@@ -58,7 +69,7 @@ module.exports = NodeHelper.create({
5869
intializeButton: function(index) {
5970
const self = this;
6071

61-
var options = { persistentWatch: true };
72+
var options = { persistentWatch: true , activeLow: !!self.buttons[index].activeLow};
6273

6374
var pir = new Gpio(self.buttons[index].pin, 'in', 'both', options);
6475
pir.watch(this.watchHandler(index));

0 commit comments

Comments
 (0)