From 68080df45eb13009309d03ab0d1601a2059f7453 Mon Sep 17 00:00:00 2001 From: Maxwell Hadley Date: Sat, 8 Feb 2014 22:36:23 +0000 Subject: [PATCH] Starting to add scale factors & linearisation Added breakpoints property to the node Building the breakpoints editor (nearly there!) --- hardware/BBB/144-analog-in.html | 88 ++++++++++++++++++++++++++++++++- hardware/BBB/144-analog-in.js | 6 +++ 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/hardware/BBB/144-analog-in.html b/hardware/BBB/144-analog-in.html index 7fc547a3..98739ef7 100644 --- a/hardware/BBB/144-analog-in.html +++ b/hardware/BBB/144-analog-in.html @@ -37,6 +37,16 @@ +
+ Input Scaling +
+
+
+
    +
+
+ Add Breakpoint +
@@ -58,6 +68,7 @@ analogue input in the range [0-1), or NaN if an read error occurs (errors are lo name: { value:"" }, // along with default values. topic: { value:"", required:true }, pin: { value:"", required:true }, + breakpoints: { value:[{input:0.0, output:0.0, mutable:false}, {input:1.0, output:1.0, mutable:false}] } }, inputs:1, // set the number of inputs - only 0 or 1 outputs:1, // set the number of outputs - 0 to n @@ -67,6 +78,81 @@ analogue input in the range [0-1), or NaN if an read error occurs (errors are lo }, labelStyle: function() { // sets the class to apply to the label return this.name ? "node_label_italic" : ""; - } + }, + oneditprepare: function () { + function generateBreakpoint(i, breakpoint) { + var container = $('
  • ', {style:"margin:0; padding:8px 0px; border-bottom: 1px solid #ccc;"}); + var row = $('
    ').appendTo(container); + var row2 = $('
    ', {style:"padding-top: 5px; text-align: right;"}).appendTo(container); + + var breakpointField = $('').appendTo(row); + var inputValueField = $('', + {class:"node-input-breakpoint-input-value", type:"text", style:"margin-left:5px; margin-right:2px; width:36%;"}).appendTo(breakpointField); + breakpointField.append(" => "); + var outputValueField = $('', + {class:"node-input-breakpoint-output-value", type:"text", style:"margin-left:0px; width:36%;"}).appendTo(breakpointField); + var finalSpan = $('', {style:"float:right; margin-top:3px; margin-right:10px;"}).appendTo(row); + var mutableFlag = $('', {class:"node-input-breakpoint-mutable", style:"display:hide;"}).appendTo(row); + if (breakpoint.mutable) { + mutableFlag.attr("mutable", "true"); + var deleteButton = $('', {href:"#", class:"btn btn-mini", style:"margin-left: 5px;"}).appendTo(finalSpan); + $('', {class:"icon-remove"}).appendTo(deleteButton); + + deleteButton.click(function() { + container.css({"background":"#fee"}); + container.fadeOut(300, function() { + $(this).remove(); + $("#node-input-breakpoint-container").children().each(function (i) { + $(this).find(".node-input-breakpoint-index").html(i + 1); + }); + }); + }); + } else { + mutableFlag.attr("mutable", "false"); + } + inputValueField.val(breakpoint.input); + outputValueField.val(breakpoint.output); + $("#node-input-breakpoint-container").append(container); + } + + $("#node-input-add-breakpoint").click(function () { + generateBreakpoint($("#node-input-breakpoint-container").children().length + 1, {input:0, output:0, mutable:true}); + $("#node-input-breakpoint-container-div").scrollTop($("#node-input-breakpoint-container-div").get(0).scrollHeight); + }); + + for (var i = 0; i < this.breakpoints.length; i++) { + var breakpoint = this.breakpoints[i]; + generateBreakpoint(i + 1, breakpoint); + } + + // Handle resizing the Input Scaling div when the dialog is resized + function switchDialogResize(ev, ui) { + $("#node-input-breakpoint-container-div").css("height", (ui.size.height - 290) + "px"); + }; + + $("#dialog").on("dialogresize", switchDialogResize); + $("#dialog").one("dialogopen", function (ev) { + var size = $("#dialog").dialog('option', 'sizeCache-switch'); + if (size) { + switchDialogResize(null, { size:size }); + } + }); + $("#dialog").one("dialogclose", function(ev, ui) { + $("#dialog").off("dialogresize", switchDialogResize); + }); + }, + oneditsave: function() { + var breakpoints = $("#node-input-breakpoint-container").children(); + var node = this; + node.breakpoints = []; + breakpoints.each(function (i) { + var breakpoint = $(this); + var r = {}; + r.input = breakpoint.find(".node-input-breakpoint-input-value").val() - 0 + r.output = breakpoint.find(".node-input-breakpoint-output-value").val() - 0; + r.mutable = breakpoint.find(".node-input-breakpoint-mutable").attr("mutable") == "true"; + node.breakpoints.push(r); + }); + } }); diff --git a/hardware/BBB/144-analog-in.js b/hardware/BBB/144-analog-in.js index aa97eee1..36223b76 100644 --- a/hardware/BBB/144-analog-in.js +++ b/hardware/BBB/144-analog-in.js @@ -32,11 +32,17 @@ function AnalogInputNode(n) { // Store local copies of the node configuration (as defined in the .html) this.topic = n.topic; this.pin = n.pin; + this.breakpoints = n.breakpoints; // Define 'node' to allow us to access 'this' from within callbacks (the 'var' is essential - // otherwise there is only one global 'node' for all instances of AnalogInputNode!) var node = this; + node.log("breakpoints:"); + for (var i = 0; i < node.breakpoints.length; i++) { + node.log(i + ": {input:" + node.breakpoints[i].input + ", output:" + node.breakpoints[i].output + ", mutable:" + node.breakpoints[i].mutable +"}"); + } + // A callback function variable seems to be more reliable than a lambda ?! var readCallback = function (x) { var msg = {};