X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=web%2Fgui.js;h=e49cf4d4d6fbcd299f9a64203f736b4a3abc5ac0;hb=0654fb285c91da103314610cd4f27295e3da38f3;hp=911325b149c483a9eedd4491bb42cb8ee696954d;hpb=6a39a89e22203e51cff62dd6daa68d5eb0836ffa;p=matches%2FMCTX3420.git diff --git a/web/gui.js b/web/gui.js index 911325b..e49cf4d 100644 --- a/web/gui.js +++ b/web/gui.js @@ -8,8 +8,27 @@ $(document).ready(function() { g_sensors = [] - g_numSensors = 2 + g_numSensors = 1 g_storeTime = [] + g_key = null + g_led = 1 + + $.fn.ledFlash = function() + { + //alert("Flash LED"); + if (g_led == 0) + { + $.ajax({url : "api/actuators", data : {id : 0, set : 1}}) + g_led = 1 + $("#led").html("LED On"); + } + else + { + $.ajax({url : "api/actuators", data : {id : 0, set : 0}}) + g_led = 0 + $("#led").html("LED Off"); + } + } $.fn.pruneSensorData = function(id) { @@ -43,7 +62,7 @@ $(document).ready(function() $.fn.updateSensor = function(json) { //console.log(json.data) - var sensor = g_sensors[json.id] + var sensor = g_sensors[0] var most_recent = null if (sensor.length > 0) most_recent = sensor[sensor.length-1][0] @@ -61,7 +80,7 @@ $(document).ready(function() //console.log("Plot:") //console.log(g_sensors[json.id]) - $.plot("#sensor"+String(json.id)+"_plot", [g_sensors[json.id]]) + $.plot("#sensor"+String(0)+"_plot", [g_sensors[0]]) $.ajax({url : "/api/sensors", data : {id : json.id}, success : function(data) {$(this).updateSensor(data);}}); // @@ -78,10 +97,19 @@ $(document).ready(function() $.plot("#sensor"+String(id)+"_plot", [g_sensors[id]]) } + $.fn.setPressure = function() + { + var value = Number($("#control0_value").val()) + $.ajax({url : "/api/control", data : {action : "set", value : String(value), id : 0, key : g_key}, success : function(json) {alert(json.description)}}) + } + $.fn.LoadGUI = function() { //TODO: Get rid of g_numSensors; query the server for sensors? + $.ajax({url : "/api/control", data : {action : "start", force : "true"}, success : function(json) {g_key = String(json.key)}, async : false}) + console.log("Key is " + g_key) + // Load the plots plotsHTML = "" for (var i = 0; i < g_numSensors; ++i) @@ -101,6 +129,11 @@ $(document).ready(function() } $("#plots").html(plotsHTML) + controlHTML = "

Controls

\n" + controlHTML += "" + + $("#controls").html(controlHTML) + } @@ -111,7 +144,7 @@ $(document).ready(function() for (var i = 0; i < g_numSensors; ++i) { - $.ajax({url : "/api/sensors", data : {id : i}, success : function(data) {$(this).updateSensor(data);}}) + $.ajax({url : "/api/sensors", data : {id : 2}, success : function(data) {$(this).updateSensor(data);}}) } });