Track autonomous commit status separately per scoring display (fixes #27).

This commit is contained in:
Patrick Fairbank
2016-10-16 16:00:09 -07:00
parent 093b7f64f0
commit cb9a887e86
3 changed files with 28 additions and 20 deletions

View File

@@ -46,7 +46,6 @@ type MatchTiming struct {
type RealtimeScore struct {
CurrentScore Score
Cards map[string]string
AutoCommitted bool
TeleopCommitted bool
FoulsCommitted bool
}

View File

@@ -62,6 +62,7 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
} else {
score = &mainArena.blueRealtimeScore
}
autoCommitted := false
websocket, err := NewWebsocket(w, r)
if err != nil {
@@ -78,7 +79,11 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
defer close(reloadDisplaysListener)
// Send the various notifications immediately upon connection.
err = websocket.Write("score", *score)
data := struct {
Score *RealtimeScore
AutoCommitted bool
}{*score, autoCommitted}
err = websocket.Write("score", data)
if err != nil {
log.Printf("Websocket error: %s", err)
return
@@ -148,7 +153,7 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
}
if (*score).CurrentScore.AutoDefensesCrossed[intPosition-1]+
(*score).CurrentScore.DefensesCrossed[intPosition-1] < 2 {
if !(*score).AutoCommitted {
if !autoCommitted {
(*score).CurrentScore.AutoDefensesCrossed[intPosition-1]++
} else {
(*score).CurrentScore.DefensesCrossed[intPosition-1]++
@@ -165,7 +170,7 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
websocket.WriteError(err.Error())
continue
}
if !(*score).AutoCommitted {
if !autoCommitted {
if (*score).CurrentScore.AutoDefensesCrossed[intPosition-1] > 0 {
(*score).CurrentScore.AutoDefensesCrossed[intPosition-1]--
}
@@ -175,25 +180,25 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
}
}
case "autoDefenseReached":
if !(*score).AutoCommitted {
if !autoCommitted {
if (*score).CurrentScore.AutoDefensesReached < 3 {
(*score).CurrentScore.AutoDefensesReached++
}
}
case "undoAutoDefenseReached":
if !(*score).AutoCommitted {
if !autoCommitted {
if (*score).CurrentScore.AutoDefensesReached > 0 {
(*score).CurrentScore.AutoDefensesReached--
}
}
case "highGoal":
if !(*score).AutoCommitted {
if !autoCommitted {
(*score).CurrentScore.AutoHighGoals++
} else {
(*score).CurrentScore.HighGoals++
}
case "undoHighGoal":
if !(*score).AutoCommitted {
if !autoCommitted {
if (*score).CurrentScore.AutoHighGoals > 0 {
(*score).CurrentScore.AutoHighGoals--
}
@@ -203,13 +208,13 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
}
}
case "lowGoal":
if !(*score).AutoCommitted {
if !autoCommitted {
(*score).CurrentScore.AutoLowGoals++
} else {
(*score).CurrentScore.LowGoals++
}
case "undoLowGoal":
if !(*score).AutoCommitted {
if !autoCommitted {
if (*score).CurrentScore.AutoLowGoals > 0 {
(*score).CurrentScore.AutoLowGoals--
}
@@ -219,35 +224,35 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
}
}
case "challenge":
if (*score).AutoCommitted {
if autoCommitted {
if (*score).CurrentScore.Challenges < 3 {
(*score).CurrentScore.Challenges++
}
}
case "undoChallenge":
if (*score).AutoCommitted {
if autoCommitted {
if (*score).CurrentScore.Challenges > 0 {
(*score).CurrentScore.Challenges--
}
}
case "scale":
if (*score).AutoCommitted {
if autoCommitted {
if (*score).CurrentScore.Scales < 3 {
(*score).CurrentScore.Scales++
}
}
case "undoScale":
if (*score).AutoCommitted {
if autoCommitted {
if (*score).CurrentScore.Scales > 0 {
(*score).CurrentScore.Scales--
}
}
case "commit":
if mainArena.MatchState != PRE_MATCH || mainArena.currentMatch.Type == "test" {
(*score).AutoCommitted = true
autoCommitted = true
}
case "uncommitAuto":
(*score).AutoCommitted = false
autoCommitted = false
case "commitMatch":
if mainArena.MatchState != POST_MATCH {
// Don't allow committing the score until the match is over.
@@ -255,7 +260,7 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
continue
}
(*score).AutoCommitted = true
autoCommitted = true
(*score).TeleopCommitted = true
mainArena.scoringStatusNotifier.Notify(nil)
default:
@@ -266,7 +271,11 @@ func ScoringDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
mainArena.realtimeScoreNotifier.Notify(nil)
// Send out the score again after handling the command, as it most likely changed as a result.
err = websocket.Write("score", *score)
data = struct {
Score *RealtimeScore
AutoCommitted bool
}{*score, autoCommitted}
err = websocket.Write("score", data)
if err != nil {
log.Printf("Websocket error: %s", err)
return

View File

@@ -9,7 +9,7 @@ var scoreCommitted = false;
// Handles a websocket message to update the realtime scoring fields.
var handleScore = function(data) {
// Update autonomous period values.
var score = data.CurrentScore;
var score = data.Score.CurrentScore;
$("#autoDefense1Crossings").text(score.AutoDefensesCrossed[0]);
$("#autoDefense2Crossings").text(score.AutoDefensesCrossed[1]);
$("#autoDefense3Crossings").text(score.AutoDefensesCrossed[2]);
@@ -38,7 +38,7 @@ var handleScore = function(data) {
$("#teleopScore").hide();
$("#waitingMessage").hide();
scoreCommitted = false;
} else if (!data.TeleopCommitted) {
} else if (!data.Score.TeleopCommitted) {
$("#autoCommands").hide();
$("#autoScore").hide();
$("#teleopCommands").show();