diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba731a..372c56a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/MMM-Buttons.js b/MMM-Buttons.js index 42ff82e..3e24494 100644 --- a/MMM-Buttons.js +++ b/MMM-Buttons.js @@ -16,7 +16,8 @@ Module.register("MMM-Buttons", { buttons: [], minShortPressTime: 0, maxShortPressTime: 500, - minLongPressTime: 3000 + minLongPressTime: 3000, + bounceTimeout: 300 }, // Define start sequence. @@ -83,7 +84,7 @@ Module.register("MMM-Buttons", { } }, - sendAction(description) { + sendAction: function(description) { this.sendNotification(description.notification, description.payload); }, diff --git a/README.md b/README.md index b6f23ae..7190c1d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/node_helper.js b/node_helper.js index 8babf76..3312d34 100644 --- a/node_helper.js +++ b/node_helper.js @@ -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 @@ -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));