Allow a bunch of Pi nodes to be visible but not active when used not on a Pi

This commit is contained in:
Dave Conway-Jones 2018-04-15 11:24:56 +01:00
parent ace67b0154
commit acc2dc1a14
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
15 changed files with 428 additions and 355 deletions

View File

@ -8,23 +8,26 @@ module.exports = function(RED) {
var LedBorgInUse = false;
var gpioCommand = __dirname+'/nrgpio';
var allOK = true;
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
if (cpuinfo.indexOf(": BCM") === -1) {
RED.log.warn("ledborg : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
RED.log.warn("ledborg : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
allOK = false;
}
else if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
RED.log.warn("ledborg : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand}));
allOK = false;
}
}
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
util.log("[rpi-ledborg] Info : Can't find RPi.GPIO python library.");
throw "Warning : Can't find RPi.GPIO python library.";
}
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
util.log("[rpi-ledborg] Error : "+gpioCommand+" needs to be executable.");
throw "Error : nrgpio must to be executable.";
RED.log.warn("ledborg : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
// GPIO pins 11 (R), 13 (G), 15 (B).
@ -95,46 +98,50 @@ module.exports = function(RED) {
}
}
node.child = spawn(gpioCommand, ["borg","11"]);
node.running = true;
node.status({fill:"green",shape:"dot",text:"OK"});
if (allOK === true) {
node.child = spawn(gpioCommand, ["borg","11"]);
node.running = true;
node.status({fill:"green",shape:"dot",text:"OK"});
node.on("input", inputlistener);
node.on("input", inputlistener);
node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
});
node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
});
node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
});
node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
});
node.child.on('close', function () {
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(); }
});
node.child.on('close', function () {
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(); }
});
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'); }
else { node.log('error: ' + err); }
});
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'); }
else { node.log('error: ' + err); }
});
node.on("close", function(done) {
node.on("close", function(done) {
LedBorgInUse = false;
node.status({fill:"red",shape:"circle",text:""});
if (node.child != null) {
node.done = done;
node.child.stdin.write(" close 11");
node.child.kill('SIGKILL');
}
else { done(); }
});
}
else {
LedBorgInUse = false;
node.status({fill:"red",shape:"circle",text:""});
if (node.child != null) {
node.done = done;
node.child.stdin.write(" close 11");
node.child.kill('SIGKILL');
}
else { done(); }
});
node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
}
}
RED.nodes.registerType("ledborg",LedBorgNode);
}

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-ledborg",
"version" : "0.0.18",
"version" : "0.0.19",
"description" : "A Node-RED node to control a PiBorg LedBorg board for a Raspberry Pi.",
"dependencies" : {
},

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pilcd",
"version" : "0.0.8",
"version" : "0.0.9",
"description" : "A Node-RED node for Raspberry Pi to write to HD44780 style LCD panels.",
"dependencies" : {
},

View File

@ -6,20 +6,26 @@ module.exports = function(RED) {
var fs = require('fs');
var gpioCommand = __dirname + '/nrlcd';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");
throw "Info : Ignoring Raspberry Pi specific node.";
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) {
RED.log.warn("rpi-lcd : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
RED.log.warn("rpi-lcd : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
allOK = false;
}
else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
RED.log.warn("rpi-lcd : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand}));
allOK = false;
}
}
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
util.log("[rpi-lcd] Info : Can't find Pi RPi.GPIO python library.");
throw "Warning : Can't find Pi RPi.GPIO python library.";
}
if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
util.log("[rpi-lcd] Error : " + gpioCommand + " needs to be executable.");
throw "Error : " + gpioCommand + " must to be executable.";
catch(err) {
RED.log.warn("rpi-lcd : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
function PiLcdNode(n) {
@ -33,54 +39,61 @@ module.exports = function(RED) {
else { node.warn("Command not running"); }
}
if (node.pins !== undefined) {
node.child = spawn(gpioCommand, [node.pins]);
node.running = true;
if (RED.settings.verbose) { node.log("pin: " + node.pins + " :"); }
node.on("input", inputlistener);
if (allOK === true) {
if (node.pins !== undefined) {
node.child = spawn(gpioCommand, [node.pins]);
node.running = true;
if (RED.settings.verbose) { node.log("pin: " + node.pins + " :"); }
node.on("input", inputlistener);
node.child.stdout.on('data', function(data) {
if (RED.settings.verbose) { node.log("out: " + data + " :"); }
node.child.stdout.on('data', function(data) {
if (RED.settings.verbose) { node.log("out: " + data + " :"); }
});
node.child.stderr.on('data', function(data) {
if (RED.settings.verbose) { node.log("err: " + data + " :"); }
});
node.child.on('close', function(code) {
if (RED.settings.verbose) { node.log("ret: " + code + " :"); }
node.child = null;
node.running = false;
});
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'); }
else { node.log('error: ' + err); }
});
}
else {
node.error("Invalid GPIO pins: " + node.pin);
}
var wfi = function(done) {
if (!node.running) {
if (RED.settings.verbose) { node.log("end"); }
done();
return;
}
setTimeout(function() { wfi(done); }, 333);
}
node.on("close", function(done) {
if (node.child != null) {
node.child.stdin.write("c:lose" + node.pin);
node.child.kill('SIGKILL');
}
wfi(done);
});
node.child.stderr.on('data', function(data) {
if (RED.settings.verbose) { node.log("err: " + data + " :"); }
});
node.child.on('close', function(code) {
if (RED.settings.verbose) { node.log("ret: " + code + " :"); }
node.child = null;
node.running = false;
});
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'); }
else { node.log('error: ' + err); }
});
}
else {
node.error("Invalid GPIO pins: " + node.pin);
node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
node.on("input", function(msg){
node.status({fill:"grey",shape:"dot",text:RED._("node-red:rpi-gpio.status.na",{value:msg.payload.toString()})});
});
}
var wfi = function(done) {
if (!node.running) {
if (RED.settings.verbose) { node.log("end"); }
done();
return;
}
setTimeout(function() { wfi(done); }, 333);
}
node.on("close", function(done) {
if (node.child != null) {
node.child.stdin.write("c:lose" + node.pin);
node.child.kill('SIGKILL');
}
wfi(done);
});
}
RED.nodes.registerType("rpi-lcd", PiLcdNode);
}

View File

@ -6,20 +6,26 @@ module.exports = function(RED) {
var fs = require('fs');
var gpioCommand = __dirname+'/nrgpio.py';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");
throw "Info : Ignoring Raspberry Pi specific node.";
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) {
RED.log.warn("rpi-liter : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
RED.log.warn("rpi-liter : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
allOK = false;
}
else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
RED.log.warn("rpi-liter : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand}));
allOK = false;
}
}
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
util.log("[rpi-gpio] Info : Can't find Pi RPi.GPIO python library.");
throw "Warning : Can't find Pi RPi.GPIO python library.";
}
if ( !(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
util.log("[rpi-gpio] Error : "+gpioCommand+" needs to be executable.");
throw "Error : " + gpioCommand + " must to be executable.";
catch(err) {
RED.log.warn("rpi-liter : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
function PiLiter(n) {
@ -28,75 +34,80 @@ module.exports = function(RED) {
this.dir = (n.dir ? 1 : 0) || 0;
var node = this;
if (this.pinv === "bar") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = Number(msg.payload);
if ((out >= 1) && (out <= 8)) { out = Math.pow(2, out) - 1; }
else { out = 0; }
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
});
}
else if (this.pinv === "meter") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = Number(msg.payload);
if ((out >= 1) && (out <= 8)) { out = Math.pow(2, (out-1)); }
else { out = 0; }
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
});
}
else if (this.pinv === "all") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = msg.payload;
if ((out === 1)|(out === true)|(out === "1")|(out === "on")) {
out = 255;
}
else { out = 0; }
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
});
}
else if (this.pinv === "pin") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
var byte = 0;
node.on("input", function(msg) {
if (typeof msg.payload === "object") {
var out = Number(msg.payload.led);
var l = Number(msg.payload.state);
if ((out >= 1) && (out <= 8)) {
out = (Math.pow(2, (out-1)));
if (l === 0) { byte = (byte & (~out) & 255); }
else { byte = (byte | out) & 255; }
if (node.child !== null) { node.child.stdin.write(byte+"\n"); }
else { node.warn("Command not running"); }
if (allOK === true) {
if (this.pinv === "bar") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = Number(msg.payload);
if ((out >= 1) && (out <= 8)) { out = Math.pow(2, out) - 1; }
else { out = 0; }
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
});
}
else if (this.pinv === "meter") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = Number(msg.payload);
if ((out >= 1) && (out <= 8)) { out = Math.pow(2, (out-1)); }
else { out = 0; }
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
});
}
else if (this.pinv === "all") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = msg.payload;
if ((out === 1)|(out === true)|(out === "1")|(out === "on")) {
out = 255;
}
else { out = 0; }
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
});
}
else if (this.pinv === "pin") {
node.child = spawn(gpioCommand, ["byte",node.dir]);
var byte = 0;
node.on("input", function(msg) {
if (typeof msg.payload === "object") {
var out = Number(msg.payload.led);
var l = Number(msg.payload.state);
if ((out >= 1) && (out <= 8)) {
out = (Math.pow(2, (out-1)));
if (l === 0) { byte = (byte & (~out) & 255); }
else { byte = (byte | out) & 255; }
if (node.child !== null) { node.child.stdin.write(byte+"\n"); }
else { node.warn("Command not running"); }
}
else { node.warn("Not a valid object - see Info panel."); }
}
else { node.warn("Not a valid object - see Info panel."); }
});
}
else {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = Number(msg.payload);
if ((out >= 0) && (out <= 255)) {
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
}
else { node.warn("Invalid input - not between 0 and 255"); }
});
}
node.on("close", function() {
if (node.child != null) {
node.child.kill('SIGKILL');
}
else { node.warn("Not a valid object - see Info panel."); }
if (RED.settings.verbose) { node.log("end"); }
});
}
else {
node.child = spawn(gpioCommand, ["byte",node.dir]);
node.on("input", function(msg) {
var out = Number(msg.payload);
if ((out >= 0) && (out <= 255)) {
if (node.child !== null) { node.child.stdin.write(out+"\n"); }
else { node.warn("Command not running"); }
}
else { node.warn("Invalid input - not between 0 and 255"); }
});
node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
}
node.on("close", function() {
if (node.child != null) {
node.child.kill('SIGKILL');
}
if (RED.settings.verbose) { node.log("end"); }
});
}
RED.nodes.registerType("rpi-liter",PiLiter);
}

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-piliter",
"version" : "0.0.11",
"version" : "0.0.12",
"description" : "A Node-RED node to drive a Raspberry Pi Pi-LITEr 8 LED board.",
"dependencies" : {
},

View File

@ -31,7 +31,7 @@ def Measure():
# else:
# print("Echo start detected")
start = time.time()
GPIO.wait_for_edge(ECHO, GPIO.BOTH, timeout=400)
if channel is None:
print("Ultrasonic sensor timed out (post-echo).")
@ -40,7 +40,7 @@ def Measure():
# else:
# print("Echo finish detected")
stop = time.time()
elapsed = stop-start
distance = (elapsed * 34300)/2 # Using speed of sound at 20C (68F)

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pisrf",
"version" : "0.1.0",
"version" : "0.1.1",
"description" : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder",
"dependencies" : {
},

View File

@ -6,20 +6,26 @@ module.exports = function(RED) {
var fs = require('fs');
var gpioCommand = __dirname + '/nrsrf.py';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//util.log("Info : Ignoring Raspberry Pi specific node.");
throw "Info : Ignoring Raspberry Pi specific node.";
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
allOK = false;
}
else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:gpioCommand}));
allOK = false;
}
}
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
util.log("[rpi-srf] Info : Can't find Pi RPi.GPIO python library.");
throw "Warning : Can't find Pi RPi.GPIO python library.";
}
if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
util.log("[rpi-srf] Error : " + gpioCommand + " needs to be executable.");
throw "Error : " + gpioCommand + " must to be executable.";
catch(err) {
RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
function PiSrfNode(n) {
@ -29,56 +35,60 @@ module.exports = function(RED) {
this.pins += ","+(n.pulse || 0.5);
var node = this;
if (node.pins !== undefined) {
node.child = spawn(gpioCommand, [node.pins]);
node.running = true;
if (RED.settings.verbose) { node.log("parameters: " + node.pins + " :"); }
if (allOK === true) {
if (node.pins !== undefined) {
node.child = spawn(gpioCommand, [node.pins]);
node.running = true;
if (RED.settings.verbose) { node.log("parameters: " + node.pins + " :"); }
node.child.stdout.on('data', function(data) {
if (RED.settings.verbose) { node.log("out: " + data + " :"); }
data = data.toString().trim();
if (data.length > 0) {
node.send({topic:node.topic, payload:data});
node.child.stdout.on('data', function(data) {
if (RED.settings.verbose) { node.log("out: " + data + " :"); }
data = data.toString().trim();
if (data.length > 0) {
node.send({topic:node.topic, payload:data});
}
});
node.child.stderr.on('data', function(data) {
if (RED.settings.verbose) { node.log("err: " + data + " :"); }
});
node.child.on('close', function(code) {
if (RED.settings.verbose) { node.log("ret: " + code + " :"); }
node.child = null;
node.running = false;
});
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'); }
else { node.log('error: ' + err); }
});
}
else {
node.error("Invalid Parameters: " + node.pins);
}
var wfi = function(done) {
if (!node.running) {
if (RED.settings.verbose) { node.log("end"); }
done();
return;
}
});
setTimeout(function() { wfi(done); }, 333);
}
node.child.stderr.on('data', function(data) {
if (RED.settings.verbose) { node.log("err: " + data + " :"); }
node.on("close", function(done) {
if (node.child != null) {
node.child.kill('SIGKILL');
}
wfi(done);
});
node.child.on('close', function(code) {
if (RED.settings.verbose) { node.log("ret: " + code + " :"); }
node.child = null;
node.running = false;
});
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'); }
else { node.log('error: ' + err); }
});
}
else {
node.error("Invalid Parameters: " + node.pins);
node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
}
var wfi = function(done) {
if (!node.running) {
if (RED.settings.verbose) { node.log("end"); }
done();
return;
}
setTimeout(function() { wfi(done); }, 333);
}
node.on("close", function(done) {
if (node.child != null) {
node.child.kill('SIGKILL');
}
wfi(done);
});
}
RED.nodes.registerType("rpi-srf", PiSrfNode);
}

View File

@ -6,23 +6,26 @@ module.exports = function(RED) {
var fs = require('fs');
var colors = require('./colours.js');
var piCommand = __dirname+'/neopix';
var allOK = true;
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) { throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); }
if (cpuinfo.indexOf(": BCM") === -1) {
RED.log.warn("rpi-neopixels : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (execSync('python -c "import neopixel"').toString() !== "") {
RED.log.warn("rpi-neopixels : Can't find neopixel python library");
allOK = false;
}
else if (!(1 & parseInt ((fs.statSync(piCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
RED.log.warn("rpi-neopixels : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:piCommand}));
allOK = false;
}
}
catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
}
if (execSync('python -c "import neopixel"').toString() !== "") {
RED.log.warn("Can't find neopixel python library");
throw "Warning : Can't find neopixel python library";
}
if ( !(1 & parseInt ((fs.statSync(piCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
RED.log.error(piCommand + " command is not executable");
throw "Error : "+RED._("rpi-gpio.errors.mustbeexecutable");
RED.log.warn("rpi-neopixels : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
// the magic to make python print stuff immediately
@ -110,57 +113,70 @@ module.exports = function(RED) {
}
}
<<<<<<< Updated upstream
node.child = spawn(piCommand, [node.pixels, node.wipe, node.mode, node.brightness, node.gamma]);
node.status({fill:"green",shape:"dot",text:"ok"});
||||||| merged common ancestors
node.child = spawn(piCommand, [node.pixels, node.wipe, node.mode]);
node.status({fill:"green",shape:"dot",text:"ok"});
=======
if (allOK === true) {
node.child = spawn(piCommand, [node.pixels, node.wipe, node.mode]);
node.status({fill:"green",shape:"dot",text:"ok"});
>>>>>>> Stashed changes
node.on("input", inputlistener);
node.on("input", inputlistener);
node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
});
node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
});
node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
});
node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
});
node.child.on('close', function () {
node.child = null;
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
if (node.done) {
node.child.on('close', function () {
node.child = null;
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
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.error(RED._("rpi-gpio.errors.commandnotfound")); }
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); }
});
node.on("close", function(done) {
node.status({fill:"grey",shape:"ring",text:"closed"});
node.done();
}
else { node.status({fill:"red",shape:"ring",text:"stopped"}); }
});
if (node.child != null) {
node.done = done;
node.child.kill('SIGKILL');
}
else { done(); }
});
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")); }
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); }
});
node.on("close", function(done) {
node.status({fill:"grey",shape:"ring",text:"closed"});
if (node.child != null) {
node.done = done;
node.child.kill('SIGKILL');
if (node.bgnd) {
if (node.bgnd.split(',').length === 1) {
node.bgnd = colors.getRGB(node.bgnd,node.rgb);
}
if (node.mode.indexOf("shift") === -1) {
node.child.stdin.write(node.bgnd+"\n");
}
}
else { done(); }
});
if (node.bgnd) {
if (node.bgnd.split(',').length === 1) {
node.bgnd = colors.getRGB(node.bgnd,node.rgb);
}
if (node.mode.indexOf("shift") === -1) {
node.child.stdin.write(node.bgnd+"\n");
if (node.fgnd) {
if (node.fgnd.split(',').length === 1) {
node.fgnd = colors.getRGB(node.fgnd,node.rgb);
}
}
}
if (node.fgnd) {
if (node.fgnd.split(',').length === 1) {
node.fgnd = colors.getRGB(node.fgnd,node.rgb);
}
else {
node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
}
}
RED.nodes.registerType("rpi-neopixels",PiNeopixelNode);

View File

@ -1,11 +1,12 @@
{
"name": "node-red-node-pi-neopixel",
"version": "0.0.17",
"description": "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
"dependencies": {},
"repository": {
"type": "git",
"url": "https://github.com/node-red/node-red-nodes/tree/master/hardware/neopixel"
"name" : "node-red-node-pi-neopixel",
"version" : "0.0.17",
"description" : "A Node-RED node to output to a neopixel (ws2812) string of LEDS from a Raspberry Pi.",
"dependencies" : {
},
"repository" : {
"type":"git",
"url":"https://github.com/node-red/node-red-nodes/tree/master/hardware/neopixel"
},
"license": "Apache-2.0",
"keywords": [

View File

@ -1,6 +1,6 @@
{
"name": "node-red-node-pi-gpiod",
"version": "0.0.9",
"version": "0.0.10",
"description": "A node-red node for PiGPIOd",
"dependencies" : {
"js-pigpio": "*"

View File

@ -99,14 +99,15 @@ module.exports = function(RED) {
var PiGPIO;
function inputlistener(msg) {
if (!inerror) {
if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload);
var limit = 1;
if (node.out !== "out") { limit = 100; }
if ((out >= 0) && (out <= limit)) {
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "false") { msg.payload = false; }
var out = Number(msg.payload);
var limit = 1;
if (node.out !== "out") { limit = 100; }
var pre = "";
if ((out >= 0) && (out <= limit)) {
if (RED.settings.verbose) { node.log("out: "+msg.payload); }
if (!inerror) {
if (node.out === "out") {
PiGPIO.write(node.pin, msg.payload);
}
@ -119,8 +120,11 @@ module.exports = function(RED) {
}
node.status({fill:"green",shape:"dot",text:msg.payload.toString()});
}
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
else {
node.status({fill:"grey",shape:"ring",text:"N/C: " + msg.payload.toString()});
}
}
else { node.warn(RED._("pi-gpiod:errors.invalidinput")+": "+out); }
}
if (node.pin !== undefined) {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-pi-unicorn-hat",
"version" : "0.0.16",
"version" : "0.0.17",
"description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.",
"dependencies" : {
"pngjs": "2.2.*"

View File

@ -7,20 +7,26 @@ module.exports = function(RED) {
var execSync = require('child_process').execSync;
var hatCommand = __dirname+'/unihat';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
//RED.log.info(RED._("rpi-gpio.errors.ignorenode"));
throw "Info : "+RED._("rpi-gpio.errors.ignorenode");
try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
if (cpuinfo.indexOf(": BCM") === -1) {
RED.log.warn("rpi-unicorn : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
else if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) {
RED.log.warn("rpi-unicorn : "+RED._("node-red:rpi-gpio.errors.libnotfound"));
allOK = false;
}
else if (!(1 & parseInt ((fs.statSync(gpioCommand).mode & parseInt ("777", 8)).toString (8)[0]))) {
RED.log.warn("rpi-unicorn : "+RED._("node-red:rpi-gpio.errors.needtobeexecutable",{command:hatCommand}));
allOK = false;
}
}
if (execSync('python -c "import neopixel"').toString() !== "") {
RED.log.warn("Can't find neopixel python library");
throw "Warning : Can't find neopixel python library";
}
if ( !(1 & parseInt ((fs.statSync(hatCommand).mode & parseInt ("777", 8)).toString (8)[0]) )) {
RED.log.error(hatCommand + " command is not executable");
throw "Error : "+RED._("rpi-gpio.errors.mustbeexecutable");
catch(err) {
RED.log.warn("rpi-unicorn : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
allOK = false;
}
// the magic to make python print stuff immediately
@ -208,52 +214,57 @@ module.exports = function(RED) {
else { node.warn("Input not a string"); }
}
node.child = spawn(hatCommand, [node.bright]);
node.status({fill:"green",shape:"dot",text:"ok"});
if (allOK === true) {
node.child = spawn(hatCommand, [node.bright]);
node.status({fill:"green",shape:"dot",text:"ok"});
node.on("input", inputlistener);
node.on("input", inputlistener);
node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
});
node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); }
});
node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
});
node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); }
});
node.child.on('close', function () {
node.child = null;
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
if (node.done) {
node.child.on('close', function () {
node.child = null;
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
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.error(RED._("rpi-gpio.errors.commandnotfound")); }
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); }
});
node.on("close", function(done) {
node.status({fill:"grey",shape:"ring",text:"closed"});
node.done();
if (node.tout) { clearTimeout(node.tout); }
if (node.child != null) {
node.done = done;
node.child.kill('SIGKILL');
}
else { done(); }
});
var nowready = function() {
node.tout = setTimeout( function() {
if (ready) { inputlistener({payload:"0"}); }
else { nowready(); }
}, 100);
}
else { node.status({fill:"red",shape:"ring",text:"stopped"}); }
});
node.child.on('error', function (err) {
if (err.errno === "ENOENT") { node.error(RED._("rpi-gpio.errors.commandnotfound")); }
else if (err.errno === "EACCES") { node.error(RED._("rpi-gpio.errors.commandnotexecutable")); }
else { node.error(RED._("rpi-gpio.errors.error")+': ' + err.errno); }
});
node.on("close", function(done) {
node.status({fill:"grey",shape:"ring",text:"closed"});
if (node.tout) { clearTimeout(node.tout); }
if (node.child != null) {
node.done = done;
node.child.kill('SIGKILL');
}
else { done(); }
});
var nowready = function() {
node.tout = setTimeout( function() {
if (ready) { inputlistener({payload:"0"}); }
else { nowready(); }
}, 100);
nowready();
}
else {
node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
}
nowready();
}
RED.nodes.registerType("rpi-unicorn",UnicornHatNode);
}