From: Jeremy Tan Date: Sun, 29 Sep 2013 09:25:30 +0000 (+0800) Subject: Update pintest + fix css X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=6377ff1447acecdb0496116d983034768773d726;p=matches%2FMCTX3420.git Update pintest + fix css --- diff --git a/testing/MCTXWeb/public_html/pintest.html b/testing/MCTXWeb/public_html/pintest.html index 5d0527b..d8821be 100644 --- a/testing/MCTXWeb/public_html/pintest.html +++ b/testing/MCTXWeb/public_html/pintest.html @@ -30,6 +30,7 @@ $("#pwm-container").exportPWM($("#pwm-menu")); } }); + $("#adc-controls").trigger("reset").setADCControl(); }); @@ -110,7 +111,7 @@
Analogue input (ADC)
-
+ diff --git a/testing/MCTXWeb/public_html/static/mctx.gui.js b/testing/MCTXWeb/public_html/static/mctx.gui.js index 180c395..c359e3b 100644 --- a/testing/MCTXWeb/public_html/static/mctx.gui.js +++ b/testing/MCTXWeb/public_html/static/mctx.gui.js @@ -194,4 +194,8 @@ $.fn.setErrorLog = function () { }; updater(); -}; \ No newline at end of file +}; + +$(document).ajaxError(function (event, jqXHR) { + console.log("AJAX query failed with: " + jqXHR.status + " (" + jqXHR.statusText + ")"); +}); \ No newline at end of file diff --git a/testing/MCTXWeb/public_html/static/mctx.pintest.js b/testing/MCTXWeb/public_html/static/mctx.pintest.js index 7a792e8..f04daad 100644 --- a/testing/MCTXWeb/public_html/static/mctx.pintest.js +++ b/testing/MCTXWeb/public_html/static/mctx.pintest.js @@ -5,6 +5,7 @@ mctx.pintest = {}; +mctx.pintest.api = mctx.api + "pin"; mctx.pintest.gpios = [ 4, 5, 8, 9, 10, 11, 14, 15, 26, 27, 30, 31, 44, 45, 46, 47, 48, 49, 60, 61, 65, 66, 67, 68, 69, 70, 71, 72, @@ -12,49 +13,22 @@ mctx.pintest.gpios = [ ]; mctx.pintest.pwms = [0, 1, 2, 3, 4, 5, 6, 7]; mctx.pintest.refreshRate = 750; - - -function unexport (type, number, container, menu) { - var url = mctx.api + "pin"; - - $.ajax({url : url, data : {type : type, num : number, export : -1}}) - .fail(function () { - switch(type) { - case "adc" : - var text = container.find("input[type='text'][name='" + number + "']"); - var check = container.find("input[type='checkbox'][name='unexport']"); - text.empty(); - check.attr("checked", true); - break; - case "gpi": case "gpo" : - container.remove(); - menu.append($("
AIN0123
", {"class" : "centre"}); @@ -82,18 +56,18 @@ $.fn.exportGPIO = function(menu) { container.append(form); menu.find("option[value='" + number+"']").remove(); }) - .done(function (jqXHR) { + .fail(function (jqXHR) { alert("Failed to export GPIO " + number + ". Is the server running?\n" + "Error code: " + jqXHR.status); }); + return this; }; $.fn.exportPWM = function(menu) { var number = menu.val(); - var url = mctx.api + "pin"; var container = this; - $.ajax({url : url, data : {type : "pwm", num : number, export : "1"}}) + $.ajax({url : mctx.pintest.api, data : {type : "pwm", num : number, export : "1"}}) .fail(function () { var form = $("", {"class" : "controls", action : "#", id : "pwm-" + number}); var title = $("
", {"class" : "centre bold", text : "PWM " + number}); @@ -119,15 +93,12 @@ $.fn.exportPWM = function(menu) { .append($("
").append( $("", {type : "text", readonly : "", name : "result"}))) .append($("").append( - $("", {type : "checkbox", name : "unexport", value :umber}) - .click(function () { - unexport("pwm", number, form, menu); - return false; - }))); + $("", {type : "checkbox", name : "unexport", value :number}))); form.append(title); table.append(header).append(controls); form.append(table); + form.setPWMControl(number, menu); container.append(form); menu.find("option[value='" + number+"']").remove(); }) @@ -135,6 +106,7 @@ $.fn.exportPWM = function(menu) { alert("Failed to export PWM " + number + ". Is the server running?\n" + "Error code: " + jqXHR.status); }); + return this; }; $.fn.setGPIOControl = function (number, menu) { @@ -146,16 +118,16 @@ $.fn.setGPIOControl = function (number, menu) { var update = true; var updater = function() { if (update) { - $.ajax({url : mctx.api + "pin", data : {type : "gpi", num : number}}) + $.ajax({url : mctx.pintest.api, data : {type : "gpi", num : number}}) .done(function (data) { result.val(data); }) - .fail(function () { - update = false; - result.val("GPIO retrieve failed."); + .always(function () { + setTimeout(updater, mctx.pintest.refreshRate); }); + } else { + setTimeout(updater, mctx.pintest.idleRefreshRate); } - setTimeout(updater, mctx.pintest.refreshRate); }; dir.click(function () { @@ -178,9 +150,9 @@ $.fn.setGPIOControl = function (number, menu) { set.click(function () { dir.attr("disabled", true); var val = (set.val() === "Off") ? 1 : 0; - $.ajax({url : mctx.api + "pin", data : {type : "gpo", num : number, set : val}}) + $.ajax({url : mctx.pintest.api, data : {type : "gpo", num : number, set : val}}) .done(function (data) { - result.text(data); + result.val(data); if (val === 0) set.val("Off"); else @@ -196,13 +168,87 @@ $.fn.setGPIOControl = function (number, menu) { unexport.click(function () { update = false; - $.ajax({url : mctx.api + "pin", data : {type : "gpi", num : number, export : -1}}) + $.ajax({url : mctx.pintest.api, data : {type : "gpi", num : number, export : -1}}) container.remove(); menu.append($("