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

@ -60,7 +60,7 @@ func (d *daemon) httpIndex(w http.ResponseWriter, r *http.Request) {
volts, mbar := d.pirani()
rp := d.rpGet()
dp := d.dpGet()
failsafe, highpressure := d.safetyStatusGet()
safety := d.safetyStatusGet()
loadB, err := os.ReadFile("/proc/loadavg")
load := "unknown"
@ -75,8 +75,8 @@ func (d *daemon) httpIndex(w http.ResponseWriter, r *http.Request) {
}
templateIndex.Execute(w, map[string]any{
"failsafe": failsafe,
"highpressure": highpressure,
"failsafe": safety.failsafe,
"highpressure": safety.highPressure,
"volts": formatVolts(volts),
"mbar": formatMbar(mbar),
"rp": rp,
@ -110,10 +110,10 @@ func (d *daemon) httpStream(w http.ResponseWriter, r *http.Request) {
rp := d.rpGet()
dp := d.dpGet()
rough, high := d.vacuumStatusGet()
failsafe, highpressure := d.safetyStatusGet()
safety := d.safetyStatusGet()
v := struct {
Failsafe bool
HighPressure bool
Failsafe bool
HighPressure bool
Volts string
Mbar string
MbarFloat float32
@ -122,8 +122,8 @@ func (d *daemon) httpStream(w http.ResponseWriter, r *http.Request) {
RoughReached bool
HighReached bool
}{
Failsafe: failsafe,
HighPressure: highpressure,
Failsafe: safety.failsafe,
HighPressure: safety.highPressure,
Volts: formatVolts(volts),
Mbar: string(formatMbar(mbar)),
MbarFloat: mbar,

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.