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

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

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

@ -25,34 +25,20 @@ module.exports = function (RED) {
var usrLEDs = ["USR0", "USR1", "USR2", "USR3"]; var usrLEDs = ["USR0", "USR1", "USR2", "USR3"];
// Load the hardware library and set up polymorphic functions to suit it. Prefer // 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 // octalbonescript (faster & less buggy) but drop back to bonescript if not available
try { bonescript = require("octalbonescript");
bonescript = require("octalbonescript"); adjustName = function (pin) {
adjustName = function (pin) { if (pin === "P8_7") {
if (pin === "P8_7") { pin = "P8_07";
pin = "P8_07"; } else if (pin === "P8_8") {
} else if (pin === "P8_8") { pin = "P8_08";
pin = "P8_08"; } else if (pin === "P8_9") {
} else if (pin === "P8_9") { pin = "P8_09";
pin = "P8_09"; }
} return pin;
return pin; };
}; setPinMode = function (pin, direction, callback) {
setPinMode = function (pin, direction, callback) { bonescript.pinMode(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 // Node constructor for bbb-analogue-in
function AnalogueInputNode(n) { function AnalogueInputNode(n) {
@ -78,7 +64,7 @@ module.exports = function (RED) {
// The callback function for analogRead. Accumulates the required number of // The callback function for analogRead. Accumulates the required number of
// measurements, then divides the total number, applies output scaling and // measurements, then divides the total number, applies output scaling and
// sends the result // sends the result
var analogReadCallback = function (x) { var analogReadCallback = function (err, x) {
sum = sum + x.value; sum = sum + x.value;
count = count - 1; count = count - 1;
if (count > 0) { 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 // 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 // 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 // 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.value === undefined) {
if (x.attached === true) { if (x.attached === true) {
node.interruptAttached = 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 // 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 // being debounced. Terminate the debounce, and send a message if the state has
// actually changed // actually changed
var debounceCallback = function (x) { var debounceCallback = function (err, x) {
node.debounceTimer = null; node.debounceTimer = null;
node.debouncing = false; node.debouncing = false;
if (x.value !== undefined && node.currentState !== Number(x.value)) { if (x.value !== undefined && node.currentState !== Number(x.value)) {
@ -261,7 +247,7 @@ module.exports = function (RED) {
process.nextTick(function () { process.nextTick(function () {
setPinMode(node._pin, bonescript.INPUT, function (response, pin) { setPinMode(node._pin, bonescript.INPUT, function (response, pin) {
if (response.value === true) { 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 // Initialise the currentState and lastActiveTime variables based on the value read
node.currentState = Number(x.value); node.currentState = Number(x.value);
if (node.currentState === node.activeState) { if (node.currentState === node.activeState) {
@ -357,7 +343,7 @@ module.exports = function (RED) {
process.nextTick(function () { process.nextTick(function () {
setPinMode(node._pin, bonescript.INPUT, function (response, pin) { setPinMode(node._pin, bonescript.INPUT, function (response, pin) {
if (response.value === true) { 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 // Initialise the currentState based on the value read
node.currentState = Number(x.value); node.currentState = Number(x.value);
// Attempt to attach an interrupt handler to the pin. If we succeed, // Attempt to attach an interrupt handler to the pin. If we succeed,
@ -417,24 +403,25 @@ module.exports = function (RED) {
newState = !newState; 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.send({topic: node.topic, payload: newState});
node.currentState = newState; node.currentState = newState;
});
}; };
// If we have a valid pin, set it as an output and set the default state // If we have a valid pin, set it as an output and set the default state
if (gpioPins.concat(usrLEDs).indexOf(node.pin) >= 0) { if (gpioPins.concat(usrLEDs).indexOf(node.pin) >= 0) {
// Don't set up interrupts & intervals until after the close event handler has been installed // 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 () { process.nextTick(function () {
setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) { 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); node.on("input", inputCallback);
setTimeout(function () { setTimeout(function () {
bonescript.digitalWrite(node._pin, node.defaultState); bonescript.digitalWrite(node._pin, node.defaultState, function() {});
}, 50); }, 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.retriggerable === false) {
if (node.pulseTimer === null) { if (node.pulseTimer === null) {
node.pulseTimer = setTimeout(endPulseCallback, time); 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}); node.send({topic: node.topic, payload: node.pulseState});
});
} }
} else { } else {
if (node.pulseTimer !== null) { if (node.pulseTimer !== null) {
clearTimeout(node.pulseTimer); clearTimeout(node.pulseTimer);
} else { } else {
bonescript.digitalWrite(node._pin, node.pulseState); bonescript.digitalWrite(node._pin, node.pulseState, function() {
node.send({topic: node.topic, payload: node.pulseState}); node.send({topic: node.topic, payload: node.pulseState});
});
} }
node.pulseTimer = setTimeout(endPulseCallback, time); 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 // At the end of the pulse, restore the default state and set the timer to null
var endPulseCallback = function () { var endPulseCallback = function () {
node.pulseTimer = null; node.pulseTimer = null;
bonescript.digitalWrite(node._pin, node.defaultState); bonescript.digitalWrite(node._pin, node.defaultState, function() {
node.send({topic: node.topic, payload: node.defaultState}); node.send({topic: node.topic, payload: node.defaultState});
});
}; };
// If we have a valid pin, set it as an output and set the default state // If we have a valid pin, set it as an output and set the default state

View File

@ -1,29 +1,34 @@
node-red-node-beaglebone 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 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. Only of use on a BeagleboneBlack board. Should ideally be running the
it does also need <b>bonescript</b> - but this is also pre-installed so no need to mark as a dependency... <a href="http://beagleboard.org/latest-images/" target="_new"> latest Debian</a>
images - as they have node.js v0.10.x preinstalled.
Install 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 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 Usage
----- -----
This package provides 5 nodes for use with the BeagleboneBlack board. This package provides 5 nodes for use with the BeagleboneBlack board.
###Analogue Input ### Analogue Input
Reads an analogue pin when triggered by Reads an analogue pin when triggered by
a message. a message.
@ -41,7 +46,7 @@ each. Values between breakpoints are linearly interpolated.
To reduce the effect of noise, enable averaging. This will read the input pin To reduce the effect of noise, enable averaging. This will read the input pin
voltage ten times in rapid succession for each input message and output the mean value. voltage ten times in rapid succession for each input message and output the mean value.
###Digital Input ### Digital Input
Sends a message with payload 0 or 1 on the first output when the pin changes state, and logs the total time in the active state. Sends a message with payload 0 or 1 on the first output when the pin changes state, and logs the total time in the active state.
@ -57,7 +62,7 @@ The pin state messages may be generated for both directions of change, or for ju
or just 1 to 0 changes. This is useful to generate a single message from a button or just 1 to 0 changes. This is useful to generate a single message from a button
press. When using buttons or switches, enable debouncing to improve reliability. press. When using buttons or switches, enable debouncing to improve reliability.
###Pulse Input ### Pulse Input
Pulse input for the Beaglebone Black. Counts input pulses or pulse edges: outputs Pulse input for the Beaglebone Black. Counts input pulses or pulse edges: outputs
total counts and the rate of counts/sec, with scaling. total counts and the rate of counts/sec, with scaling.
@ -67,22 +72,20 @@ rate message on the second output, at the chosen interval. An input message with
and a numeric payload will set the total count to that value (no scaling is applied): and a numeric payload will set the total count to that value (no scaling is applied):
any other input message will reset it to zero. any other input message will reset it to zero.
###Digital Output ### Digital Output
Sets the output pin high or low depending on the payload of the input message. Numeric Sets the output pin high or low depending on the payload of the input message. Numeric
payloads > 0.5 are 'high' (1), payloads <= 0.5 are 'low' (0). Other payloads which payloads > 0.5 are 'high' (1), payloads <= 0.5 are 'low' (0). Other payloads which
evaluate to true are 'high', if not then 'low'. Selecting the Inverting checkbox will evaluate to true are 'high', if not then 'low'. Selecting the Inverting checkbox will
switch the sense of the pin output. switch the sense of the pin output.
If the Toggle state checkbox is checked, the message content is ignored: successive If the Toggle state checkbox is checked, the message content is ignored: successive
messages cause the pin to toggle between 0 and 1. 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 pin will be initially set to the given Startup state until the first message arrives:
the Inverting property is not applied to this value. the Inverting property is not applied to this value.
###Pulse Output ### Pulse Output
Pulses the output pin for the set time after receiving an input message, unless the Pulses the output pin for the set time after receiving an input message, unless the
message has a topic including the text 'time' and a numeric payload. In this case, the message has a topic including the text 'time' and a numeric payload. In this case, the

View File

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