Nicen the rego form and add back the change password form
[matches/MCTX3420.git] / web / gui.js
index 911325b..e49cf4d 100644 (file)
@@ -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 = "<h2 id=control0>Controls</h2>\n"
+               controlHTML += "<button id=led onclick=\"$(document).ledFlash()\">LED On</button>"
+               
+               $("#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);}})
 
        }
 });

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