diff --git a/hardware/BBB/144-analog-in.html b/hardware/BBB/144-analog-in.html
index 319da5b8..7fc547a3 100644
--- a/hardware/BBB/144-analog-in.html
+++ b/hardware/BBB/144-analog-in.html
@@ -14,72 +14,59 @@
limitations under the License.
-->
-
-
-
-
-
-
-
-
+
diff --git a/hardware/BBB/144-analog-in.js b/hardware/BBB/144-analog-in.js
index bd5a6679..aa97eee1 100644
--- a/hardware/BBB/144-analog-in.js
+++ b/hardware/BBB/144-analog-in.js
@@ -19,9 +19,9 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red");
// Require bonescript
try {
- var bs = require("bonescript");
-} catch(err) {
- require("util").log("[BBB-analog-in] Error: cannot find module 'bonescript'");
+ var bonescript = require("bonescript");
+} catch (err) {
+ require("util").log("[144-analog-in] Error: cannot find module 'bonescript'");
}
// The main node definition - most things happen in here
@@ -33,30 +33,28 @@ function AnalogInputNode(n) {
this.topic = n.topic;
this.pin = n.pin;
- // Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
- // otherwise there is only one 'node' for all instances of AnalogInputNode!)
+ // Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential -
+ // otherwise there is only one global 'node' for all instances of AnalogInputNode!)
var node = this;
- // A callback function variable seems to be more reliable than a lambda ?!
- var cbFun = function (x) {
- var msg = {};
- msg.topic = node.topic;
- msg.payload = x.value;
- if (isNaN(x.value)) {
- this.log(x.err);
- }
- node.send(msg);
- };
+ // A callback function variable seems to be more reliable than a lambda ?!
+ var readCallback = function (x) {
+ var msg = {};
+ msg.topic = node.topic;
+ msg.payload = x.value;
+ if (isNaN(x.value)) {
+ node.log(x.err);
+ }
+ node.send(msg);
+ };
- // If we have a valid pin, set the input event handler to Bonescript's analogRead
- if (["P9_39", "P9_40", "P9_37", "P9_38", "P9_33", "P9_36", "P9_35"].indexOf(node.pin) >= 0) {
- node.on("input", function (msg) { bs.analogRead(node.pin, cbFun) });
- } else {
- node.error("Unconfigured input pin");
- }
+ // If we have a valid pin, set the input event handler to Bonescript's analogRead
+ if (["P9_39", "P9_40", "P9_37", "P9_38", "P9_33", "P9_36", "P9_35"].indexOf(node.pin) >= 0) {
+ node.on("input", function (msg) { bonescript.analogRead(node.pin, readCallback) });
+ } else {
+ node.error("Unconfigured input pin");
+ }
}
// Register the node by name. This must be called before overriding any of the Node functions.
-RED.nodes.registerType("BBB-analog-in", AnalogInputNode);
-
-// AnalogInputNode.prototype.close = function () { };
+RED.nodes.registerType("analog-in", AnalogInputNode);
diff --git a/hardware/BBB/145-digital-in.html b/hardware/BBB/145-digital-in.html
index a4d2d251..8dcca48e 100644
--- a/hardware/BBB/145-digital-in.html
+++ b/hardware/BBB/145-digital-in.html
@@ -14,8 +14,7 @@
limitations under the License.
-->
-
-
+
-
+
-
-
+
diff --git a/hardware/BBB/145-digital-in.js b/hardware/BBB/145-digital-in.js
index 1d489182..886a8cde 100644
--- a/hardware/BBB/145-digital-in.js
+++ b/hardware/BBB/145-digital-in.js
@@ -19,7 +19,7 @@ var RED = require(process.env.NODE_RED_HOME + "/red/red");
// Require bonescript
try {
- var bs = require("bonescript");
+ var bonescript = require("bonescript");
} catch (err) {
require("util").log("[145-digital-in] Error: cannot find module 'bonescript'");
}
@@ -119,31 +119,31 @@ function DiscreteInputNode(n) {
"P9_15", "P9_16", "P9_17", "P9_18", "P9_21", "P9_22", "P9_23", "P9_24", "P9_26",
"P9_27", "P9_30", "P9_41", "P9_42"].indexOf(node.pin) >= 0) {
setTimeout(function () {
- bs.pinMode(node.pin, bs.INPUT);
- bs.digitalRead(node.pin, function (x) {
- // Initialise the currentState and lastActveTime variables based on the value read
- node.log("digitalRead: x.value = " + x.value);
- node.log("digitalRead: node.currentState = " + node.currentState);
- node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
- node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
- node.currentState = x.value - 0;
- node.log("First read - currentState: " + node.currentState);
- if (node.currentState === node.activeState) {
- node.lastActiveTime = Date.now();
- }
- // Attempt to attach a change-of-state interrupt handler to the pin. If we succeed,
- // set the input event and interval handlers, then send an initial message with the
- // pin state on the first output
- if (bs.attachInterrupt(node.pin, true, bs.CHANGE, interruptCallback)) {
- node.interruptAttached = true;
- node.on("input", inputCallback);
- node.intervalId = setInterval(timerCallback, node.updateInterval);
- } else {
- node.error("Failed to attach interrupt");
- }
- setTimeout(function () { node.emit("input", {}); }, 50);
- });
- }, 50);
+ bonescript.pinMode(node.pin, bonescript.INPUT);
+ bonescript.digitalRead(node.pin, function (x) {
+ // Initialise the currentState and lastActveTime variables based on the value read
+ node.log("digitalRead: x.value = " + x.value);
+ node.log("digitalRead: node.currentState = " + node.currentState);
+ node.log("digitalRead: node.totalActiveTime = " + node.totalActiveTime);
+ node.log("digitalRead: node.lastActiveTime = " + node.lastActiveTime);
+ node.currentState = x.value - 0;
+ node.log("First read - currentState: " + node.currentState);
+ if (node.currentState === node.activeState) {
+ node.lastActiveTime = Date.now();
+ }
+ // Attempt to attach a change-of-state interrupt handler to the pin. If we succeed,
+ // set the input event and interval handlers, then send an initial message with the
+ // pin state on the first output
+ if (bonescript.attachInterrupt(node.pin, true, bonescript.CHANGE, interruptCallback)) {
+ node.interruptAttached = true;
+ node.on("input", inputCallback);
+ node.intervalId = setInterval(timerCallback, node.updateInterval);
+ } else {
+ node.error("Failed to attach interrupt");
+ }
+ setTimeout(function () { node.emit("input", {}); }, 50);
+ });
+ }, 50);
} else {
node.error("Unconfigured input pin");
}
@@ -155,7 +155,7 @@ RED.nodes.registerType("discrete-in", DiscreteInputNode);
// On close, detach the interrupt (if we attached one) and clear the interval (if we set one)
DiscreteInputNode.prototype.close = function () {
if (this.interruptAttached) {
- bs.detachInterrupt(this.pin);
+ bonescript.detachInterrupt(this.pin);
}
if (this.intervalId !== null) {
clearInterval(this.intervalId);