2 * MCTX3420 2013 GUI stuff.
6 mctx.api = location.protocol + "//" + location.host + "/api/";
7 mctx.expected_api_version = 0;
9 0 : {name : "Strain gauge 1"},
10 1 : {name : "Strain gauge 2"},
11 2 : {name : "Strain gauge 3"},
12 3 : {name : "Strain gauge 4"},
13 4 : {name : "Pressure sensor 1"},
14 5 : {name : "Pressure sensor 2"}
18 0 : {name : "Solenoid 1"},
19 1 : {name : "Solenoid 2"},
20 2 : {name : "Solenoid 3"},
21 3 : {name : "Pressure regulator"}
24 mctx.strain_gauges = {};
25 mctx.strain_gauges.ids = [0, 1, 2, 3];
26 mctx.strain_gauges.time_limit = 20;
29 document.write((new Date()).toDateString());
33 * Populates the navigation bar
35 $.fn.populateNavbar = function () {
36 var menu = $("<ul/>", {class : "menu"});
37 var sensorEntry = $("<li/>").append($("<a/>", {text : "Sensor data", href : "#"}));
38 var submenu = $("<ul/>", {class : "submenu"});
40 for (sensor in mctx.sensors) {
41 var href = mctx.api + "sensors?start_time=0&format=tsv&id=" + sensor;
42 submenu.append($("<li/>").append(
43 $("<a/>", {text : mctx.sensors[sensor].name,
44 href : href, target : "_blank"})
47 menu.append(sensorEntry.append(submenu));
49 var actuatorEntry = $("<li/>").append($("<a/>", {text : "Actuator data", href : "#"}));
50 submenu = $("<ul/>", {class : "submenu"});
52 for (actuator in mctx.actuators) {
53 var href = mctx.api + "actuators?start_time=0&format=tsv&id=" + actuator;
54 submenu.append($("<li/>").append(
55 $("<a/>", {text : mctx.actuators[actuator].name,
56 href : href, target : "_blank"})
59 menu.append(actuatorEntry.append(submenu));
64 * Sets the camera autoupdater
67 $.fn.setCamera = function () {
68 var url = mctx.api + "image";
71 //Stop updating if we can't retrieve an image!
72 this.error(function() {
78 var updater = function() {
81 parent.attr("src", "");
85 parent.attr("src", url + "#" + (new Date()).getTime());
87 setTimeout(updater, 500);
94 $.fn.setStrainGraphs = function () {
95 var sensor_url = mctx.api + "sensors";
98 var updater = function () {
99 var time_limit = mctx.strain_gauges.time_limit;
100 var responses = new Array(mctx.strain_gauges.ids.length);
102 for (var i = 0; i < mctx.strain_gauges.ids.length; i++) {
103 var parameters = {id : i, start_time: -time_limit};
104 responses[i] = $.ajax({url : sensor_url, data : parameters});
107 $.when.apply(this, responses).then(function () {
108 var data = new Array(arguments.length);
109 for (var i = 0; i < arguments.length; i++) {
110 var raw_data = arguments[i][0].data;
113 $.plot(graphdiv, data);
114 setTimeout(updater, 500);
115 }, function () {alert("boo");});