diff --git a/scoring_display.go b/scoring_display.go index b17ddbd..d521f8e 100644 --- a/scoring_display.go +++ b/scoring_display.go @@ -64,6 +64,8 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) { matchLoadTeamsListener := mainArena.matchLoadTeamsNotifier.Listen() defer close(matchLoadTeamsListener) + matchTimeListener := mainArena.matchTimeNotifier.Listen() + defer close(matchTimeListener) reloadDisplaysListener := mainArena.reloadDisplaysNotifier.Listen() defer close(reloadDisplaysListener) @@ -73,6 +75,11 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) { log.Printf("Websocket error: %s", err) return } + err = websocket.Write("matchTime", MatchTimeMessage{mainArena.MatchState, int(mainArena.lastMatchTimeSec)}) + if err != nil { + log.Printf("Websocket error: %s", err) + return + } // Spin off a goroutine to listen for notifications and pass them on through the websocket. go func() { @@ -86,6 +93,12 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) { } messageType = "score" message = *score + case matchTimeSec, ok := <-matchTimeListener: + if !ok { + return + } + messageType = "matchTime" + message = MatchTimeMessage{mainArena.MatchState, matchTimeSec.(int)} case _, ok := <-reloadDisplaysListener: if !ok { return diff --git a/static/js/scoring_display.js b/static/js/scoring_display.js index 3ad5131..9493613 100644 --- a/static/js/scoring_display.js +++ b/static/js/scoring_display.js @@ -8,6 +8,7 @@ var selectedStack = 0; var numStacks = 10; var stacks; var stackScoreChanged = false; +var scoreCommitted = false; function Stack() { this.Totes = 0; @@ -59,15 +60,15 @@ var handleScore = function(data) { $("#autoScore").show(); $("#teleopCommands").hide(); $("#teleopScore").hide(); - $("#commitMatchScore").hide(); $("#waitingMessage").hide(); + scoreCommitted = false; } else if (!data.TeleopCommitted) { $("#autoCommands").hide(); $("#autoScore").hide(); $("#teleopCommands").show(); $("#teleopScore").show(); - $("#commitMatchScore").show(); $("#waitingMessage").hide(); + scoreCommitted = false; } else { $("#autoCommands").hide(); $("#autoScore").hide(); @@ -75,6 +76,7 @@ var handleScore = function(data) { $("#teleopScore").hide(); $("#commitMatchScore").hide(); $("#waitingMessage").show(); + scoreCommitted = true; } }; @@ -146,6 +148,15 @@ var handleKeyPress = function(event) { } }; +// Handles a websocket message to update the match status. +var handleMatchTime = function(data) { + if (matchStates[data.MatchState] == "POST_MATCH" && !scoreCommitted) { + $("#commitMatchScore").show(); + } else { + $("#commitMatchScore").hide(); + } +}; + // Updates the stack grid to highlight only the active stack. var updateSelectedStack = function() { for (i = 0; i < numStacks; i++) { @@ -176,7 +187,8 @@ var commitMatchScore = function() { $(function() { // Set up the websocket back to the server. websocket = new CheesyWebsocket("/displays/scoring/" + alliance + "/websocket", { - score: function(event) { handleScore(event.data); } + score: function(event) { handleScore(event.data); }, + matchTime: function(event) { handleMatchTime(event.data); } }); updateSelectedStack(); diff --git a/templates/scoring_display.html b/templates/scoring_display.html index 42e4d2f..0d61872 100644 --- a/templates/scoring_display.html +++ b/templates/scoring_display.html @@ -138,6 +138,7 @@ + {{end}} {{define "stack"}}