mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Add debounce time to the to BBB input node
This commit is contained in:
parent
7cb43208e6
commit
ed4b6b18ec
@ -228,7 +228,7 @@ voltage ten times in rapid succession for each input message and output the mean
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-debounce">Debounce</label>
|
<label for="node-input-debounce">Debounce</label>
|
||||||
<input type="checkbox" id="node-input-debounce" style="display:inline-block; width:auto; vertical-align:top;">
|
<input type="text" id="node-input-debounce" placeholder="debounce time in mS" style="width: 160px"> mS
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-outputOn">Output on</label>
|
<label for="node-input-outputOn">Output on</label>
|
||||||
@ -284,7 +284,7 @@ press. When using buttons or switches, enable debouncing to improve reliability.
|
|||||||
defaults: { // defines the editable properties of the node
|
defaults: { // defines the editable properties of the node
|
||||||
pin: { value:"", required:true },
|
pin: { value:"", required:true },
|
||||||
activeLow: { value:false, required:true },
|
activeLow: { value:false, required:true },
|
||||||
debounce: { value:false, required:true },
|
debounce: { value:0, required:true },
|
||||||
outputOn: { value:"both", required:true },
|
outputOn: { value:"both", required:true },
|
||||||
updateInterval: { value:60, required:true, validate:RED.validators.number() },
|
updateInterval: { value:60, required:true, validate:RED.validators.number() },
|
||||||
topic: { value:"" },
|
topic: { value:"" },
|
||||||
|
@ -111,7 +111,7 @@ module.exports = function (RED) {
|
|||||||
this.activeState = 1;
|
this.activeState = 1;
|
||||||
}
|
}
|
||||||
this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages
|
this.updateInterval = n.updateInterval*1000; // How often to send totalActiveTime messages
|
||||||
this.debounce = n.debounce; // Enable switch contact debouncing algorithm
|
this.debounce = n.debounce || null; // Enable switch contact debouncing algorithm
|
||||||
if (n.outputOn === "rising") {
|
if (n.outputOn === "rising") {
|
||||||
this.activeEdges = [false, true];
|
this.activeEdges = [false, true];
|
||||||
} else if (n.outputOn === "falling") {
|
} else if (n.outputOn === "falling") {
|
||||||
@ -140,7 +140,7 @@ module.exports = function (RED) {
|
|||||||
// 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 (err, x) {
|
var interruptCallback = function (err, x) {
|
||||||
if (x.value === undefined) {
|
if (x === undefined) {
|
||||||
if (x.attached === true) {
|
if (x.attached === true) {
|
||||||
node.interruptAttached = true;
|
node.interruptAttached = true;
|
||||||
node.on("input", inputCallback);
|
node.on("input", inputCallback);
|
||||||
@ -148,13 +148,13 @@ module.exports = function (RED) {
|
|||||||
} else {
|
} else {
|
||||||
node.error("Failed to attach interrupt");
|
node.error("Failed to attach interrupt");
|
||||||
}
|
}
|
||||||
} else if (node.currentState !== Number(x.value)) {
|
} else if (node.currentState !== Number(x)) {
|
||||||
if (node.debounce) {
|
if (node.debounce) {
|
||||||
if (node.debouncing === false) {
|
if (node.debouncing === false) {
|
||||||
node.debouncing = true;
|
node.debouncing = true;
|
||||||
node.debounceTimer = setTimeout(function () {
|
node.debounceTimer = setTimeout(function () {
|
||||||
bonescript.digitalRead(node._pin, debounceCallback);
|
bonescript.digitalRead(node._pin, debounceCallback);
|
||||||
}, 7);
|
}, Number(node.debounce));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendStateMessage(x);
|
sendStateMessage(x);
|
||||||
@ -168,7 +168,7 @@ module.exports = function (RED) {
|
|||||||
var debounceCallback = function (err, 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 !== undefined && node.currentState !== Number(x)) {
|
||||||
sendStateMessage(x);
|
sendStateMessage(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -177,7 +177,7 @@ module.exports = function (RED) {
|
|||||||
// have determined we have a 'genuine' change of state. Update the currentState and
|
// have determined we have a 'genuine' change of state. Update the currentState and
|
||||||
// ActiveTime variables, and send a message on the first output with the new state
|
// ActiveTime variables, and send a message on the first output with the new state
|
||||||
var sendStateMessage = function (x) {
|
var sendStateMessage = function (x) {
|
||||||
node.currentState = Number(x.value);
|
node.currentState = Number(x);
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
if (node.currentState === node.activeState) {
|
if (node.currentState === node.activeState) {
|
||||||
node.lastActiveTime = now;
|
node.lastActiveTime = now;
|
||||||
@ -249,7 +249,7 @@ module.exports = function (RED) {
|
|||||||
if (!response) {
|
if (!response) {
|
||||||
bonescript.digitalRead(node._pin, function (err, 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);
|
||||||
if (node.currentState === node.activeState) {
|
if (node.currentState === node.activeState) {
|
||||||
node.lastActiveTime = Date.now();
|
node.lastActiveTime = Date.now();
|
||||||
}
|
}
|
||||||
@ -296,7 +296,7 @@ module.exports = function (RED) {
|
|||||||
// 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 (x) {
|
||||||
if (x.value === undefined) {
|
if (x === undefined) {
|
||||||
if (x.attached === true) {
|
if (x.attached === true) {
|
||||||
node.interruptAttached = true;
|
node.interruptAttached = true;
|
||||||
node.on("input", inputCallback);
|
node.on("input", inputCallback);
|
||||||
@ -345,7 +345,7 @@ module.exports = function (RED) {
|
|||||||
if (!response) {
|
if (!response) {
|
||||||
bonescript.digitalRead(node._pin, function (err, 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);
|
||||||
// Attempt to attach an interrupt handler to the pin. If we succeed,
|
// Attempt to attach an interrupt handler to the pin. If we succeed,
|
||||||
// set the input event and interval handlers
|
// set the input event and interval handlers
|
||||||
var interruptType;
|
var interruptType;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-beaglebone",
|
"name" : "node-red-node-beaglebone",
|
||||||
"version" : "0.1.3",
|
"version" : "0.1.4",
|
||||||
"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