node-red-node-pi-gpio 2.0.4 → 2.0.6

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.js CHANGED
@@ -45,46 +45,59 @@ 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.code === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")+err.path,err); }
87
+ else if (err.code === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")+err.path,err); }
88
+ else { node.error(RED._("rpi-gpio.errors.error",{error:err.code}),err) }
89
+ });
90
+
91
+ node.child.stdin.on('error', function (err) {
92
+ if (!node.finished) {
93
+ node.error(RED._("rpi-gpio.errors.error",{error:err.code}),err);
94
+ }
95
+ });
96
+ }
87
97
 
98
+ if (allOK === true) {
99
+ if (node.pin !== undefined) {
100
+ startPin();
88
101
  }
89
102
  else {
90
103
  node.warn(RED._("rpi-gpio.errors.invalidpin")+": "+node.pin);
@@ -109,8 +122,9 @@ module.exports = function(RED) {
109
122
  if (node.child != null) {
110
123
  node.finished = done;
111
124
  node.child.stdin.write("close "+node.pin, () => {
112
- node.child.kill('SIGKILL');
113
- setTimeout(function() { if (done) { done(); } }, 25);
125
+ if (node.child) {
126
+ node.child.kill('SIGKILL');
127
+ }
114
128
  });
115
129
  }
116
130
  else { if (done) { done(); } }
@@ -190,11 +204,16 @@ module.exports = function(RED) {
190
204
  });
191
205
 
192
206
  node.child.on('error', function (err) {
193
- if (err.errno === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")); }
194
- else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
195
- else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); }
207
+ if (err.code === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")+err.path,err); }
208
+ else if (err.code === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")+err.path,err); }
209
+ else { node.error(RED._("rpi-gpio.errors.error",{error:err.code}),err) }
196
210
  });
197
211
 
212
+ node.child.stdin.on('error', function (err) {
213
+ if (!node.finished) {
214
+ node.error(RED._("rpi-gpio.errors.error",{error:err.code}),err);
215
+ }
216
+ });
198
217
  }
199
218
  else {
200
219
  node.warn(RED._("rpi-gpio.errors.invalidpin")+": "+node.pin);
@@ -214,7 +233,7 @@ module.exports = function(RED) {
214
233
  node.finished = done;
215
234
  node.child.stdin.write("close "+node.pin, () => {
216
235
  node.child.kill('SIGKILL');
217
- setTimeout(function() { if (done) { done(); } }, 25);
236
+ setTimeout(function() { if (done) { done(); } }, 50);
218
237
  });
219
238
  }
220
239
  else { if (done) { done(); } }
@@ -66,8 +66,8 @@
66
66
  "invalidinput": "Ungültige Eingabe",
67
67
  "needtobeexecutable": "__command__ muss ausführbar sein",
68
68
  "mustbeexecutable": "nrgpio muss ausführbar sein",
69
- "commandnotfound": "nrgpio-Befehl nicht gefunden",
70
- "commandnotexecutable": "nrgpio-Befehl nicht ausführbar",
69
+ "commandnotfound": "nrgpio-Befehl nicht gefunden ",
70
+ "commandnotexecutable": "nrgpio-Befehl nicht ausführbar ",
71
71
  "error": "Fehler: __error__",
72
72
  "pythoncommandnotfound": "nrgpio-Python-Befehl nicht aktiv"
73
73
  }
@@ -66,8 +66,8 @@
66
66
  "invalidinput": "Invalid input",
67
67
  "needtobeexecutable": "__command__ needs to be executable",
68
68
  "mustbeexecutable": "nrgpio must to be executable",
69
- "commandnotfound": "nrgpio command not found",
70
- "commandnotexecutable": "nrgpio command not executable",
69
+ "commandnotfound": "nrgpio command not found ",
70
+ "commandnotexecutable": "nrgpio command not executable ",
71
71
  "error": "error: __error__",
72
72
  "pythoncommandnotfound": "nrgpio python command not running"
73
73
  }
@@ -66,8 +66,8 @@
66
66
  "invalidinput": "入力が不正です",
67
67
  "needtobeexecutable": "__command__ は実行可能である必要があります",
68
68
  "mustbeexecutable": "nrgpio は実行可能である必要があります",
69
- "commandnotfound": "nrgpio コマンドが見つかりません",
70
- "commandnotexecutable": "nrgpio コマンドが実行可能ではありません",
69
+ "commandnotfound": "nrgpio コマンドが見つかりません ",
70
+ "commandnotexecutable": "nrgpio コマンドが実行可能ではありません ",
71
71
  "error": "エラー: __error__",
72
72
  "pythoncommandnotfound": "nrgpio python コマンドが実行されていません"
73
73
  }
@@ -65,8 +65,8 @@
65
65
  "invalidinput": "입력이 올바르지 않습니다",
66
66
  "needtobeexecutable": "__command__ 은 실행가능상태일 필요가 있습니다 ",
67
67
  "mustbeexecutable": "nrgpio 은 실행가능상태일 필요가 있습니다 ",
68
- "commandnotfound": "nrgpio 커맨드를 찾을수 없습니다",
69
- "commandnotexecutable": "nrgpio 커맨드가 실행가능상태가 아닙니다",
68
+ "commandnotfound": "nrgpio 커맨드를 찾을수 없습니다 ",
69
+ "commandnotexecutable": "nrgpio 커맨드가 실행가능상태가 아닙니다 ",
70
70
  "error": "에러: __error__",
71
71
  "pythoncommandnotfound": "nrgpio python 커맨드가 실행되지 않았습니다"
72
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-node-pi-gpio",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "The basic Node-RED node for Pi GPIO",
5
5
  "dependencies" : {
6
6
  },