succd: factor out safety status to separate struct
This commit is contained in:
parent
80f482b732
commit
239a5c40cc
|
@ -60,7 +60,7 @@ func (d *daemon) httpIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
volts, mbar := d.pirani()
|
volts, mbar := d.pirani()
|
||||||
rp := d.rpGet()
|
rp := d.rpGet()
|
||||||
dp := d.dpGet()
|
dp := d.dpGet()
|
||||||
failsafe, highpressure := d.safetyStatusGet()
|
safety := d.safetyStatusGet()
|
||||||
|
|
||||||
loadB, err := os.ReadFile("/proc/loadavg")
|
loadB, err := os.ReadFile("/proc/loadavg")
|
||||||
load := "unknown"
|
load := "unknown"
|
||||||
|
@ -75,8 +75,8 @@ func (d *daemon) httpIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
templateIndex.Execute(w, map[string]any{
|
templateIndex.Execute(w, map[string]any{
|
||||||
"failsafe": failsafe,
|
"failsafe": safety.failsafe,
|
||||||
"highpressure": highpressure,
|
"highpressure": safety.highPressure,
|
||||||
"volts": formatVolts(volts),
|
"volts": formatVolts(volts),
|
||||||
"mbar": formatMbar(mbar),
|
"mbar": formatMbar(mbar),
|
||||||
"rp": rp,
|
"rp": rp,
|
||||||
|
@ -110,10 +110,10 @@ func (d *daemon) httpStream(w http.ResponseWriter, r *http.Request) {
|
||||||
rp := d.rpGet()
|
rp := d.rpGet()
|
||||||
dp := d.dpGet()
|
dp := d.dpGet()
|
||||||
rough, high := d.vacuumStatusGet()
|
rough, high := d.vacuumStatusGet()
|
||||||
failsafe, highpressure := d.safetyStatusGet()
|
safety := d.safetyStatusGet()
|
||||||
v := struct {
|
v := struct {
|
||||||
Failsafe bool
|
Failsafe bool
|
||||||
HighPressure bool
|
HighPressure bool
|
||||||
Volts string
|
Volts string
|
||||||
Mbar string
|
Mbar string
|
||||||
MbarFloat float32
|
MbarFloat float32
|
||||||
|
@ -122,8 +122,8 @@ func (d *daemon) httpStream(w http.ResponseWriter, r *http.Request) {
|
||||||
RoughReached bool
|
RoughReached bool
|
||||||
HighReached bool
|
HighReached bool
|
||||||
}{
|
}{
|
||||||
Failsafe: failsafe,
|
Failsafe: safety.failsafe,
|
||||||
HighPressure: highpressure,
|
HighPressure: safety.highPressure,
|
||||||
Volts: formatVolts(volts),
|
Volts: formatVolts(volts),
|
||||||
Mbar: string(formatMbar(mbar)),
|
Mbar: string(formatMbar(mbar)),
|
||||||
MbarFloat: mbar,
|
MbarFloat: mbar,
|
||||||
|
|
|
@ -17,8 +17,7 @@ type daemon struct {
|
||||||
// Pirani gauge.
|
// Pirani gauge.
|
||||||
adcPirani adc
|
adcPirani adc
|
||||||
|
|
||||||
failsafe bool
|
safety safetyStatus
|
||||||
highPressure bool
|
|
||||||
|
|
||||||
gpioDiffusionPump gpio
|
gpioDiffusionPump gpio
|
||||||
gpioRoughingPump gpio
|
gpioRoughingPump gpio
|
||||||
|
@ -41,6 +40,15 @@ type daemon struct {
|
||||||
aboveHigh thresholdOutput
|
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.
|
// momentaryOutput is an output that can be triggered for 500ms.
|
||||||
type momentaryOutput struct {
|
type momentaryOutput struct {
|
||||||
// output of the block.
|
// output of the block.
|
||||||
|
@ -128,38 +136,38 @@ func (d *daemon) processOnce(_ context.Context) error {
|
||||||
// samples are still being captured.
|
// samples are still being captured.
|
||||||
if d.piraniDetection() == piraniDetectionDisconnected {
|
if d.piraniDetection() == piraniDetectionDisconnected {
|
||||||
// Unrealistic result, Pirani probe probably disconnected. Failsafe mode.
|
// Unrealistic result, Pirani probe probably disconnected. Failsafe mode.
|
||||||
if !d.failsafe {
|
if !d.safety.failsafe {
|
||||||
d.failsafe = true
|
d.safety.failsafe = true
|
||||||
klog.Errorf("Pirani probe seems disconnected; enabling failsafe mode")
|
klog.Errorf("Pirani probe seems disconnected; enabling failsafe mode")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if d.failsafe {
|
if d.safety.failsafe {
|
||||||
if mbar >= 1e2 {
|
if mbar >= 1e2 {
|
||||||
d.failsafe = false
|
d.safety.failsafe = false
|
||||||
klog.Infof("Values are plausible again; quitting failsafe mode")
|
klog.Infof("Values are plausible again; quitting failsafe mode")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if mbar >= 1e-1 {
|
if mbar >= 1e-1 {
|
||||||
if !d.highPressure {
|
if !d.safety.highPressure {
|
||||||
d.highPressure = true
|
d.safety.highPressure = true
|
||||||
klog.Errorf("Pressure is too high; enabling diffusion pump lockout")
|
klog.Errorf("Pressure is too high; enabling diffusion pump lockout")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if d.highPressure {
|
if d.safety.highPressure {
|
||||||
d.highPressure = false
|
d.safety.highPressure = false
|
||||||
klog.Infof("Pressure is low enough for diffusion pump operation; quitting diffusion pump lockout")
|
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.aboveRough.output = true
|
||||||
d.aboveHigh.output = true
|
d.aboveHigh.output = true
|
||||||
d.dpOn = false
|
d.dpOn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.highPressure {
|
if d.safety.highPressure {
|
||||||
d.dpOn = false
|
d.dpOn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,12 +295,10 @@ func (d *daemon) vacuumStatusGet() (rough, high bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *daemon) safetyStatusGet() (failsafe, highPressure bool) {
|
func (d *daemon) safetyStatusGet() safetyStatus {
|
||||||
d.mu.RLock()
|
d.mu.RLock()
|
||||||
defer d.mu.RUnlock()
|
defer d.mu.RUnlock()
|
||||||
failsafe = d.failsafe
|
return d.safety
|
||||||
highPressure = d.highPressure
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pumpDownPressed toggles the pump down relay for 500ms.
|
// pumpDownPressed toggles the pump down relay for 500ms.
|
||||||
|
|
Loading…
Reference in a new issue