Skip to content

Commit

Permalink
Merge pull request #1 from Jopyth/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
Jopyth authored Jul 20, 2017
2 parents 58f7acd + 4c3a85d commit f201a10
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.1] - Unreleased
### Fixed
- Module is able to send notifications in Midori browser again

## [1.0.0] - 2017-01-28
### Initial release of the Buttons module.
5 changes: 3 additions & 2 deletions MMM-Buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Module.register("MMM-Buttons", {
buttons: [],
minShortPressTime: 0,
maxShortPressTime: 500,
minLongPressTime: 3000
minLongPressTime: 3000,
bounceTimeout: 300
},

// Define start sequence.
Expand Down Expand Up @@ -83,7 +84,7 @@ Module.register("MMM-Buttons", {
}
},

sendAction(description) {
sendAction: function(description) {
this.sendNotification(description.notification, description.payload);
},

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Here is full documentation of options for the modules configuration:
| `minShortPressTime` | Minimum duration to trigger a short press in `ms`. Default is `0`. |
| `maxShortPressTime` | Maximum duration to trigger a short press in `ms`. Default is `500`. |
| `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. |
| `bounceTimeout` | Duration to ignore bouncing (unintentional doubble press on the button). |

### Button Configuration

Expand Down
21 changes: 16 additions & 5 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,31 @@ module.exports = NodeHelper.create({

return function (err, value) {
if (value == 1) {
self.buttons[index].pressed = new Date().getTime();
var start = new Date().getTime();
if (self.buttons[index].downBounceTimeoutEnd > start) {
// We're bouncing!
return;
}

self.buttons[index].pressed = start;
self.buttons[index].downBounceTimeoutEnd = start + self.config.bounceTimeout;
self.sendSocketNotification("BUTTON_DOWN", {
index: index
});
setTimeout(self.watchHandler(index), self.config.minLongPressTime, undefined, 0);
return;
}
if (value == 0 && self.buttons[index].pressed !== undefined) {
var start = self.buttons[index].pressed;
var end = new Date().getTime();
var time = end - start;
var end = new Date().getTime();
if (self.buttons[index].upBounceTimeoutEnd > end) {
// We're bouncing!
return;
}

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

var time = end - start;
self.sendSocketNotification("BUTTON_UP", {
index: index,
duration: time
Expand All @@ -58,7 +69,7 @@ module.exports = NodeHelper.create({
intializeButton: function(index) {
const self = this;

var options = { persistentWatch: true };
var options = { persistentWatch: true , activeLow: !!self.buttons[index].activeLow};

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

0 comments on commit f201a10

Please sign in to comment.