gpio retry failing pin connection

This commit is contained in:
Dave Conway-Jones 2022-07-14 19:00:58 +01:00
parent c32823a85a
commit c9f57afe22
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 50 additions and 42 deletions

View File

@ -45,8 +45,7 @@ module.exports = function(RED) {
}
}
if (allOK === true) {
if (node.pin !== undefined) {
var startPin = function() {
node.child = spawn(gpioCommand, ["in",node.pin,node.intype,node.debounce]);
node.running = true;
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.running = false;
node.child = null;
node.child.removeAllListeners();
delete node.child;
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.finished();
}
@ -84,7 +87,11 @@ module.exports = function(RED) {
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
else { node.error(RED._("rpi-gpio.errors.error",{error:err.errno})) }
});
}
if (allOK === true) {
if (node.pin !== undefined) {
startPin();
}
else {
node.warn(RED._("rpi-gpio.errors.invalidpin")+": "+node.pin);
@ -109,8 +116,9 @@ module.exports = function(RED) {
if (node.child != null) {
node.finished = done;
node.child.stdin.write("close "+node.pin, () => {
if (node.child) {
node.child.kill('SIGKILL');
setTimeout(function() { if (done) { done(); } }, 25);
}
});
}
else { if (done) { done(); } }
@ -214,7 +222,7 @@ module.exports = function(RED) {
node.finished = done;
node.child.stdin.write("close "+node.pin, () => {
node.child.kill('SIGKILL');
setTimeout(function() { if (done) { done(); } }, 25);
setTimeout(function() { if (done) { done(); } }, 50);
});
}
else { if (done) { done(); } }

View File

@ -1,6 +1,6 @@
{
"name": "node-red-node-pi-gpio",
"version": "2.0.4",
"version": "2.0.5",
"description": "The basic Node-RED node for Pi GPIO",
"dependencies" : {
},