From 9839a36649fbd852835693ec2096c4601372b7c1 Mon Sep 17 00:00:00 2001 From: Sam Moore Date: Mon, 2 Sep 2013 19:51:40 +0800 Subject: [PATCH] Add control to GUI --- server/run.sh | 4 ++-- web/gui.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/server/run.sh b/server/run.sh index 7b3d24a..a776cbd 100755 --- a/server/run.sh +++ b/server/run.sh @@ -2,5 +2,5 @@ # Use this to quickly test run the server in valgrind #spawn-fcgi -p9005 -n ./valgrind.sh # Use this to run the server normally -spawn-fcgi -p9005 -n ./server & -./stream +./stream & +spawn-fcgi -p9005 -n ./server diff --git a/web/gui.js b/web/gui.js index 911325b..da4e0d0 100644 --- a/web/gui.js +++ b/web/gui.js @@ -10,6 +10,7 @@ $(document).ready(function() g_sensors = [] g_numSensors = 2 g_storeTime = [] + g_key = null $.fn.pruneSensorData = function(id) { @@ -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 = "

Controls

\n" + controlHTML += "

Pressure: " + controlHTML += "

" + + $("#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 : i}, success : function(data) {$(this).updateSensor(data);}}) } }); -- 2.20.1