From 5a9cfb34259dfcd4f3fbd4e623765a87a1994d53 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Tue, 8 Apr 2014 15:54:08 +0100 Subject: [PATCH] Tweaks to hardware nodes to throw not laoded exceptions correctly. --- hardware/BBB/145-BBB-hardware.js | 7 ------ hardware/Pi/38-rpi-pibrella.js | 39 +++++++++++++++----------------- hardware/Pi/78-ledborg.js | 3 +-- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/hardware/BBB/145-BBB-hardware.js b/hardware/BBB/145-BBB-hardware.js index 4df3a04d..78ba7151 100644 --- a/hardware/BBB/145-BBB-hardware.js +++ b/hardware/BBB/145-BBB-hardware.js @@ -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 diff --git a/hardware/Pi/38-rpi-pibrella.js b/hardware/Pi/38-rpi-pibrella.js index f7d44279..1a254f3e 100644 --- a/hardware/Pi/38-rpi-pibrella.js +++ b/hardware/Pi/38-rpi-pibrella.js @@ -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) @@ -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) { - 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"); - } - - }); + exec("gpio mode 14 in"); }); + +RED.nodes.registerType("rpi-pibrella in",PibrellaIn); +RED.nodes.registerType("rpi-pibrella out",PibrellaOut); diff --git a/hardware/Pi/78-ledborg.js b/hardware/Pi/78-ledborg.js index 6e5eb20e..9aa6453e 100644 --- a/hardware/Pi/78-ledborg.js +++ b/hardware/Pi/78-ledborg.js @@ -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) {