From 239a5c40cc1543f58dfb3436b5b67285392c4dde Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Sat, 28 Sep 2024 07:35:45 +0200 Subject: [PATCH] succd: factor out safety status to separate struct --- succbone/succd/http.go | 16 ++++++++-------- succbone/succd/process.go | 38 ++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/succbone/succd/http.go b/succbone/succd/http.go index 43bee92..fd39c87 100644 --- a/succbone/succd/http.go +++ b/succbone/succd/http.go @@ -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, diff --git a/succbone/succd/process.go b/succbone/succd/process.go index 7d408ba..313af1d 100644 --- a/succbone/succd/process.go +++ b/succbone/succd/process.go @@ -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.