mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Add PLC integration for field sensors, motors, and lights.
This commit is contained in:
@@ -98,7 +98,7 @@ func (web *Web) audienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.R
|
||||
BlueScore *game.Score
|
||||
RedScoreSummary *game.ScoreSummary
|
||||
BlueScoreSummary *game.ScoreSummary
|
||||
}{web.arena.RedRealtimeScore.CurrentScore, web.arena.BlueRealtimeScore.CurrentScore,
|
||||
}{&web.arena.RedRealtimeScore.CurrentScore, &web.arena.BlueRealtimeScore.CurrentScore,
|
||||
web.arena.RedScoreSummary(), web.arena.BlueScoreSummary()}
|
||||
err = websocket.Write("realtimeScore", data)
|
||||
if err != nil {
|
||||
@@ -160,7 +160,7 @@ func (web *Web) audienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.R
|
||||
BlueScore *game.Score
|
||||
RedScoreSummary *game.ScoreSummary
|
||||
BlueScoreSummary *game.ScoreSummary
|
||||
}{web.arena.RedRealtimeScore.CurrentScore, web.arena.BlueRealtimeScore.CurrentScore,
|
||||
}{&web.arena.RedRealtimeScore.CurrentScore, &web.arena.BlueRealtimeScore.CurrentScore,
|
||||
web.arena.RedScoreSummary(), web.arena.BlueScoreSummary()}
|
||||
case _, ok := <-scorePostedListener:
|
||||
if !ok {
|
||||
|
||||
@@ -415,7 +415,7 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
|
||||
// Send out the status again after handling the command, as it most likely changed as a result.
|
||||
err = websocket.Write("status", web.arena)
|
||||
err = websocket.Write("status", web.arena.GetStatus())
|
||||
if err != nil {
|
||||
log.Printf("Websocket error: %s", err)
|
||||
return
|
||||
@@ -541,7 +541,7 @@ func (web *Web) commitMatchScore(match *model.Match, matchResult *model.MatchRes
|
||||
|
||||
func (web *Web) getCurrentMatchResult() *model.MatchResult {
|
||||
return &model.MatchResult{MatchId: web.arena.CurrentMatch.Id, MatchType: web.arena.CurrentMatch.Type,
|
||||
RedScore: web.arena.RedRealtimeScore.CurrentScore, BlueScore: web.arena.BlueRealtimeScore.CurrentScore,
|
||||
RedScore: &web.arena.RedRealtimeScore.CurrentScore, BlueScore: &web.arena.BlueRealtimeScore.CurrentScore,
|
||||
RedCards: web.arena.RedRealtimeScore.Cards, BlueCards: web.arena.BlueRealtimeScore.Cards}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,8 +129,8 @@ func (web *Web) matchReviewEditPostHandler(w http.ResponseWriter, r *http.Reques
|
||||
|
||||
if isCurrent {
|
||||
// If editing the current match, just save it back to memory.
|
||||
web.arena.RedRealtimeScore.CurrentScore = matchResult.RedScore
|
||||
web.arena.BlueRealtimeScore.CurrentScore = matchResult.BlueScore
|
||||
web.arena.RedRealtimeScore.CurrentScore = *matchResult.RedScore
|
||||
web.arena.BlueRealtimeScore.CurrentScore = *matchResult.BlueScore
|
||||
web.arena.RedRealtimeScore.Cards = matchResult.RedCards
|
||||
web.arena.BlueRealtimeScore.Cards = matchResult.BlueCards
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena/field"
|
||||
"github.com/Team254/cheesy-arena/model"
|
||||
"net/http"
|
||||
)
|
||||
@@ -24,7 +25,12 @@ func (web *Web) fieldGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||
data := struct {
|
||||
*model.EventSettings
|
||||
AllianceStationDisplays map[string]string
|
||||
}{web.arena.EventSettings, web.arena.AllianceStationDisplays}
|
||||
FieldTestMode string
|
||||
Inputs []bool
|
||||
Counters []uint16
|
||||
Coils []bool
|
||||
}{web.arena.EventSettings, web.arena.AllianceStationDisplays, web.arena.FieldTestMode, web.arena.Plc.Inputs[:],
|
||||
web.arena.Plc.Counters[:], web.arena.Plc.Coils[:]}
|
||||
err = template.ExecuteTemplate(w, "base", data)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
@@ -54,3 +60,64 @@ func (web *Web) fieldReloadDisplaysHandler(w http.ResponseWriter, r *http.Reques
|
||||
web.arena.ReloadDisplaysNotifier.Notify(nil)
|
||||
http.Redirect(w, r, "/setup/field", 303)
|
||||
}
|
||||
|
||||
// Controls the field LEDs for testing or effect.
|
||||
func (web *Web) fieldTestPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !web.userIsAdmin(w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
if web.arena.MatchState != field.PreMatch {
|
||||
http.Error(w, "Arena must be in pre-match state", 400)
|
||||
return
|
||||
}
|
||||
|
||||
mode := r.PostFormValue("mode")
|
||||
switch mode {
|
||||
case "boiler":
|
||||
web.arena.Plc.SetBoilerMotors(true)
|
||||
web.arena.Plc.SetRotorMotors(0, 0)
|
||||
web.arena.Plc.SetRotorLights(0, 0)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{false, false, false})
|
||||
case "rotor1":
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(1, 1)
|
||||
web.arena.Plc.SetRotorLights(1, 1)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{true, false, false}, [3]bool{true, false, false})
|
||||
case "rotor2":
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(2, 2)
|
||||
web.arena.Plc.SetRotorLights(2, 2)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{false, true, false}, [3]bool{false, true, false})
|
||||
case "rotor3":
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(3, 3)
|
||||
web.arena.Plc.SetRotorLights(2, 2)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{false, false, true}, [3]bool{false, false, true})
|
||||
case "rotor4":
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(4, 4)
|
||||
web.arena.Plc.SetRotorLights(2, 2)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{false, false, false})
|
||||
case "red":
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(4, 0)
|
||||
web.arena.Plc.SetRotorLights(2, 0)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{true, true, true}, [3]bool{false, false, false})
|
||||
case "blue":
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(0, 4)
|
||||
web.arena.Plc.SetRotorLights(0, 2)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{true, true, true})
|
||||
case "flash":
|
||||
fallthrough
|
||||
default:
|
||||
web.arena.Plc.SetBoilerMotors(false)
|
||||
web.arena.Plc.SetRotorMotors(0, 0)
|
||||
web.arena.Plc.SetRotorLights(0, 0)
|
||||
web.arena.Plc.SetTouchpadLights([3]bool{false, false, false}, [3]bool{false, false, false})
|
||||
}
|
||||
|
||||
web.arena.FieldTestMode = mode
|
||||
http.Redirect(w, r, "/setup/field", 303)
|
||||
}
|
||||
|
||||
@@ -23,10 +23,7 @@ func TestSetupField(t *testing.T) {
|
||||
assert.Contains(t, recorder.Body.String(), "12345")
|
||||
assert.Contains(t, recorder.Body.String(), "selected")
|
||||
|
||||
// TODO(patrick): Replace with PLC mode.
|
||||
/*
|
||||
recorder = web.postHttpResponse("/setup/field/lights", "mode=strobe")
|
||||
assert.Equal(t, 303, recorder.Code)
|
||||
assert.Equal(t, "strobe", web.arena.Lights.currentMode)
|
||||
*/
|
||||
recorder = web.postHttpResponse("/setup/field/test", "mode=rotor2")
|
||||
assert.Equal(t, 303, recorder.Code)
|
||||
assert.Equal(t, "rotor2", web.arena.FieldTestMode)
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
eventSettings.SwitchAddress = r.PostFormValue("switchAddress")
|
||||
eventSettings.SwitchPassword = r.PostFormValue("switchPassword")
|
||||
eventSettings.BandwidthMonitoringEnabled = r.PostFormValue("bandwidthMonitoringEnabled") == "on"
|
||||
eventSettings.PlcAddress = r.PostFormValue("plcAddress")
|
||||
eventSettings.AdminPassword = r.PostFormValue("adminPassword")
|
||||
eventSettings.ReaderPassword = r.PostFormValue("readerPassword")
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ func (web *Web) newHandler() http.Handler {
|
||||
router.HandleFunc("/setup/field", web.fieldGetHandler).Methods("GET")
|
||||
router.HandleFunc("/setup/field", web.fieldPostHandler).Methods("POST")
|
||||
router.HandleFunc("/setup/field/reload_displays", web.fieldReloadDisplaysHandler).Methods("GET")
|
||||
router.HandleFunc("/setup/field/test", web.fieldTestPostHandler).Methods("POST")
|
||||
router.HandleFunc("/setup/lower_thirds", web.lowerThirdsGetHandler).Methods("GET")
|
||||
router.HandleFunc("/setup/lower_thirds/websocket", web.lowerThirdsWebsocketHandler).Methods("GET")
|
||||
router.HandleFunc("/setup/sponsor_slides", web.sponsorSlidesGetHandler).Methods("GET")
|
||||
|
||||
Reference in New Issue
Block a user