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

Tweak to Pi GPIO node to throw exceptions more in line with latest thinking

This commit is contained in:
Dave C-J 2014-04-08 16:04:13 +01:00
parent d784889b75
commit e38b321c33

View File

@ -19,14 +19,12 @@ var util = require("util");
var exec = require('child_process').exec; var exec = require('child_process').exec;
var fs = require('fs'); var fs = require('fs');
if (!fs.existsSync("/usr/local/bin/gpio")) { if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
exec("cat /proc/cpuinfo | grep BCM27",function(err,stdout,stderr) { throw "Info : Ignoring Raspberry Pi specific node.";
if (stdout.indexOf('BCM27') > -1) { }
util.log('[36-rpi-gpio.js] Error: Cannot find Wiring-Pi "gpio" command. http://wiringpi.com/download-and-install/');
} if (!fs.existsSync("/usr/local/bin/gpio")) { // gpio command not installed
// else not on a Pi so don't worry anyone with needless messages. throw "Info : Can't find Raspberry Pi wiringPi gpio command.";
});
return;
} }
// Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant) // Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant)
@ -103,6 +101,10 @@ function GPIOInNode(n) {
else { else {
this.error("Invalid GPIO pin: "+this.pin); this.error("Invalid GPIO pin: "+this.pin);
} }
this.on("close", function() {
clearInterval(this._interval);
});
} }
function GPIOOutNode(n) { function GPIOOutNode(n) {
@ -133,6 +135,10 @@ function GPIOOutNode(n) {
else { else {
this.error("Invalid GPIO pin: "+this.pin); this.error("Invalid GPIO pin: "+this.pin);
} }
this.on("close", function() {
exec("gpio mode "+this.pin+" in");
});
} }
exec("gpio mode 0 in",function(err,stdout,stderr) { exec("gpio mode 0 in",function(err,stdout,stderr) {
@ -145,17 +151,8 @@ exec("gpio mode 0 in",function(err,stdout,stderr) {
exec("gpio mode 4 in"); exec("gpio mode 4 in");
exec("gpio mode 5 in"); exec("gpio mode 5 in");
exec("gpio mode 6 in"); exec("gpio mode 6 in");
exec("gpio mode 7 in",function(err,stdout,stderr) { exec("gpio mode 7 in");
RED.nodes.registerType("rpi-gpio in",GPIOInNode);
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
GPIOInNode.prototype.close = function() {
clearInterval(this._interval);
}
GPIOOutNode.prototype.close = function() {
exec("gpio mode "+this.pin+" in");
}
});
}); });
RED.nodes.registerType("rpi-gpio in",GPIOInNode);
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);