X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=testing%2FMCTXWeb%2Fpublic_html%2Fstatic%2Fmctx.gui.js;h=e7dd167d46ecaf125633952e205ad1efd707a145;hb=7b58480c5700b8ce4a686836049458be6681934b;hp=478e9ad30c8789f6a936c4fffd4a94b1b2737221;hpb=a7ce111ea751bbddf9b5d9659c50a0ca720e1bbf;p=matches%2FMCTX3420.git diff --git a/testing/MCTXWeb/public_html/static/mctx.gui.js b/testing/MCTXWeb/public_html/static/mctx.gui.js index 478e9ad..e7dd167 100644 --- a/testing/MCTXWeb/public_html/static/mctx.gui.js +++ b/testing/MCTXWeb/public_html/static/mctx.gui.js @@ -3,8 +3,7 @@ */ mctx = {}; -//mctx.api = location.protocol + "/" + location.host + "/api/"; -mctx.api = "http://mctx.us.to:8080/api/"; +mctx.api = location.protocol + "//" + location.host + "/api/"; mctx.expected_api_version = 0; mctx.sensors = { 0 : {name : "Strain gauge 1"}, @@ -22,6 +21,10 @@ mctx.actuators = { 3 : {name : "Pressure regulator"} }; +mctx.strain_gauges = {}; +mctx.strain_gauges.ids = [0, 1, 2, 3]; +mctx.strain_gauges.time_limit = 20; + function getDate(){ document.write((new Date()).toDateString()); } @@ -62,9 +65,10 @@ $.fn.populateNavbar = function () { * @returns {$.fn} */ $.fn.setCamera = function () { - var loc = mctx.api + "image"; + var url = mctx.api + "image"; var update = true; + //Stop updating if we can't retrieve an image! this.error(function() { update = false; }); @@ -78,11 +82,39 @@ $.fn.setCamera = function () { return; } - parent.attr("src", loc + "#" + (new Date()).getTime()); + parent.attr("src", url + "#" + (new Date()).getTime()); setTimeout(updater, 500); }; + updater(); + return this; +}; + +$.fn.setStrainGraphs = function () { + var sensor_url = mctx.api + "sensors"; + var graphdiv = this; + + var updater = function () { + var time_limit = mctx.strain_gauges.time_limit; + var responses = new Array(mctx.strain_gauges.ids.length); + + for (var i = 0; i < mctx.strain_gauges.ids.length; i++) { + var parameters = {id : i, start_time: -time_limit}; + responses[i] = $.ajax({url : sensor_url, data : parameters}); + } + + $.when.apply(this, responses).then(function () { + var data = new Array(arguments.length); + for (var i = 0; i < arguments.length; i++) { + var raw_data = arguments[i][0].data; + data[i] = raw_data; + } + $.plot(graphdiv, data); + setTimeout(updater, 500); + }, function () {alert("boo");}); + }; + updater(); return this; }; \ No newline at end of file