mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
parent
f0867c5a01
commit
705c7f76c4
@ -25,20 +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
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node constructor for bbb-analogue-in
|
// Node constructor for bbb-analogue-in
|
||||||
function AnalogueInputNode(n) {
|
function AnalogueInputNode(n) {
|
||||||
@ -65,7 +65,7 @@ module.exports = function (RED) {
|
|||||||
// 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 (err, x) {
|
var analogReadCallback = function (err, x) {
|
||||||
sum = sum + x.value;
|
sum = sum + Number(x);
|
||||||
count = count - 1;
|
count = count - 1;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
bonescript.analogRead(node._pin, analogReadCallback);
|
bonescript.analogRead(node._pin, analogReadCallback);
|
||||||
@ -404,9 +404,9 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bonescript.digitalWrite(node._pin, newState ? 1 : 0, function() {
|
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
|
||||||
@ -416,7 +416,7 @@ module.exports = function (RED) {
|
|||||||
process.nextTick(function () {
|
process.nextTick(function () {
|
||||||
setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) {
|
setPinMode(node._pin, bonescript.OUTPUT, function (response, pin) {
|
||||||
if (response) {
|
if (response) {
|
||||||
node.error("Unable to set " + pin + " as output: " + response.err);
|
node.error("Unable to set " + pin + " as output: " + response.err);
|
||||||
} else {
|
} else {
|
||||||
node.on("input", inputCallback);
|
node.on("input", inputCallback);
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -465,15 +465,15 @@ module.exports = function (RED) {
|
|||||||
if (node.pulseTimer === null) {
|
if (node.pulseTimer === null) {
|
||||||
node.pulseTimer = setTimeout(endPulseCallback, time);
|
node.pulseTimer = setTimeout(endPulseCallback, time);
|
||||||
bonescript.digitalWrite(node._pin, node.pulseState, function() {
|
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, function() {
|
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);
|
||||||
@ -485,7 +485,7 @@ module.exports = function (RED) {
|
|||||||
var endPulseCallback = function () {
|
var endPulseCallback = function () {
|
||||||
node.pulseTimer = null;
|
node.pulseTimer = null;
|
||||||
bonescript.digitalWrite(node._pin, node.defaultState, function() {
|
bonescript.digitalWrite(node._pin, node.defaultState, function() {
|
||||||
node.send({topic: node.topic, payload: node.defaultState});
|
node.send({topic: node.topic, payload: node.defaultState});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-beaglebone",
|
"name" : "node-red-node-beaglebone",
|
||||||
"version" : "0.1.0",
|
"version" : "0.1.1",
|
||||||
"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.*"
|
"octalbonescript":"^1.1.*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user