Files
cheesy-arena-lite/static/js/fta_display.js

77 lines
3.6 KiB
JavaScript
Raw Normal View History

2014-08-23 23:41:15 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: austin.linux@gmail.com (Austin Schuh)
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Client-side logic for the FTA diagnostic display.
var websocket;
// Handles a websocket message to update the team connection status.
var handleArenaStatus = function(data) {
2014-08-23 23:41:15 -07:00
// Update the team status view.
$.each(data.AllianceStations, function(station, stationStatus) {
if (stationStatus.Team) {
$("#status" + station + " .team").text(stationStatus.Team.Id);
} else {
$("#status" + station + " .team").text("");
}
2014-08-23 23:41:15 -07:00
if (stationStatus.DsConn) {
var dsConn = stationStatus.DsConn;
$("#status" + station + " .ds-status").attr("data-status-ok", dsConn.DsLinked);
2017-09-23 18:07:33 -07:00
$("#status" + station + " .radio-status").attr("data-status-ok", dsConn.RadioLinked);
$("#status" + station + " .robot-status").attr("data-status-ok", dsConn.RobotLinked);
2014-08-23 23:41:15 -07:00
if (stationStatus.DsConn.SecondsSinceLastRobotLink > 1 && stationStatus.DsConn.SecondsSinceLastRobotLink < 1000) {
$("#status" + station + " .robot-status").text(stationStatus.DsConn.SecondsSinceLastRobotLink.toFixed());
} else {
$("#status" + station + " .robot-status").text("");
}
var lowBatteryThreshold = 6;
2018-09-03 12:51:52 -07:00
if (matchStates[data.MatchState] === "PRE_MATCH") {
lowBatteryThreshold = 12;
}
2014-08-23 23:41:15 -07:00
$("#status" + station + " .battery-status").attr("data-status-ok",
dsConn.BatteryVoltage > lowBatteryThreshold && dsConn.RobotLinked);
$("#status" + station + " .battery-status").text(dsConn.BatteryVoltage.toFixed(1) + "V");
2014-08-23 23:41:15 -07:00
$("#status" + station + " .trip-time").attr("data-status-ok", true);
$("#status" + station + " .trip-time").text(dsConn.DsRobotTripTimeMs.toFixed(1) + "ms");
2014-08-23 23:41:15 -07:00
$("#status" + station + " .packet-loss").attr("data-status-ok", true);
$("#status" + station + " .packet-loss").text(dsConn.MissedPacketCount);
2014-08-23 23:41:15 -07:00
} else {
$("#status" + station + " .ds-status").attr("data-status-ok", "");
2015-06-20 23:54:14 -07:00
$("#status" + station + " .ds-status").text("");
2017-09-23 18:07:33 -07:00
$("#status" + station + " .radio-status").attr("data-status-ok", "");
$("#status" + station + " .radio-status").text("");
2014-08-23 23:41:15 -07:00
$("#status" + station + " .robot-status").attr("data-status-ok", "");
$("#status" + station + " .robot-status").text("");
$("#status" + station + " .battery-status").attr("data-status-ok", "");
$("#status" + station + " .battery-status").text("");
$("#status" + station + " .trip-time").attr("data-status-ok", "");
$("#status" + station + " .trip-time").text("");
$("#status" + station + " .packet-loss").attr("data-status-ok", "");
$("#status" + station + " .packet-loss").text("");
}
if (stationStatus.Estop) {
2014-08-23 23:41:15 -07:00
$("#status" + station + " .bypass-status-fta").attr("data-status-ok", false);
$("#status" + station + " .bypass-status-fta").text("ES");
} else if (stationStatus.Bypass) {
$("#status" + station + " .bypass-status-fta").attr("data-status-ok", false);
$("#status" + station + " .bypass-status-fta").text("B");
} else {
$("#status" + station + " .bypass-status-fta").attr("data-status-ok", true);
$("#status" + station + " .bypass-status-fta").text("");
}
});
};
$(function() {
// Activate tooltips above the status headers.
$("[data-toggle=tooltip]").tooltip({"placement": "top"});
// Set up the websocket back to the server.
websocket = new CheesyWebsocket("/displays/fta/websocket", {
arenaStatus: function(event) { handleArenaStatus(event.data); }
2014-08-23 23:41:15 -07:00
});
});