-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnode_helper.js
38 lines (31 loc) · 1.17 KB
/
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
31
32
33
34
35
36
37
38
var NodeHelper = require("node_helper");
var pin = 4;
module.exports = NodeHelper.create({
start: function() {
this.config = null;
this.lastPressedTime = null;
},
socketNotificationReceived: function(notification, payload) {
if(notification === 'SET_CONFIG'){
this.config = payload;
if(this.config['enableRaspberryButton']){
var Gpio = require('onoff').Gpio,
button = new Gpio(pin, 'in', 'both');
process.on('SIGINT', function () {
button.unexport();
process.exit();
});
var self = this;
button.watch(function (err, value) {
if (err) { throw err; }
if(value === 1){
if(self.lastPressedTime === null || (self.lastPressedTime !== null && (new Date() - self.lastPressedTime) > 2000)){
self.lastPressedTime = new Date();
self.sendSocketNotification('ALEXA_START_RECORDING', {});
}
}
});
}
}
},
});