Merge branch 'master' of https://github.com/szmoore/MCTX3420.git
[matches/MCTX3420.git] / web / gui.js
index 911325b..7d7a8fe 100644 (file)
@@ -8,8 +8,9 @@ $(document).ready(function()
 {
 
        g_sensors = []
-       g_numSensors = 2
+       g_numSensors = 1
        g_storeTime = []
+       g_key = null
 
        $.fn.pruneSensorData = function(id)
        {
@@ -43,7 +44,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 +62,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 +79,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 +111,12 @@ $(document).ready(function()
                }
                $("#plots").html(plotsHTML)
 
+               controlHTML = "<h2 id=control0>Controls</h2>\n"
+               controlHTML += "<p> Pressure: <input type=text id=control0_value value=\"100\"/>"
+               controlHTML += "<button id=actuator0 onclick=\"$(document).setPressure()\">SET</button> </p>"
+               
+               $("#controls").html(controlHTML)
+
        }
 
 
@@ -111,7 +127,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);}})
 
        }
 });

UCC git Repository :: git.ucc.asn.au