Add samplerate control to control page
authorJeremy Tan <[email protected]>
Tue, 22 Oct 2013 11:45:12 +0000 (19:45 +0800)
committerJeremy Tan <[email protected]>
Tue, 22 Oct 2013 11:45:12 +0000 (19:45 +0800)
testing/MCTXWeb/public_html/control.html
testing/MCTXWeb/public_html/static/mctx.control.js

index 60817cf..412f7f8 100644 (file)
             };   
             $(this).setPressure(pressure, $("#pressure-result"));
           });
+          
+          //Set logic for sensor sample rate thing
+          $("#sensor-select").loadSensorList($("#samplerate-result"));
+          $("#samplerate-controls").submit(function () {
+            setSampleRate($("#sensor-select option:selected").val(), 
+                          $("#sensor-set").val(), $("#samplerate-result"));
+          });
        });       
       }).fail(function () {
         $(document).ready(function () {
                 </tr>
               </table>
               <p class="left" id="pressure-result">
-                
+                &nbsp;
               </p>
               <p class="right">
                 <input type="submit" value="Set pressure">
               </p>
             </form>
+            
+            <form id="samplerate-controls" action="#" class="nice clear">
+              <table>
+                <tr>
+                  <td><label for="sensor-select">Select a sensor</label></td>
+                  <td><label for="sensor-set">Set sampling rate (s)</label></td>
+                </tr>
+                <tr>
+                  <td><select id="sensor-select" style="width:100%;"></select></td>
+                  <td><input id="sensor-set" type="text"></td>
+                </tr>
+              </table>
+              <p class="left" id="samplerate-result">
+                &nbsp;
+              </p>
+              <p class="right">
+                <input type="submit" value="Set sampling rate">
+              </p>
+            </form>
           </div>
           
           <div id="stats-widget" class="widget">
index 24b0448..1d5c744 100644 (file)
@@ -26,6 +26,42 @@ function toggleControls(running) {
   }
 }
 
+function setSampleRate(id, val, result) {
+  var n = Number(val);
+  if (isNaN(n) || n < 0) {
+    result.text("You must give positive numeric values.").addClass("fail");
+    return;
+  }
+  
+  $.ajax({
+    url : mctx.api + 'sensors',
+    data : {id : id, sample_s : n}
+  }).done(function(data) {
+    if (!result.checkStatus(data)) {
+      return;
+    }
+    
+    result.text("Set ok!").removeClass("fail").addClass("pass");
+  });
+};
+
+$.fn.loadSensorList = function (result, input) {
+  var select = this;
+  
+  $.ajax({
+    url : mctx.api + 'identify',
+    data : {'sensors' : 1}
+  }).done(function(data) {
+    if (!result.checkStatus(data)) {
+      return;
+    }
+    for (var id in data.sensors) {
+      var option = $("<option/>", {value : id, text : data.sensors[id]});
+      select.append(option);
+    }
+  });
+}
+
 $.fn.setStatusUpdater = function () {
   var result = this;
   

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