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

Tweaks to hardware nodes to throw not laoded exceptions correctly.

This commit is contained in:
Dave C-J 2014-04-08 15:54:08 +01:00
parent 36bbddffe5
commit 5a9cfb3425
3 changed files with 19 additions and 30 deletions

View File

@ -18,13 +18,6 @@
var RED = require(process.env.NODE_RED_HOME + "/red/red");
var bonescript = require("bonescript");
// Require bonescript
//try {
// var bonescript = require("bonescript");
//} catch (err) {
// require("util").log("[145-BBB-hardware] Error: cannot find module 'bonescript'");
//}
// Node constructor for bbb-analogue-in
function AnalogueInputNode(n) {
// Create a RED node

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('[36-rpi-gpio.js] Error: Cannot find Wiring-Pi "gpio" command. http://wiringpi.com/download-and-install/');
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
throw "Info : Ignoring Raspberry Pi specific node.";
}
// else not on a Pi so don't worry anyone with needless messages.
});
return;
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)
@ -94,6 +92,10 @@ function PibrellaIn(n) {
else {
this.error("Invalid GPIO pin: "+this.pin);
}
this.on("close", function() {
clearInterval(this._interval);
});
}
function PibrellaOut(n) {
@ -142,6 +144,10 @@ function PibrellaOut(n) {
else {
this.error("Invalid GPIO pin: "+this.pin);
}
this.on("close", function() {
exec("gpio mode "+this.pin+" in");
});
}
exec("gpio mode 0 out",function(err,stdout,stderr) {
@ -159,17 +165,8 @@ exec("gpio mode 0 out",function(err,stdout,stderr) {
exec("gpio mode 11 in");
exec("gpio mode 12 in");
exec("gpio mode 13 in");
exec("gpio mode 14 in",function(err,stdout,stderr) {
exec("gpio mode 14 in");
});
RED.nodes.registerType("rpi-pibrella in",PibrellaIn);
RED.nodes.registerType("rpi-pibrella out",PibrellaOut);
PibrellaIn.prototype.close = function() {
clearInterval(this._interval);
}
PibrellaOut.prototype.close = function() {
exec("gpio mode "+this.pin+" in");
}
});
});

View File

@ -20,8 +20,7 @@ var fs = require('fs');
// check if /dev/ledborg exists - if not then don't even show the node.
if (!fs.existsSync("/dev/ledborg")) {
//util.log("[78-ledborg.js] Warning: PiBorg hardware : LedBorg not found");
return;
throw "Info : PiBorg hardware : LedBorg not found";
}
function LedBorgNode(n) {