diff --git a/field/arena.go b/field/arena.go index 588035b..3af3b28 100644 --- a/field/arena.go +++ b/field/arena.go @@ -647,7 +647,7 @@ func (arena *Arena) checkCanStartMatch() error { return err } - if arena.EventSettings.PlcAddress != "" { + if arena.Plc.IsEnabled() { if !arena.Plc.IsHealthy { return fmt.Errorf("Cannot start match while PLC is not healthy.") } diff --git a/field/arena_test.go b/field/arena_test.go index aecd3ca..b80a7f1 100644 --- a/field/arena_test.go +++ b/field/arena_test.go @@ -73,12 +73,12 @@ func TestArenaCheckCanStartMatch(t *testing.T) { assert.Nil(t, arena.checkCanStartMatch()) // Check PLC constraints. - arena.EventSettings.PlcAddress = "1.2.3.4" + arena.Plc.SetAddress("1.2.3.4") err = arena.checkCanStartMatch() if assert.NotNil(t, err) { assert.Contains(t, err.Error(), "Cannot start match while PLC is not healthy") } - arena.Plc.IsHealthy = true + arena.Plc.SetAddress("") assert.Nil(t, arena.checkCanStartMatch()) } diff --git a/plc/plc.go b/plc/plc.go index fb010b2..e649c2c 100644 --- a/plc/plc.go +++ b/plc/plc.go @@ -87,11 +87,16 @@ func (plc *Plc) SetAddress(address string) { } } +// Returns true if the PLC is enabled in the configurations. +func (plc *Plc) IsEnabled() bool { + return plc.address != "" +} + // Loops indefinitely to read inputs from and write outputs to PLC. func (plc *Plc) Run() { for { if plc.handler == nil { - if plc.address == "" { + if !plc.IsEnabled() { // No PLC is configured; just allow the loop to continue to simulate inputs and outputs. plc.IsHealthy = false } else { @@ -137,13 +142,13 @@ func (plc *Plc) Run() { // Returns the state of the field emergency stop button (true if e-stop is active). func (plc *Plc) GetFieldEstop() bool { - return plc.address != "" && !plc.inputs[fieldEstop] + return plc.IsEnabled() && !plc.inputs[fieldEstop] } // Returns the state of the red and blue driver station emergency stop buttons (true if e-stop is active). func (plc *Plc) GetTeamEstops() ([3]bool, [3]bool) { var redEstops, blueEstops [3]bool - if plc.address != "" { + if plc.IsEnabled() { redEstops[0] = !plc.inputs[redEstop1] redEstops[1] = !plc.inputs[redEstop2] redEstops[2] = !plc.inputs[redEstop3] diff --git a/templates/match_play.html b/templates/match_play.html index d60f19d..a7c48f2 100644 --- a/templates/match_play.html +++ b/templates/match_play.html @@ -118,7 +118,7 @@
Referee
PLC Status
diff --git a/templates/scoring_panel.html b/templates/scoring_panel.html
index c90d0fe..94761e7 100644
--- a/templates/scoring_panel.html
+++ b/templates/scoring_panel.html
@@ -30,7 +30,7 @@
{{end}}
- {{if eq .EventSettings.PlcAddress ""}}
+ {{if not .PlcIsEnabled}}