Update BBB nodes to support Jessie

Fix to close #156
Now mandates octalbonescript so a minor version bump.
This commit is contained in:
Dave Conway-Jones 2016-01-01 14:38:39 +00:00
parent c2dc764965
commit 681bdae576
3 changed files with 55 additions and 61 deletions

46
hardware/BBB/145-BBB-hardware.js Executable file → Normal file
View File

@ -25,7 +25,6 @@ module.exports = function (RED) {
var usrLEDs = ["USR0", "USR1", "USR2", "USR3"];
// Load the hardware library and set up polymorphic functions to suit it. Prefer
// octalbonescript (faster & less buggy) but drop back to bonescript if not available
try {
bonescript = require("octalbonescript");
adjustName = function (pin) {
if (pin === "P8_7") {
@ -40,19 +39,6 @@ module.exports = function (RED) {
setPinMode = function (pin, direction, callback) {
bonescript.pinMode(pin, direction, callback);
}
} catch (e) {
try {
bonescript = require("bonescript");
adjustName = function (pin) {
return pin;
};
setPinMode = function (pin, direction, callback) {
bonescript.pinMode(pin, direction, undefined, undefined, undefined, callback);
}
} catch (er) {
throw "Info : Ignoring Beaglebone specific node.";
}
}
// Node constructor for bbb-analogue-in
function AnalogueInputNode(n) {
@ -78,7 +64,7 @@ module.exports = function (RED) {
// The callback function for analogRead. Accumulates the required number of
// measurements, then divides the total number, applies output scaling and
// sends the result
var analogReadCallback = function (x) {
var analogReadCallback = function (err, x) {
sum = sum + x.value;
count = count - 1;
if (count > 0) {
@ -153,7 +139,7 @@ module.exports = function (RED) {
// schedule a re-read of the input pin in 7ms time, and set the debouncing flag
// Note: if x has an 'attached' field and no 'value' field, the callback is reporting
// the success or failure of attaching the interrupt - we must handle this
var interruptCallback = function (x) {
var interruptCallback = function (err, x) {
if (x.value === undefined) {
if (x.attached === true) {
node.interruptAttached = true;
@ -179,7 +165,7 @@ module.exports = function (RED) {
// This function is called approx 7ms after a potential change-of-state which is
// being debounced. Terminate the debounce, and send a message if the state has
// actually changed
var debounceCallback = function (x) {
var debounceCallback = function (err, x) {
node.debounceTimer = null;
node.debouncing = false;
if (x.value !== undefined && node.currentState !== Number(x.value)) {
@ -261,7 +247,7 @@ module.exports = function (RED) {
process.nextTick(function () {
setPinMode(node._pin, bonescript.INPUT, function (response, pin) {
if (response.value === true) {
bonescript.digitalRead(node._pin, function (x) {
bonescript.digitalRead(node._pin, function (err, x) {
// Initialise the currentState and lastActiveTime variables based on the value read
node.currentState = Number(x.value);
if (node.currentState === node.activeState) {
@ -357,7 +343,7 @@ module.exports = function (RED) {
process.nextTick(function () {
setPinMode(node._pin, bonescript.INPUT, function (response, pin) {
if (response.value === true) {
bonescript.digitalRead(node._pin, function (x) {
bonescript.digitalRead(node._pin, function (err, x) {
// Initialise the currentState based on the value read
node.currentState = Number(x.value);
// Attempt to attach an interrupt handler to the pin. If we succeed,
@ -417,24 +403,25 @@ module.exports = function (RED) {
newState = !newState;
}
}
bonescript.digitalWrite(node._pin, newState ? 1 : 0);
bonescript.digitalWrite(node._pin, newState ? 1 : 0, function() {
node.send({topic: node.topic, payload: newState});
node.currentState = newState;
});
};
// If we have a valid pin, set it as an output and set the default state
if (gpioPins.concat(usrLEDs).indexOf(node.pin) >= 0) {
// Don't set up interrupts & intervals until after the close event handler has been installed
bonescript.detachInterrupt(node._pin);
if (node._pin) { bonescript.detachInterrupt(node._pin); }
process.nextTick(function () {
setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) {
if (response.value === true) {
if (response) {
node.error("Unable to set " + pin + " as output: " + response.err);
} else {
node.on("input", inputCallback);
setTimeout(function () {
bonescript.digitalWrite(node._pin, node.defaultState);
bonescript.digitalWrite(node._pin, node.defaultState, function() {});
}, 50);
} else {
node.error("Unable to set " + pin + " as output: " + response.err);
}
});
});
@ -477,15 +464,17 @@ module.exports = function (RED) {
if (node.retriggerable === false) {
if (node.pulseTimer === null) {
node.pulseTimer = setTimeout(endPulseCallback, time);
bonescript.digitalWrite(node._pin, node.pulseState);
bonescript.digitalWrite(node._pin, node.pulseState, function() {
node.send({topic: node.topic, payload: node.pulseState});
});
}
} else {
if (node.pulseTimer !== null) {
clearTimeout(node.pulseTimer);
} else {
bonescript.digitalWrite(node._pin, node.pulseState);
bonescript.digitalWrite(node._pin, node.pulseState, function() {
node.send({topic: node.topic, payload: node.pulseState});
});
}
node.pulseTimer = setTimeout(endPulseCallback, time);
}
@ -495,8 +484,9 @@ module.exports = function (RED) {
// At the end of the pulse, restore the default state and set the timer to null
var endPulseCallback = function () {
node.pulseTimer = null;
bonescript.digitalWrite(node._pin, node.defaultState);
bonescript.digitalWrite(node._pin, node.defaultState, function() {
node.send({topic: node.topic, payload: node.defaultState});
});
};
// If we have a valid pin, set it as an output and set the default state

View File

@ -1,22 +1,27 @@
node-red-node-beaglebone
========================
A set of <a href="http://nodered.org" target="_new">Node-RED</a> nodes to interface with the GPIO pins of a <a href="http://http://beagleboard.org/black/" target="_new">Beaglebone Black</a>.
A set of <a href="http://nodered.org" target="_new">Node-RED</a> nodes to
interface with the GPIO pins of a <a href="http://http://beagleboard.org/black/" target="_new">Beaglebone Black</a>.
Pre-requisites
--------------
Only of use on a BeagleboneBlack board. Should ideally be running the <a href="http://beagleboard.org/latest-images/" target="_new"> latest Debian</a> image - as that has node.js v0.10.x and the bonescript npm preinstalled.
it does also need <b>bonescript</b> - but this is also pre-installed so no need to mark as a dependency...
Only of use on a BeagleboneBlack board. Should ideally be running the
<a href="http://beagleboard.org/latest-images/" target="_new"> latest Debian</a>
images - as they have node.js v0.10.x preinstalled.
Install
-------
Run the following command in the root directory of your Node-RED install
For Debian **Jessie** with kernel 4.1 run the following command in the root
directory of your Node-RED install. This is usually `~/.node-red`
npm install node-red-node-beaglebone
v0.4 now also supports <a href="http://octalbonejs.com/" target="_new">OctaBoneScript</a> if installed.
For previous versions of Debian, for example **Wheezy** - use the older version
of this node.
npm install node-red-node-beaglebone@0.0.8
Usage
-----
@ -74,11 +79,9 @@ payloads > 0.5 are 'high' (1), payloads <= 0.5 are 'low' (0). Other payloads whi
evaluate to true are 'high', if not then 'low'. Selecting the Inverting checkbox will
switch the sense of the pin output.
If the Toggle state checkbox is checked, the message content is ignored: successive
messages cause the pin to toggle between 0 and 1.
The pin will be initially set to the given Startup state until the first message arrives:
the Inverting property is not applied to this value.

View File

@ -1,15 +1,16 @@
{
"name" : "node-red-node-beaglebone",
"version" : "0.0.8",
"version" : "0.1.0",
"description" : "A set of Node-RED nodes to interface to the GPIO pins of a Beaglebone Black board",
"dependencies" : {
"octalbonescript":"^1.1.*"
},
"repository" : {
"type":"git",
"url":"https://github.com/node-red/node-red-nodes/tree/master/hardware/BBB"
},
"license": "Apache-2.0",
"keywords": [ "node-red", "beagleboneblack", "beaglebone", "bbb" ],
"keywords": [ "node-red", "beagleboneblack", "beaglebone", "bbb", "octalbonescript" ],
"node-red" : {
"nodes" : {
"bbb": "145-BBB-hardware.js"