Merge branch 'master' into lite

This commit is contained in:
Ken Schenke
2020-04-16 18:02:00 -05:00
2 changed files with 14 additions and 0 deletions

View File

@@ -206,6 +206,7 @@ func (arena *Arena) LoadMatch(match *model.Match) error {
arena.BlueScore = new(game.Score) arena.BlueScore = new(game.Score)
arena.FieldVolunteers = false arena.FieldVolunteers = false
arena.FieldReset = false arena.FieldReset = false
arena.Plc.ResetMatch()
// Notify any listeners about the new match. // Notify any listeners about the new match.
arena.MatchLoadNotifier.Notify() arena.MatchLoadNotifier.Notify()
@@ -396,6 +397,7 @@ func (arena *Arena) Update() {
enabled = true enabled = true
sendDsPacket = true sendDsPacket = true
} }
arena.Plc.ResetMatch()
case WarmupPeriod: case WarmupPeriod:
auto = true auto = true
enabled = false enabled = false

View File

@@ -27,6 +27,7 @@ type Plc struct {
oldRegisters [registerCount]uint16 oldRegisters [registerCount]uint16
oldCoils [coilCount]bool oldCoils [coilCount]bool
cycleCounter int cycleCounter int
matchResetCycles int
} }
const ( const (
@@ -193,6 +194,12 @@ func (plc *Plc) GetEthernetConnected() ([3]bool, [3]bool) {
} }
} }
// Resets the internal state of the PLC to start a new match.
func (plc *Plc) ResetMatch() {
plc.coils[matchReset] = true
plc.matchResetCycles = 0
}
// Sets the on/off state of the stack lights on the scoring table. // Sets the on/off state of the stack lights on the scoring table.
func (plc *Plc) SetStackLights(red, blue, orange, green bool) { func (plc *Plc) SetStackLights(red, blue, orange, green bool) {
plc.coils[stackLightRed] = red plc.coils[stackLightRed] = red
@@ -313,6 +320,11 @@ func (plc *Plc) writeCoils() bool {
return false return false
} }
if plc.matchResetCycles > 5 {
plc.coils[matchReset] = false // Only need a short pulse to reset the internal state of the PLC.
} else {
plc.matchResetCycles++
}
return true return true
} }