-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathnode_helper.js
More file actions
81 lines (65 loc) · 2.01 KB
/
node_helper.js
File metadata and controls
81 lines (65 loc) · 2.01 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
'use strict';
/* Magic Mirror
* Module: MMM-PIR-Sensor
*
* By Paul-Vincent Roll http://paulvincentroll.com
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
const exec = require('child_process').exec;
module.exports = NodeHelper.create({
start: function () {
this.started = false
this.isMonitorOn(function(result){
console.log("monitor on: " + result);
});
},
activateMonitor: function () {
var _this = this;
this.isMonitorOn(function(result){
if (!result){
exec("/opt/vc/bin/tvservice --preferred && sudo chvt 6 && sudo chvt 7", null);
console.log('monitor has been activated');
}
});
this.started = false;
},
deactivateMonitor: function () {
this.isMonitorOn(function(result){
if (result){
exec("/opt/vc/bin/tvservice -o", null);
console.log('monitor has been deactivated');
}
});
this.started = false;
},
isMonitorOn: function(resultCallback){
//exec("/opt/vc/bin/tvservice -o", null);
exec('/opt/vc/bin/tvservice -s', function(err, out, code) {
var e = err;
var o = out;
var c = code;
if (out.indexOf('0x120002') > 0) {
resultCallback(false);
}
else {
resultCallback(true);
}
console.log("monitor :" + out);
});
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function (notification, payload) {
const self = this;
if (notification === 'MOTION_DETECTED' && this.started == false) {
const self = this;
this.started = true;
this.activateMonitor();
}
if (notification === 'DEACTIVATE_MONITOR' && this.started == false) {
const self = this;
this.started = true;
this.deactivateMonitor();
}
}
});