succd: factor out safety status to separate struct

This commit is contained in:
Serge Bazanski 2024-09-28 07:35:45 +02:00
parent 80f482b732
commit 239a5c40cc
2 changed files with 30 additions and 24 deletions

View file

@ -17,8 +17,7 @@ type daemon struct {
// Pirani gauge.
adcPirani adc
failsafe bool
highPressure bool
safety safetyStatus
gpioDiffusionPump gpio
gpioRoughingPump gpio
@ -41,6 +40,15 @@ type daemon struct {
aboveHigh thresholdOutput
}
type safetyStatus struct {
// failsafe mode is enabled when the pirani gauge appears to be
// disconnected, and is disabled only when an atmosphere is read.
failsafe bool
// highPressure mode is enabled when the pressure reading is above 1e-1
// mbar, locking out the diffusion pump from being enabled.
highPressure bool
}
// momentaryOutput is an output that can be triggered for 500ms.
type momentaryOutput struct {
// output of the block.
@ -128,38 +136,38 @@ func (d *daemon) processOnce(_ context.Context) error {
// samples are still being captured.
if d.piraniDetection() == piraniDetectionDisconnected {
// Unrealistic result, Pirani probe probably disconnected. Failsafe mode.
if !d.failsafe {
d.failsafe = true
if !d.safety.failsafe {
d.safety.failsafe = true
klog.Errorf("Pirani probe seems disconnected; enabling failsafe mode")
}
} else {
if d.failsafe {
if d.safety.failsafe {
if mbar >= 1e2 {
d.failsafe = false
d.safety.failsafe = false
klog.Infof("Values are plausible again; quitting failsafe mode")
}
}
}
if mbar >= 1e-1 {
if !d.highPressure {
d.highPressure = true
if !d.safety.highPressure {
d.safety.highPressure = true
klog.Errorf("Pressure is too high; enabling diffusion pump lockout")
}
} else {
if d.highPressure {
d.highPressure = false
if d.safety.highPressure {
d.safety.highPressure = false
klog.Infof("Pressure is low enough for diffusion pump operation; quitting diffusion pump lockout")
}
}
if d.failsafe {
if d.safety.failsafe {
d.aboveRough.output = true
d.aboveHigh.output = true
d.dpOn = false
}
if d.highPressure {
if d.safety.highPressure {
d.dpOn = false
}
@ -287,12 +295,10 @@ func (d *daemon) vacuumStatusGet() (rough, high bool) {
return
}
func (d *daemon) safetyStatusGet() (failsafe, highPressure bool) {
func (d *daemon) safetyStatusGet() safetyStatus {
d.mu.RLock()
defer d.mu.RUnlock()
failsafe = d.failsafe
highPressure = d.highPressure
return
return d.safety
}
// pumpDownPressed toggles the pump down relay for 500ms.