mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Bit more consistent error handling / status updates for Pi GPIO node
This commit is contained in:
parent
07acc6642f
commit
a22f819f40
@ -57,7 +57,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((pinsInUse[this.pin] !== this.intype)||(pinsInUse[this.pin] === "pwm")) {
|
if ((pinsInUse[this.pin] !== this.intype)||(pinsInUse[this.pin] === "pwm")) {
|
||||||
node.error("GPIO pin "+this.pin+" already set as "+pinTypes[pinsInUse[this.pin]]);
|
node.warn("GPIO pin "+this.pin+" already set as "+pinTypes[pinsInUse[this.pin]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,24 +89,27 @@ module.exports = function(RED) {
|
|||||||
node.child.on('close', function (code) {
|
node.child.on('close', function (code) {
|
||||||
node.child = null;
|
node.child = null;
|
||||||
node.running = false;
|
node.running = false;
|
||||||
node.status({fill:"red",shape:"circle",text:""});
|
|
||||||
if (RED.settings.verbose) { node.log("closed"); }
|
if (RED.settings.verbose) { node.log("closed"); }
|
||||||
if (node.done) { node.done(); }
|
if (node.done) {
|
||||||
|
node.status({fill:"grey",shape:"ring",text:"closed"});
|
||||||
|
node.done();
|
||||||
|
}
|
||||||
|
else { node.status({fill:"red",shape:"ring",text:"stopped"}); }
|
||||||
});
|
});
|
||||||
|
|
||||||
node.child.on('error', function (err) {
|
node.child.on('error', function (err) {
|
||||||
if (err.errno === "ENOENT") { node.warn('Command not found'); }
|
if (err.errno === "ENOENT") { node.error('nrgpio command not found'); }
|
||||||
else if (err.errno === "EACCES") { node.warn('Command not executable'); }
|
else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); }
|
||||||
else { node.log('error: ' + err); }
|
else { node.log('error: ' + err); }
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.error("Invalid GPIO pin: "+node.pin);
|
node.warn("Invalid GPIO pin: "+node.pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.on("close", function(done) {
|
node.on("close", function(done) {
|
||||||
node.status({fill:"red",shape:"circle",text:""});
|
node.status({fill:"grey",shape:"ring",text:"close"});
|
||||||
delete pinsInUse[node.pin];
|
delete pinsInUse[node.pin];
|
||||||
if (node.child != null) {
|
if (node.child != null) {
|
||||||
node.done = done;
|
node.done = done;
|
||||||
@ -131,7 +134,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((pinsInUse[this.pin] !== this.out)||(pinsInUse[this.pin] === "pwm")) {
|
if ((pinsInUse[this.pin] !== this.out)||(pinsInUse[this.pin] === "pwm")) {
|
||||||
node.error("GPIO pin "+this.pin+" already set as "+pinTypes[pinsInUse[this.pin]]);
|
node.warn("GPIO pin "+this.pin+" already set as "+pinTypes[pinsInUse[this.pin]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,10 +146,15 @@ module.exports = function(RED) {
|
|||||||
if (node.out === "pwm") { limit = 100; }
|
if (node.out === "pwm") { limit = 100; }
|
||||||
if ((out >= 0) && (out <= limit)) {
|
if ((out >= 0) && (out <= limit)) {
|
||||||
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
|
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
|
||||||
if (node.child !== null) { node.child.stdin.write(msg.payload+"\n"); }
|
if (node.child !== null) {
|
||||||
else { node.warn("Command not running"); }
|
node.child.stdin.write(msg.payload+"\n");
|
||||||
node.status({fill:"green",shape:"dot",text:msg.payload});
|
node.status({fill:"green",shape:"dot",text:msg.payload});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
node.error("nrpgio python command not running");
|
||||||
|
node.status({fill:"red",shape:"ring",text:"not running"});
|
||||||
|
}
|
||||||
|
}
|
||||||
else { node.warn("Invalid input: "+out); }
|
else { node.warn("Invalid input: "+out); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,24 +180,27 @@ module.exports = function(RED) {
|
|||||||
node.child.on('close', function (code) {
|
node.child.on('close', function (code) {
|
||||||
node.child = null;
|
node.child = null;
|
||||||
node.running = false;
|
node.running = false;
|
||||||
node.status({fill:"red",shape:"circle",text:""});
|
|
||||||
if (RED.settings.verbose) { node.log("closed"); }
|
if (RED.settings.verbose) { node.log("closed"); }
|
||||||
if (node.done) { node.done(); }
|
if (node.done) {
|
||||||
|
node.status({fill:"grey",shape:"ring",text:"closed"});
|
||||||
|
node.done();
|
||||||
|
}
|
||||||
|
else { node.status({fill:"red",shape:"ring",text:"stopped"}); }
|
||||||
});
|
});
|
||||||
|
|
||||||
node.child.on('error', function (err) {
|
node.child.on('error', function (err) {
|
||||||
if (err.errno === "ENOENT") { node.warn('Command not found'); }
|
if (err.errno === "ENOENT") { node.error('nrgpio ommand not found'); }
|
||||||
else if (err.errno === "EACCES") { node.warn('Command not executable'); }
|
else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); }
|
||||||
else { node.log('error: ' + err); }
|
else { node.log('error: ' + err); }
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
node.error("Invalid GPIO pin: "+node.pin);
|
node.warn("Invalid GPIO pin: "+node.pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.on("close", function(done) {
|
node.on("close", function(done) {
|
||||||
node.status({fill:"red",shape:"circle",text:""});
|
node.status({fill:"grey",shape:"ring",text:"close"});
|
||||||
delete pinsInUse[node.pin];
|
delete pinsInUse[node.pin];
|
||||||
if (node.child != null) {
|
if (node.child != null) {
|
||||||
node.done = done;
|
node.done = done;
|
||||||
@ -237,19 +248,22 @@ module.exports = function(RED) {
|
|||||||
node.child.on('close', function (code) {
|
node.child.on('close', function (code) {
|
||||||
node.child = null;
|
node.child = null;
|
||||||
node.running = false;
|
node.running = false;
|
||||||
node.status({fill:"red",shape:"circle",text:""});
|
|
||||||
if (RED.settings.verbose) { node.log("closed"); }
|
if (RED.settings.verbose) { node.log("closed"); }
|
||||||
if (node.done) { node.done(); }
|
if (node.done) {
|
||||||
|
node.status({fill:"grey",shape:"ring",text:"closed"});
|
||||||
|
node.done();
|
||||||
|
}
|
||||||
|
else { node.status({fill:"red",shape:"ring",text:"stopped"}); }
|
||||||
});
|
});
|
||||||
|
|
||||||
node.child.on('error', function (err) {
|
node.child.on('error', function (err) {
|
||||||
if (err.errno === "ENOENT") { node.warn('Command not found'); }
|
if (err.errno === "ENOENT") { node.error('nrgpio ommand not found'); }
|
||||||
else if (err.errno === "EACCES") { node.warn('Command not executable'); }
|
else if (err.errno === "EACCES") { node.error('nrgpio ommand not executable'); }
|
||||||
else { node.log('error: ' + err); }
|
else { node.log('error: ' + err); }
|
||||||
});
|
});
|
||||||
|
|
||||||
node.on("close", function(done) {
|
node.on("close", function(done) {
|
||||||
node.status({fill:"red",shape:"circle",text:""});
|
node.status({fill:"grey",shape:"ring",text:"close"});
|
||||||
if (node.child != null) {
|
if (node.child != null) {
|
||||||
node.done = done;
|
node.done = done;
|
||||||
node.child.kill('SIGINT');
|
node.child.kill('SIGINT');
|
||||||
|
@ -19,6 +19,10 @@ import sys
|
|||||||
|
|
||||||
bounce = 20 # bounce time in mS to apply
|
bounce = 20 # bounce time in mS to apply
|
||||||
|
|
||||||
|
if sys.version_info >= (3,0):
|
||||||
|
print("Sorry - currently only configured to work with python 2.x")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
cmd = sys.argv[1].lower()
|
cmd = sys.argv[1].lower()
|
||||||
pin = int(sys.argv[2])
|
pin = int(sys.argv[2])
|
||||||
|
Loading…
Reference in New Issue
Block a user