mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
gpio retry failing pin connection
This commit is contained in:
parent
c32823a85a
commit
c9f57afe22
@ -45,8 +45,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allOK === true) {
|
var startPin = function() {
|
||||||
if (node.pin !== undefined) {
|
|
||||||
node.child = spawn(gpioCommand, ["in",node.pin,node.intype,node.debounce]);
|
node.child = spawn(gpioCommand, ["in",node.pin,node.intype,node.debounce]);
|
||||||
node.running = true;
|
node.running = true;
|
||||||
node.status({fill:"yellow",shape:"dot",text:"rpi-gpio.status.ok"});
|
node.status({fill:"yellow",shape:"dot",text:"rpi-gpio.status.ok"});
|
||||||
@ -70,9 +69,13 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.child.on('close', function (code) {
|
node.child.on('close', function (code) {
|
||||||
node.running = false;
|
node.running = false;
|
||||||
node.child = null;
|
node.child.removeAllListeners();
|
||||||
|
delete node.child;
|
||||||
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
|
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
|
||||||
if (node.finished) {
|
if (!node.finished && code === 1) {
|
||||||
|
setTimeout(function() {startPin()}, 250);
|
||||||
|
}
|
||||||
|
else if (node.finished) {
|
||||||
node.status({fill:"grey",shape:"ring",text:"rpi-gpio.status.closed"});
|
node.status({fill:"grey",shape:"ring",text:"rpi-gpio.status.closed"});
|
||||||
node.finished();
|
node.finished();
|
||||||
}
|
}
|
||||||
@ -84,7 +87,11 @@ module.exports = function(RED) {
|
|||||||
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
|
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
|
||||||
else { node.error(RED._("rpi-gpio.errors.error",{error:err.errno})) }
|
else { node.error(RED._("rpi-gpio.errors.error",{error:err.errno})) }
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allOK === true) {
|
||||||
|
if (node.pin !== undefined) {
|
||||||
|
startPin();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.warn(RED._("rpi-gpio.errors.invalidpin")+": "+node.pin);
|
node.warn(RED._("rpi-gpio.errors.invalidpin")+": "+node.pin);
|
||||||
@ -109,8 +116,9 @@ module.exports = function(RED) {
|
|||||||
if (node.child != null) {
|
if (node.child != null) {
|
||||||
node.finished = done;
|
node.finished = done;
|
||||||
node.child.stdin.write("close "+node.pin, () => {
|
node.child.stdin.write("close "+node.pin, () => {
|
||||||
|
if (node.child) {
|
||||||
node.child.kill('SIGKILL');
|
node.child.kill('SIGKILL');
|
||||||
setTimeout(function() { if (done) { done(); } }, 25);
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else { if (done) { done(); } }
|
else { if (done) { done(); } }
|
||||||
@ -214,7 +222,7 @@ module.exports = function(RED) {
|
|||||||
node.finished = done;
|
node.finished = done;
|
||||||
node.child.stdin.write("close "+node.pin, () => {
|
node.child.stdin.write("close "+node.pin, () => {
|
||||||
node.child.kill('SIGKILL');
|
node.child.kill('SIGKILL');
|
||||||
setTimeout(function() { if (done) { done(); } }, 25);
|
setTimeout(function() { if (done) { done(); } }, 50);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else { if (done) { done(); } }
|
else { if (done) { done(); } }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-pi-gpio",
|
"name": "node-red-node-pi-gpio",
|
||||||
"version": "2.0.4",
|
"version": "2.0.5",
|
||||||
"description": "The basic Node-RED node for Pi GPIO",
|
"description": "The basic Node-RED node for Pi GPIO",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user