diff --git a/hardware/BBB/145-BBB-hardware.html b/hardware/BBB/145-BBB-hardware.html index ac59dcd3..bad622aa 100644 --- a/hardware/BBB/145-BBB-hardware.html +++ b/hardware/BBB/145-BBB-hardware.html @@ -101,10 +101,10 @@ voltage ten times in rapid succession for each input message and output the mean var container = $('
', {style:"margin:0; padding:4px; padding-left 10px;"}); var row = $('').appendTo(container); var breakpointField = $('').appendTo(row); - var inputValueField = $('', - {disabled:"", class:"node-input-breakpoint-input-value", type:"text", style:"margin-left:5px; margin-right:2px; width:36%;"}).appendTo(breakpointField); + var inputValueField = $('', + {disabled:"", class:"node-input-breakpoint-input-value", type:"text", style:"margin-left:5px; margin-right:2px; width:36%;"}).appendTo(breakpointField); if (breakpoint.mutable) { - inputValueField.removeAttr("disabled"); + inputValueField.removeAttr("disabled"); } breakpointField.append(" => "); var outputValueField = $('', @@ -126,17 +126,17 @@ voltage ten times in rapid succession for each input message and output the mean mutableFlag.attr("mutable", "false"); } if (insert === true) { - var last = $("#node-input-breakpoint-container").children().last(); - var prev = last.prev(); - inputValueField.val((Number(last.find(".node-input-breakpoint-input-value").val()) + - Number(prev.find(".node-input-breakpoint-input-value").val()))/2); - outputValueField.val((Number(last.find(".node-input-breakpoint-output-value").val()) + - Number(prev.find(".node-input-breakpoint-output-value").val()))/2); - last.before(container); + var last = $("#node-input-breakpoint-container").children().last(); + var prev = last.prev(); + inputValueField.val((Number(last.find(".node-input-breakpoint-input-value").val()) + + Number(prev.find(".node-input-breakpoint-input-value").val()))/2); + outputValueField.val((Number(last.find(".node-input-breakpoint-output-value").val()) + + Number(prev.find(".node-input-breakpoint-output-value").val()))/2); + last.before(container); } else { - inputValueField.val(breakpoint.input); - outputValueField.val(breakpoint.output); - $("#node-input-breakpoint-container").append(container); + inputValueField.val(breakpoint.input); + outputValueField.val(breakpoint.output); + $("#node-input-breakpoint-container").append(container); } } diff --git a/hardware/BBB/145-BBB-hardware.js b/hardware/BBB/145-BBB-hardware.js index 966198c7..9f18c82b 100644 --- a/hardware/BBB/145-BBB-hardware.js +++ b/hardware/BBB/145-BBB-hardware.js @@ -35,46 +35,46 @@ function AnalogInputNode(n) { this.breakpoints = n.breakpoints; this.averaging = n.averaging; if (this.averaging) { - this.averages = 10; + this.averages = 10; } else { - this.averages = 1; + this.averages = 1; } // Define 'node' to allow us to access 'this' from within callbacks var node = this; - // Variables used for input averaging - var sum; // accumulates the input readings to be averaged - var count; // keep track of the number of measurements made - + // Variables used for input averaging + var sum; // accumulates the input readings to be averaged + var count; // keep track of the number of measurements made + // 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) { - sum = sum + x.value; - count = count - 1; - if (count > 0) { - bonescript.analogRead(node.pin, analogReadCallback); - } else { - var msg = {}; - msg.topic = node.topic; - sum = sum/node.averages; - // i is the index of the first breakpoint where the 'input' value is strictly - // greater than the measurement (note: a measurement can never be == 1) - var i = node.breakpoints.map(function (breakpoint) { return sum >= breakpoint.input; }).indexOf(false); - msg.payload = node.breakpoints[i-1].output + (node.breakpoints[i].output - node.breakpoints[i-1].output) * - (sum - node.breakpoints[i-1].input)/(node.breakpoints[i].input - node.breakpoints[i-1].input); - node.send(msg); + sum = sum + x.value; + count = count - 1; + if (count > 0) { + bonescript.analogRead(node.pin, analogReadCallback); + } else { + var msg = {}; + msg.topic = node.topic; + sum = sum/node.averages; + // i is the index of the first breakpoint where the 'input' value is strictly + // greater than the measurement (note: a measurement can never be == 1) + var i = node.breakpoints.map(function (breakpoint) { return sum >= breakpoint.input; }).indexOf(false); + msg.payload = node.breakpoints[i-1].output + (node.breakpoints[i].output - node.breakpoints[i-1].output) * + (sum - node.breakpoints[i-1].input)/(node.breakpoints[i].input - node.breakpoints[i-1].input); + node.send(msg); } }; // If we have a valid pin, set the input event handler to Bonescript's analogRead if (["P9_39", "P9_40", "P9_37", "P9_38", "P9_33", "P9_36", "P9_35"].indexOf(node.pin) >= 0) { node.on("input", function (msg) { - sum = 0; - count = node.averages; - bonescript.analogRead(node.pin, analogReadCallback); - }); + sum = 0; + count = node.averages; + bonescript.analogRead(node.pin, analogReadCallback); + }); } else { node.error("Unconfigured input pin"); } diff --git a/hardware/BBB/README.md b/hardware/BBB/README.md new file mode 100644 index 00000000..a08281c3 --- /dev/null +++ b/hardware/BBB/README.md @@ -0,0 +1,106 @@ +# BBB-hardware + +Node-RED nodes for interfacing with hardware inputs and outputs on the BeagleBone Black. +Uses the bonescript library provided with the BBB, available through NPM and on Github +at