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:
parent
d784889b75
commit
e38b321c33
@ -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('[36-rpi-gpio.js] Error: Cannot find Wiring-Pi "gpio" command. http://wiringpi.com/download-and-install/');
|
||||
}
|
||||
// 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 physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant)
|
||||
@ -103,6 +101,10 @@ function GPIOInNode(n) {
|
||||
else {
|
||||
this.error("Invalid GPIO pin: "+this.pin);
|
||||
}
|
||||
|
||||
this.on("close", function() {
|
||||
clearInterval(this._interval);
|
||||
});
|
||||
}
|
||||
|
||||
function GPIOOutNode(n) {
|
||||
@ -133,6 +135,10 @@ function GPIOOutNode(n) {
|
||||
else {
|
||||
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) {
|
||||
@ -145,17 +151,8 @@ exec("gpio mode 0 in",function(err,stdout,stderr) {
|
||||
exec("gpio mode 4 in");
|
||||
exec("gpio mode 5 in");
|
||||
exec("gpio mode 6 in");
|
||||
exec("gpio mode 7 in",function(err,stdout,stderr) {
|
||||
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");
|
||||
}
|
||||
|
||||
});
|
||||
exec("gpio mode 7 in");
|
||||
});
|
||||
|
||||
RED.nodes.registerType("rpi-gpio in",GPIOInNode);
|
||||
RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
|
||||
|
Loading…
Reference in New Issue
Block a user