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

Tidied up Pi Peripheral nodes - should now work alongside base GPIO node

This commit is contained in:
Dave C-J 2014-05-06 21:00:09 +01:00
parent 3a4f870257
commit 2b89241331
3 changed files with 40 additions and 50 deletions

View File

@ -19,14 +19,12 @@ var util = require("util");
var exec = require('child_process').exec;
var fs = require('fs');
if (!fs.existsSync("/usr/local/bin/gpio")) {
exec("cat /proc/cpuinfo | grep BCM27",function(err,stdout,stderr) {
if (stdout.indexOf('BCM27') > -1) {
util.log('[37-rpi-piface.js] Error: Cannot find Wiring-Pi "gpio" command');
}
// else not on a Pi so don't worry anyone with needless messages.
});
return;
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
throw "Info : Ignoring Raspberry Pi specific node.";
}
if (!fs.existsSync("/usr/local/bin/gpio")) { // gpio command not installed
throw "Info : Can't find Raspberry Pi wiringPi gpio command.";
}
// Map names of pins to Gordon's gpio PiFace pin numbers
@ -109,13 +107,16 @@ function PiFACEInNode(n) {
}
}
});
}, 250);
}, 200);
}
});
}
else {
node.error("Invalid PiFACE pin: "+node.pin);
}
node.on("close", function() {
clearInterval(node._interval);
});
}
function PiFACEOutNode(n) {
@ -141,21 +142,10 @@ function PiFACEOutNode(n) {
}
exec("gpio load spi",function(err,stdout,stderr) {
if (err) {
util.log('[37-rpi-piface.js] Error: "gpio load spi" command failed for some reason.');
}
exec("gpio -p reset",function(err,stdout,stderr) {
if (err) {
util.log('[37-rpi-piface.js] Error: "gpio -p reset" command failed for some reason.');
}
RED.nodes.registerType("rpi-piface in",PiFACEInNode);
RED.nodes.registerType("rpi-piface out",PiFACEOutNode);
PiFACEInNode.prototype.close = function() {
clearInterval(this._interval);
}
PiFACEOutNode.prototype.close = function() {
}
});
RED.nodes.registerType("rpi-piface in",PiFACEInNode);
RED.nodes.registerType("rpi-piface out",PiFACEOutNode);
});

View File

@ -18,7 +18,7 @@
<div class="form-row">
<label for="node-input-pin"><i class="icon-asterisk"></i> Input</label>
<select type="text" id="node-input-pin" style="width: 150px;">
<option value="-" disabled>select input</option>
<option value="-">select input</option>
<option value="Red Button">Red Button</option>
<option value="In A">In A</option>
<option value="In B">In B</option>
@ -64,7 +64,7 @@
<div class="form-row">
<label for="node-input-pin"><i class="icon-asterisk"></i> Output</label>
<select type="text" id="node-input-pin" style="width: 150px;">
<option value="-" disabled>select output</option>
<option value="-">select output</option>
<option value="Red LED">Red LED</option>
<option value="Amber LED">Amber LED</option>
<option value="Green LED">Green LED</option>

View File

@ -67,7 +67,7 @@ function PibrellaIn(n) {
this.pin = pintable[n.pin];
var node = this;
if (this.pin) {
if (node.pin) {
exec("gpio mode "+node.pin+" in", function(err,stdout,stderr) {
if (err) node.error(err);
else {
@ -90,11 +90,11 @@ function PibrellaIn(n) {
});
}
else {
this.error("Invalid GPIO pin: "+this.pin);
node.error("Invalid GPIO pin: "+node.pin);
}
this.on("close", function() {
clearInterval(this._interval);
node.on("close", function() {
clearInterval(node._interval);
});
}
@ -103,7 +103,7 @@ function PibrellaOut(n) {
this.pin = pintable[n.pin];
var node = this;
if (this.pin == "1") {
if (node.pin == "1") {
exec("gpio mode 1 pwm");
process.nextTick(function() {
exec("gpio pwm-ms");
@ -121,7 +121,7 @@ function PibrellaOut(n) {
});
});
}
else if (this.pin) {
else if (node.pin) {
process.nextTick(function() {
exec("gpio mode "+node.pin+" out", function(err,stdout,stderr) {
if (err) node.error(err);
@ -142,31 +142,31 @@ function PibrellaOut(n) {
});
}
else {
this.error("Invalid GPIO pin: "+this.pin);
node.error("Invalid GPIO pin: "+node.pin);
}
this.on("close", function() {
exec("gpio mode "+this.pin+" in");
node.on("close", function() {
exec("gpio mode "+node.pin+" in");
});
}
exec("gpio mode 0 out",function(err,stdout,stderr) {
if (err) {
util.log('[36-rpi-gpio.js] Error: "gpio" command failed for some reason.');
}
exec("gpio mode 1 out");
exec("gpio mode 2 out");
exec("gpio mode 3 out");
exec("gpio mode 4 out");
exec("gpio mode 5 out");
exec("gpio mode 6 out");
exec("gpio mode 7 out");
exec("gpio mode 10 in");
exec("gpio mode 11 in");
exec("gpio mode 12 in");
exec("gpio mode 13 in");
exec("gpio mode 14 in");
});
//exec("gpio mode 0 out",function(err,stdout,stderr) {
//if (err) {
//util.log('[36-rpi-gpio.js] Error: "gpio" command failed for some reason.');
//}
//exec("gpio mode 1 out");
//exec("gpio mode 2 out");
//exec("gpio mode 3 out");
//exec("gpio mode 4 out");
//exec("gpio mode 5 out");
//exec("gpio mode 6 out");
//exec("gpio mode 7 out");
//exec("gpio mode 10 in");
//exec("gpio mode 11 in");
//exec("gpio mode 12 in");
//exec("gpio mode 13 in");
//exec("gpio mode 14 in");
//});
RED.nodes.registerType("rpi-pibrella in",PibrellaIn);
RED.nodes.registerType("rpi-pibrella out",PibrellaOut);