Add Plc.IsEnabled() method and refactor places that were checking settings directly to use it instead.

This commit is contained in:
Patrick Fairbank
2020-03-22 17:42:37 -07:00
parent 27dc4a8773
commit 31505b265f
7 changed files with 18 additions and 11 deletions

View File

@@ -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]