forked from balassy/MMM-ModuleToggleButton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
30 lines (25 loc) · 939 Bytes
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* MagicMirror Module: MMM-ModuleToggleButton (https://github.com/balassy/MMM-ModuleToggleButton)
* By György Balássy (https://www.linkedin.com/in/balassy)
* MIT Licensed.
*/
const NodeHelper = require('node_helper'); // eslint-disable-line import/no-extraneous-dependencies
const Gpio = require('onoff').Gpio;
module.exports = NodeHelper.create({
start() {
this.started = false;
},
socketNotificationReceived(notification, payload) {
if (notification === 'TOGGLE_BUTTON_CONFIG' && !this.started) {
const self = this;
this.config = payload;
const button = new Gpio(this.config.buttonGpioPin, 'in', 'both', { persistentWatch: true, debounceTimeout: this.config.debounceTimeoutInMilliseconds });
button.watch((err, state) => {
if (state === 1) {
self.sendSocketNotification(self.config.notificationName, true);
}
});
this.started = true;
}
}
});