-
Notifications
You must be signed in to change notification settings - Fork 2
/
MMM-MotionControl.js
116 lines (103 loc) · 2.82 KB
/
MMM-MotionControl.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* Magic Mirror
* Module: MMM-MotionControl
*
* By Thierry Nischelwitzer http://nischi.ch
* MIT Licensed.
*/
Module.register('MMM-MotionControl', {
defaults: {
delay: 15000,
interval: 5000,
useFacialRecognitionOCV3: false,
useMMMFaceRecoDNN: false,
ontime: [],
},
timeout: null,
getScripts: function() {
return ['moment.js'];
},
start: function() {
var self = this;
if (this.config.useMMMFaceRecoDNN === true) {
setInterval(function() {
self.sendNotification('GET_LOGGED_IN_USERS');
}, this.config.interval);
}
},
inOnTime: function() {
var inOnTime = false;
this.config.ontime.forEach(time => {
var split = time.split('-');
var from = moment()
.startOf('day')
.add(split[0].substr(0, 2), 'h')
.add(split[0].substr(2, 2), 'm');
var to = moment()
.startOf('day')
.add(split[1].substr(0, 2), 'h')
.add(split[1].substr(2, 2), 'm');
if (moment().isBetween(from, to)) {
inOnTime = true;
}
});
return inOnTime;
},
notificationReceived: function(notification, payload, sender) {
if (this.inOnTime()) {
this.sendNotification('CECControl', 'on');
} else {
if (this.config.useFacialRecognitionOCV3 === true) {
this.handleFacialRecognitionOCV3(notification, payload, sender);
}
if (this.config.useMMMFaceRecoDNN === true) {
this.handleFaceRecoDNN(notification, payload, sender);
}
}
},
handleFacialRecognitionOCV3: function(notification, payload, sender) {
var _self = this;
if (notification === 'CURRENT_USER') {
Log.log(
this.name +
' received a module notification: ' +
notification +
' with payload ' +
payload
);
if (payload === 'None') {
if (_self.timeout === null) {
_self.timeout = setTimeout(function() {
_self.sendNotification('CECControl', 'off');
}, this.config.delay);
}
} else {
clearTimeout(_self.timeout);
_self.timeout = null;
_self.sendNotification('CECControl', 'on');
}
}
},
handleFaceRecoDNN: function(notification, payload, sender) {
var _self = this;
if (notification === 'LOGGED_IN_USERS') {
Log.log(
this.name +
' received a module notification: ' +
notification +
' with payload ' +
payload.length
);
if (payload.length === 0) {
if (_self.timeout === null) {
_self.timeout = setTimeout(function() {
_self.sendNotification('CECControl', 'off');
}, this.config.delay);
}
} else {
clearTimeout(_self.timeout);
_self.timeout = null;
_self.sendNotification('CECControl', 'on');
}
}
},
});