1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

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 LedBorgInUse = false;
var gpioCommand = __dirname+'/nrgpio'; var gpioCommand = __dirname+'/nrgpio';
var allOK = true;
try { try {
var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString(); 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) { catch(err) {
throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); RED.log.warn("ledborg : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
} allOK = false;
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.";
} }
// GPIO pins 11 (R), 13 (G), 15 (B). // GPIO pins 11 (R), 13 (G), 15 (B).
@ -95,46 +98,50 @@ module.exports = function(RED) {
} }
} }
node.child = spawn(gpioCommand, ["borg","11"]); if (allOK === true) {
node.running = true; node.child = spawn(gpioCommand, ["borg","11"]);
node.status({fill:"green",shape:"dot",text:"OK"}); 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) { node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); } if (RED.settings.verbose) { node.log("out: "+data+" :"); }
}); });
node.child.stderr.on('data', function (data) { node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); } if (RED.settings.verbose) { node.log("err: "+data+" :"); }
}); });
node.child.on('close', function () { node.child.on('close', function () {
node.child = null; node.child = null;
node.running = false; node.running = false;
node.status({fill:"red",shape:"circle",text:""}); 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.done(); }
}); });
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.warn('Command not found'); }
else if (err.errno === "EACCES") { node.warn('Command not executable'); } else if (err.errno === "EACCES") { node.warn('Command not executable'); }
else { node.log('error: ' + err); } 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; LedBorgInUse = false;
node.status({fill:"red",shape:"circle",text:""}); node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
if (node.child != null) { }
node.done = done;
node.child.stdin.write(" close 11");
node.child.kill('SIGKILL');
}
else { done(); }
});
} }
RED.nodes.registerType("ledborg",LedBorgNode); RED.nodes.registerType("ledborg",LedBorgNode);
} }

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-ledborg", "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.", "description" : "A Node-RED node to control a PiBorg LedBorg board for a Raspberry Pi.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pilcd", "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.", "description" : "A Node-RED node for Raspberry Pi to write to HD44780 style LCD panels.",
"dependencies" : { "dependencies" : {
}, },

View File

@ -6,20 +6,26 @@ module.exports = function(RED) {
var fs = require('fs'); var fs = require('fs');
var gpioCommand = __dirname + '/nrlcd'; var gpioCommand = __dirname + '/nrlcd';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi try {
//util.log("Info : Ignoring Raspberry Pi specific node."); var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
throw "Info : Ignoring Raspberry Pi specific node."; 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;
}
} }
catch(err) {
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) { RED.log.warn("rpi-lcd : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
util.log("[rpi-lcd] Info : Can't find Pi RPi.GPIO python library."); allOK = false;
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.";
} }
function PiLcdNode(n) { function PiLcdNode(n) {
@ -33,54 +39,61 @@ module.exports = function(RED) {
else { node.warn("Command not running"); } else { node.warn("Command not running"); }
} }
if (node.pins !== undefined) { if (allOK === true) {
node.child = spawn(gpioCommand, [node.pins]); if (node.pins !== undefined) {
node.running = true; node.child = spawn(gpioCommand, [node.pins]);
if (RED.settings.verbose) { node.log("pin: " + node.pins + " :"); } node.running = true;
node.on("input", inputlistener); if (RED.settings.verbose) { node.log("pin: " + node.pins + " :"); }
node.on("input", inputlistener);
node.child.stdout.on('data', function(data) { node.child.stdout.on('data', function(data) {
if (RED.settings.verbose) { node.log("out: " + 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 { 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); RED.nodes.registerType("rpi-lcd", PiLcdNode);
} }

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-piliter", "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.", "description" : "A Node-RED node to drive a Raspberry Pi Pi-LITEr 8 LED board.",
"dependencies" : { "dependencies" : {
}, },

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pisrf", "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", "description" : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder",
"dependencies" : { "dependencies" : {
}, },

View File

@ -6,20 +6,26 @@ module.exports = function(RED) {
var fs = require('fs'); var fs = require('fs');
var gpioCommand = __dirname + '/nrsrf.py'; var gpioCommand = __dirname + '/nrsrf.py';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi try {
//util.log("Info : Ignoring Raspberry Pi specific node."); var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
throw "Info : Ignoring Raspberry Pi specific node."; 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;
}
} }
catch(err) {
if (!fs.existsSync("/usr/share/doc/python-rpi.gpio")) { RED.log.warn("rpi-srf : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
util.log("[rpi-srf] Info : Can't find Pi RPi.GPIO python library."); allOK = false;
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.";
} }
function PiSrfNode(n) { function PiSrfNode(n) {
@ -29,56 +35,60 @@ module.exports = function(RED) {
this.pins += ","+(n.pulse || 0.5); this.pins += ","+(n.pulse || 0.5);
var node = this; var node = this;
if (node.pins !== undefined) { if (allOK === true) {
node.child = spawn(gpioCommand, [node.pins]); if (node.pins !== undefined) {
node.running = true; node.child = spawn(gpioCommand, [node.pins]);
if (RED.settings.verbose) { node.log("parameters: " + node.pins + " :"); } node.running = true;
if (RED.settings.verbose) { node.log("parameters: " + node.pins + " :"); }
node.child.stdout.on('data', function(data) { node.child.stdout.on('data', function(data) {
if (RED.settings.verbose) { node.log("out: " + data + " :"); } if (RED.settings.verbose) { node.log("out: " + data + " :"); }
data = data.toString().trim(); data = data.toString().trim();
if (data.length > 0) { if (data.length > 0) {
node.send({topic:node.topic, payload:data}); 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) { node.on("close", function(done) {
if (RED.settings.verbose) { node.log("err: " + data + " :"); } 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 { 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); RED.nodes.registerType("rpi-srf", PiSrfNode);
} }

View File

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

View File

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

View File

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

View File

@ -99,14 +99,15 @@ module.exports = function(RED) {
var PiGPIO; var PiGPIO;
function inputlistener(msg) { function inputlistener(msg) {
if (!inerror) { if (msg.payload === "true") { msg.payload = true; }
if (msg.payload === "true") { msg.payload = true; } if (msg.payload === "false") { msg.payload = false; }
if (msg.payload === "false") { msg.payload = false; } var out = Number(msg.payload);
var out = Number(msg.payload); var limit = 1;
var limit = 1; if (node.out !== "out") { limit = 100; }
if (node.out !== "out") { limit = 100; } var pre = "";
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 (!inerror) {
if (node.out === "out") { if (node.out === "out") {
PiGPIO.write(node.pin, msg.payload); PiGPIO.write(node.pin, msg.payload);
} }
@ -119,8 +120,11 @@ module.exports = function(RED) {
} }
node.status({fill:"green",shape:"dot",text:msg.payload.toString()}); 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) { if (node.pin !== undefined) {

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-pi-unicorn-hat", "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.", "description" : "A Node-RED node to output to a Raspberry Pi Unicorn HAT from Pimorini.",
"dependencies" : { "dependencies" : {
"pngjs": "2.2.*" "pngjs": "2.2.*"

View File

@ -7,20 +7,26 @@ module.exports = function(RED) {
var execSync = require('child_process').execSync; var execSync = require('child_process').execSync;
var hatCommand = __dirname+'/unihat'; var hatCommand = __dirname+'/unihat';
var allOK = true;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi try {
//RED.log.info(RED._("rpi-gpio.errors.ignorenode")); var cpuinfo = fs.readFileSync("/proc/cpuinfo").toString();
throw "Info : "+RED._("rpi-gpio.errors.ignorenode"); 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;
}
} }
catch(err) {
if (execSync('python -c "import neopixel"').toString() !== "") { RED.log.warn("rpi-unicorn : "+RED._("node-red:rpi-gpio.errors.ignorenode"));
RED.log.warn("Can't find neopixel python library"); allOK = false;
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");
} }
// the magic to make python print stuff immediately // the magic to make python print stuff immediately
@ -208,52 +214,57 @@ module.exports = function(RED) {
else { node.warn("Input not a string"); } else { node.warn("Input not a string"); }
} }
node.child = spawn(hatCommand, [node.bright]); if (allOK === true) {
node.status({fill:"green",shape:"dot",text:"ok"}); 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) { node.child.stdout.on('data', function (data) {
if (RED.settings.verbose) { node.log("out: "+data+" :"); } if (RED.settings.verbose) { node.log("out: "+data+" :"); }
}); });
node.child.stderr.on('data', function (data) { node.child.stderr.on('data', function (data) {
if (RED.settings.verbose) { node.log("err: "+data+" :"); } if (RED.settings.verbose) { node.log("err: "+data+" :"); }
}); });
node.child.on('close', function () { node.child.on('close', function () {
node.child = null; node.child = null;
if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); } if (RED.settings.verbose) { node.log(RED._("rpi-gpio.status.closed")); }
if (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.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.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"}); } nowready();
}); }
else {
node.child.on('error', function (err) { node.status({fill:"grey",shape:"dot",text:"node-red:rpi-gpio.status.not-available"});
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();
} }
RED.nodes.registerType("rpi-unicorn",UnicornHatNode); RED.nodes.registerType("rpi-unicorn",UnicornHatNode);
} }