From a22f819f40193ca51e1d2a2c113df87edba59991 Mon Sep 17 00:00:00 2001 From: dceejay Date: Tue, 3 Feb 2015 17:22:32 +0000 Subject: [PATCH] Bit more consistent error handling / status updates for Pi GPIO node --- nodes/core/hardware/36-rpi-gpio.js | 58 ++++++++++++++++++------------ nodes/core/hardware/nrgpio.py | 4 +++ 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/nodes/core/hardware/36-rpi-gpio.js b/nodes/core/hardware/36-rpi-gpio.js index adf5674b5..3ad605676 100644 --- a/nodes/core/hardware/36-rpi-gpio.js +++ b/nodes/core/hardware/36-rpi-gpio.js @@ -57,7 +57,7 @@ module.exports = function(RED) { } else { 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 = null; node.running = false; - node.status({fill:"red",shape:"circle",text:""}); 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) { - if (err.errno === "ENOENT") { node.warn('Command not found'); } - else if (err.errno === "EACCES") { node.warn('Command not executable'); } + if (err.errno === "ENOENT") { node.error('nrgpio command not found'); } + else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); } else { node.log('error: ' + err); } }); } else { - node.error("Invalid GPIO pin: "+node.pin); + node.warn("Invalid GPIO pin: "+node.pin); } node.on("close", function(done) { - node.status({fill:"red",shape:"circle",text:""}); + node.status({fill:"grey",shape:"ring",text:"close"}); delete pinsInUse[node.pin]; if (node.child != null) { node.done = done; @@ -131,7 +134,7 @@ module.exports = function(RED) { } else { 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,9 +146,14 @@ module.exports = function(RED) { if (node.out === "pwm") { limit = 100; } if ((out >= 0) && (out <= limit)) { if (RED.settings.verbose) { node.log("out: "+msg.payload); } - if (node.child !== null) { node.child.stdin.write(msg.payload+"\n"); } - else { node.warn("Command not running"); } - node.status({fill:"green",shape:"dot",text:msg.payload}); + if (node.child !== null) { + node.child.stdin.write(msg.payload+"\n"); + 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); } } @@ -172,24 +180,27 @@ module.exports = function(RED) { node.child.on('close', function (code) { node.child = null; node.running = false; - node.status({fill:"red",shape:"circle",text:""}); 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) { - if (err.errno === "ENOENT") { node.warn('Command not found'); } - else if (err.errno === "EACCES") { node.warn('Command not executable'); } + if (err.errno === "ENOENT") { node.error('nrgpio ommand not found'); } + else if (err.errno === "EACCES") { node.error('nrgpio command not executable'); } else { node.log('error: ' + err); } }); } else { - node.error("Invalid GPIO pin: "+node.pin); + node.warn("Invalid GPIO pin: "+node.pin); } node.on("close", function(done) { - node.status({fill:"red",shape:"circle",text:""}); + node.status({fill:"grey",shape:"ring",text:"close"}); delete pinsInUse[node.pin]; if (node.child != null) { node.done = done; @@ -237,19 +248,22 @@ module.exports = function(RED) { node.child.on('close', function (code) { node.child = null; node.running = false; - node.status({fill:"red",shape:"circle",text:""}); 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) { - if (err.errno === "ENOENT") { node.warn('Command not found'); } - else if (err.errno === "EACCES") { node.warn('Command not executable'); } + if (err.errno === "ENOENT") { node.error('nrgpio ommand not found'); } + else if (err.errno === "EACCES") { node.error('nrgpio ommand not executable'); } else { node.log('error: ' + err); } }); node.on("close", function(done) { - node.status({fill:"red",shape:"circle",text:""}); + node.status({fill:"grey",shape:"ring",text:"close"}); if (node.child != null) { node.done = done; node.child.kill('SIGINT'); diff --git a/nodes/core/hardware/nrgpio.py b/nodes/core/hardware/nrgpio.py index 414f5fc5e..751f0e373 100755 --- a/nodes/core/hardware/nrgpio.py +++ b/nodes/core/hardware/nrgpio.py @@ -19,6 +19,10 @@ import sys 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: cmd = sys.argv[1].lower() pin = int(sys.argv[2])