From ed4b6b18ec700b7899ee9cf030791e29d12e2182 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 2 Feb 2016 12:36:27 +0000 Subject: [PATCH] Add debounce time to the to BBB input node --- hardware/BBB/145-BBB-hardware.html | 4 ++-- hardware/BBB/145-BBB-hardware.js | 18 +++++++++--------- hardware/BBB/package.json | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hardware/BBB/145-BBB-hardware.html b/hardware/BBB/145-BBB-hardware.html index 9a360381..c0e38345 100644 --- a/hardware/BBB/145-BBB-hardware.html +++ b/hardware/BBB/145-BBB-hardware.html @@ -228,7 +228,7 @@ voltage ten times in rapid succession for each input message and output the mean
- + mS
@@ -284,7 +284,7 @@ press. When using buttons or switches, enable debouncing to improve reliability. defaults: { // defines the editable properties of the node pin: { value:"", required:true }, activeLow: { value:false, required:true }, - debounce: { value:false, required:true }, + debounce: { value:0, required:true }, outputOn: { value:"both", required:true }, updateInterval: { value:60, required:true, validate:RED.validators.number() }, topic: { value:"" }, diff --git a/hardware/BBB/145-BBB-hardware.js b/hardware/BBB/145-BBB-hardware.js index c550a8b3..acbd2f8e 100644 --- a/hardware/BBB/145-BBB-hardware.js +++ b/hardware/BBB/145-BBB-hardware.js @@ -111,7 +111,7 @@ module.exports = function (RED) { this.activeState = 1; } 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") { this.activeEdges = [false, true]; } 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 // the success or failure of attaching the interrupt - we must handle this var interruptCallback = function (err, x) { - if (x.value === undefined) { + if (x === undefined) { if (x.attached === true) { node.interruptAttached = true; node.on("input", inputCallback); @@ -148,13 +148,13 @@ module.exports = function (RED) { } else { node.error("Failed to attach interrupt"); } - } else if (node.currentState !== Number(x.value)) { + } else if (node.currentState !== Number(x)) { if (node.debounce) { if (node.debouncing === false) { node.debouncing = true; node.debounceTimer = setTimeout(function () { bonescript.digitalRead(node._pin, debounceCallback); - }, 7); + }, Number(node.debounce)); } } else { sendStateMessage(x); @@ -168,7 +168,7 @@ module.exports = function (RED) { var debounceCallback = function (err, x) { node.debounceTimer = null; node.debouncing = false; - if (x.value !== undefined && node.currentState !== Number(x.value)) { + if (x !== undefined && node.currentState !== Number(x)) { sendStateMessage(x); } }; @@ -177,7 +177,7 @@ module.exports = function (RED) { // 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 var sendStateMessage = function (x) { - node.currentState = Number(x.value); + node.currentState = Number(x); var now = Date.now(); if (node.currentState === node.activeState) { node.lastActiveTime = now; @@ -249,7 +249,7 @@ module.exports = function (RED) { if (!response) { bonescript.digitalRead(node._pin, function (err, x) { // 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) { 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 // the success or failure of attaching the interrupt - we must handle this var interruptCallback = function (x) { - if (x.value === undefined) { + if (x === undefined) { if (x.attached === true) { node.interruptAttached = true; node.on("input", inputCallback); @@ -345,7 +345,7 @@ module.exports = function (RED) { if (!response) { bonescript.digitalRead(node._pin, function (err, x) { // 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, // set the input event and interval handlers var interruptType; diff --git a/hardware/BBB/package.json b/hardware/BBB/package.json index a8763df9..88caa240 100644 --- a/hardware/BBB/package.json +++ b/hardware/BBB/package.json @@ -1,6 +1,6 @@ { "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", "dependencies" : { "octalbonescript":"^1.1.*"