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 CHANGED
@@ -1,5 +1,6 @@
1
1
  <style>
2
2
  .rpi-gpio-pinTable {
3
+ color: #555;
3
4
  width: 340px;
4
5
  display: inline-table;
5
6
  font-size: 13px;
package/36-rpi-gpio.js CHANGED
@@ -45,46 +45,53 @@ module.exports = function(RED) {
45
45
  }
46
46
  }
47
47
 
48
- if (allOK === true) {
49
- if (node.pin !== undefined) {
50
- node.child = spawn(gpioCommand, ["in",node.pin,node.intype,node.debounce]);
51
- node.running = true;
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
- node.child.stdout.on('data', function (data) {
55
- var d = data.toString().trim().split("\n");
56
- for (var i = 0; i < d.length; i++) {
57
- if (d[i] === '') { return; }
58
- if (node.running && node.buttonState !== -1 && !isNaN(Number(d[i])) && node.buttonState !== d[i]) {
59
- node.send({ topic:"gpio/"+node.pin, payload:Number(d[i]) });
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
- node.child.stderr.on('data', function (data) {
68
- if (RED.settings.verbose) { node.log("err: "+data+" :"); }
69
- });
66
+ node.child.stderr.on('data', function (data) {
67
+ if (RED.settings.verbose) { node.log("err: "+data+" :"); }
68
+ });
70
69
 
71
- node.child.on('close', function (code) {
72
- node.running = false;
73
- node.child = null;
74
- if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
75
- if (node.finished) {
76
- node.status({fill:"grey",shape:"ring",text:"rpi-gpio.status.closed"});
77
- node.finished();
78
- }
79
- else { node.status({fill:"red",shape:"ring",text:"rpi-gpio.status.stopped"}); }
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
- node.child.on('error', function (err) {
83
- if (err.errno === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")); }
84
- else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
85
- else { node.error(RED._("rpi-gpio.errors.error",{error:err.errno})) }
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
- node.child.kill('SIGKILL');
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
- node.child.kill('SIGKILL');
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-node-pi-gpio",
3
- "version": "2.0.2",
3
+ "version": "2.0.5",
4
4
  "description": "The basic Node-RED node for Pi GPIO",
5
5
  "dependencies" : {
6
6
  },