From 8be554d787c35f80ffd91d77dba87543ff9eda6f Mon Sep 17 00:00:00 2001 From: Jeremy Tan Date: Tue, 22 Oct 2013 19:45:12 +0800 Subject: [PATCH] Add samplerate control to control page --- testing/MCTXWeb/public_html/control.html | 28 ++++++++++++++- .../public_html/static/mctx.control.js | 36 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/testing/MCTXWeb/public_html/control.html b/testing/MCTXWeb/public_html/control.html index 60817cf..412f7f8 100644 --- a/testing/MCTXWeb/public_html/control.html +++ b/testing/MCTXWeb/public_html/control.html @@ -48,6 +48,13 @@ }; $(this).setPressure(pressure, $("#pressure-result")); }); + + //Set logic for sensor sample rate thing + $("#sensor-select").loadSensorList($("#samplerate-result")); + $("#samplerate-controls").submit(function () { + setSampleRate($("#sensor-select option:selected").val(), + $("#sensor-set").val(), $("#samplerate-result")); + }); }); }).fail(function () { $(document).ready(function () { @@ -177,12 +184,31 @@

- +  

+ +
+ + + + + + + + + +
+

+   +

+

+ +

+
diff --git a/testing/MCTXWeb/public_html/static/mctx.control.js b/testing/MCTXWeb/public_html/static/mctx.control.js index 24b0448..1d5c744 100644 --- a/testing/MCTXWeb/public_html/static/mctx.control.js +++ b/testing/MCTXWeb/public_html/static/mctx.control.js @@ -26,6 +26,42 @@ function toggleControls(running) { } } +function setSampleRate(id, val, result) { + var n = Number(val); + if (isNaN(n) || n < 0) { + result.text("You must give positive numeric values.").addClass("fail"); + return; + } + + $.ajax({ + url : mctx.api + 'sensors', + data : {id : id, sample_s : n} + }).done(function(data) { + if (!result.checkStatus(data)) { + return; + } + + result.text("Set ok!").removeClass("fail").addClass("pass"); + }); +}; + +$.fn.loadSensorList = function (result, input) { + var select = this; + + $.ajax({ + url : mctx.api + 'identify', + data : {'sensors' : 1} + }).done(function(data) { + if (!result.checkStatus(data)) { + return; + } + for (var id in data.sensors) { + var option = $("