node-red-node-pi-gpio 2.0.2 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/36-rpi-gpio.html +1 -0
- package/36-rpi-gpio.js +52 -40
- package/package.json +1 -1
package/36-rpi-gpio.html
CHANGED
package/36-rpi-gpio.js
CHANGED
|
@@ -45,46 +45,53 @@ module.exports = function(RED) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
node.status({fill:"yellow",shape:"dot",text:"rpi-gpio.status.ok"});
|
|
48
|
+
var startPin = function() {
|
|
49
|
+
node.child = spawn(gpioCommand, ["in",node.pin,node.intype,node.debounce]);
|
|
50
|
+
node.running = true;
|
|
51
|
+
node.status({fill:"yellow",shape:"dot",text:"rpi-gpio.status.ok"});
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
node.buttonState = d[i];
|
|
62
|
-
node.status({fill:"green",shape:"dot",text:d[i]});
|
|
63
|
-
if (RED.settings.verbose) { node.log("out: "+d[i]+" :"); }
|
|
53
|
+
node.child.stdout.on('data', function (data) {
|
|
54
|
+
var d = data.toString().trim().split("\n");
|
|
55
|
+
for (var i = 0; i < d.length; i++) {
|
|
56
|
+
if (d[i] === '') { return; }
|
|
57
|
+
if (node.running && node.buttonState !== -1 && !isNaN(Number(d[i])) && node.buttonState !== d[i]) {
|
|
58
|
+
node.send({ topic:"gpio/"+node.pin, payload:Number(d[i]) });
|
|
64
59
|
}
|
|
65
|
-
|
|
60
|
+
node.buttonState = d[i];
|
|
61
|
+
node.status({fill:"green",shape:"dot",text:d[i]});
|
|
62
|
+
if (RED.settings.verbose) { node.log("out: "+d[i]+" :"); }
|
|
63
|
+
}
|
|
64
|
+
});
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
node.child.stderr.on('data', function (data) {
|
|
67
|
+
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
|
|
68
|
+
});
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
node.child.on('close', function (code) {
|
|
71
|
+
node.running = false;
|
|
72
|
+
node.child.removeAllListeners();
|
|
73
|
+
delete node.child;
|
|
74
|
+
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
|
|
75
|
+
if (!node.finished && code === 1) {
|
|
76
|
+
setTimeout(function() {startPin()}, 250);
|
|
77
|
+
}
|
|
78
|
+
else if (node.finished) {
|
|
79
|
+
node.status({fill:"grey",shape:"ring",text:"rpi-gpio.status.closed"});
|
|
80
|
+
node.finished();
|
|
81
|
+
}
|
|
82
|
+
else { node.status({fill:"red",shape:"ring",text:"rpi-gpio.status.stopped"}); }
|
|
83
|
+
});
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
node.child.on('error', function (err) {
|
|
86
|
+
if (err.errno === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")); }
|
|
87
|
+
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
|
|
88
|
+
else { node.error(RED._("rpi-gpio.errors.error",{error:err.errno})) }
|
|
89
|
+
});
|
|
90
|
+
}
|
|
87
91
|
|
|
92
|
+
if (allOK === true) {
|
|
93
|
+
if (node.pin !== undefined) {
|
|
94
|
+
startPin();
|
|
88
95
|
}
|
|
89
96
|
else {
|
|
90
97
|
node.warn(RED._("rpi-gpio.errors.invalidpin")+": "+node.pin);
|
|
@@ -108,10 +115,13 @@ module.exports = function(RED) {
|
|
|
108
115
|
delete pinsInUse[node.pin];
|
|
109
116
|
if (node.child != null) {
|
|
110
117
|
node.finished = done;
|
|
111
|
-
node.child.stdin.write("close "+node.pin)
|
|
112
|
-
|
|
118
|
+
node.child.stdin.write("close "+node.pin, () => {
|
|
119
|
+
if (node.child) {
|
|
120
|
+
node.child.kill('SIGKILL');
|
|
121
|
+
}
|
|
122
|
+
});
|
|
113
123
|
}
|
|
114
|
-
else { done(); }
|
|
124
|
+
else { if (done) { done(); } }
|
|
115
125
|
});
|
|
116
126
|
}
|
|
117
127
|
RED.nodes.registerType("rpi-gpio in",GPIOInNode);
|
|
@@ -210,10 +220,12 @@ module.exports = function(RED) {
|
|
|
210
220
|
delete pinsInUse[node.pin];
|
|
211
221
|
if (node.child != null) {
|
|
212
222
|
node.finished = done;
|
|
213
|
-
node.child.stdin.write("close "+node.pin)
|
|
214
|
-
|
|
223
|
+
node.child.stdin.write("close "+node.pin, () => {
|
|
224
|
+
node.child.kill('SIGKILL');
|
|
225
|
+
setTimeout(function() { if (done) { done(); } }, 50);
|
|
226
|
+
});
|
|
215
227
|
}
|
|
216
|
-
else { done(); }
|
|
228
|
+
else { if (done) { done(); } }
|
|
217
229
|
});
|
|
218
230
|
|
|
219
231
|
}
|