From 2b89241331375d97b055803c8fb88e43aa40d4c5 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Tue, 6 May 2014 21:00:09 +0100 Subject: [PATCH] Tidied up Pi Peripheral nodes - should now work alongside base GPIO node --- hardware/Pi/37-rpi-piface.js | 34 ++++++++------------- hardware/Pi/38-rpi-pibrella.html | 4 +-- hardware/Pi/38-rpi-pibrella.js | 52 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 50 deletions(-) diff --git a/hardware/Pi/37-rpi-piface.js b/hardware/Pi/37-rpi-piface.js index f0e8fd66..17a1482f 100644 --- a/hardware/Pi/37-rpi-piface.js +++ b/hardware/Pi/37-rpi-piface.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('[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); }); diff --git a/hardware/Pi/38-rpi-pibrella.html b/hardware/Pi/38-rpi-pibrella.html index f949e8ab..ffbe3ac8 100644 --- a/hardware/Pi/38-rpi-pibrella.html +++ b/hardware/Pi/38-rpi-pibrella.html @@ -18,7 +18,7 @@
- + diff --git a/hardware/Pi/38-rpi-pibrella.js b/hardware/Pi/38-rpi-pibrella.js index 1a254f3e..ad2c3339 100644 --- a/hardware/Pi/38-rpi-pibrella.js +++ b/hardware/Pi/38-rpi-pibrella.js @@ -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);