Repository navigation
Expand file tree
/
Copy pathnode_helper.js
More file actions
executable file
·73 lines (63 loc) · 2.2 KB
/
Copy pathnode_helper.js
File metadata and controls
executable file
·73 lines (63 loc) · 2.2 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
'use strict';
const NodeHelper = require('node_helper');
const {PythonShell} = require('python-shell');
var pythonStarted = false
//var websockets = require("websockets");
module.exports = NodeHelper.create({
python_start: function () {
const self = this;
console.log("[" + self.name + "] starting python");
self.pyshell = new PythonShell('modules/' + this.name + '/python_scripts/center-display-combine_stdio.py', {args: [JSON.stringify(this.config)]});
self.pyshell.on('message', function (message) {
try {
var parsed_message = JSON.parse(message)
//console.log("[MSG " + self.name + "] " + parsed_message);
if (parsed_message.hasOwnProperty('status')){
console.log("[" + self.name + "] " + parsed_message.status);
}
}
catch(err) {
console.log("[" + self.name + "] a non json message received");
//console.log(message);
//console.log(err);
}
});
},
// Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
const self = this;
if(notification === 'CENTER_DISPLAY_CONFIG') {
this.config = payload
this.python_start();
}else if(notification === 'CENTER_DISPLAY'){
var data = {"SET": payload};
self.pyshell.send(JSON.stringify(data));
}else if (notification === 'DETECTED_GESTURES'){
self.pyshell.send(JSON.stringify(payload));
}else if (notification === 'DETECTED_OBJECTS'){
self.pyshell.send(JSON.stringify(payload));
}else if (notification === 'DETECTED_FACES'){
self.pyshell.send(JSON.stringify(payload));
}else if (notification === 'GESTURE_DET_FPS'){
var data = {"GESTURE_DET_FPS": payload};
self.pyshell.send(JSON.stringify(data));
}else if (notification === 'OBJECT_DET_FPS'){
var data = {"OBJECT_DET_FPS": payload};
self.pyshell.send(JSON.stringify(data));
}else if (notification === 'FACE_DET_FPS'){
var data = {"FACE_DET_FPS": payload};
self.pyshell.send(JSON.stringify(data));
};
},
stop: function() {
const self = this;
self.pyshell.childProcess.kill('SIGINT');
self.pyshell.end(function (err) {
if (err){
//throw err;
};
console.log('finished');
});
self.pyshell.childProcess.kill('SIGKILL');
}
});