2024-09-28 06:10:33 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "math"
|
|
|
|
|
|
|
|
// daemonState contains all the state of the daemon. A copy of it can be
|
|
|
|
// requested for consumers, eg. the web view.
|
|
|
|
type daemonState struct {
|
|
|
|
safety safetyStatus
|
|
|
|
|
2024-09-28 07:35:41 +00:00
|
|
|
piraniVolts100 ringbufferInput
|
|
|
|
piraniVolts3 ringbufferInput
|
|
|
|
|
|
|
|
rpOn bool
|
|
|
|
dpOn bool
|
2024-09-28 06:10:33 +00:00
|
|
|
|
|
|
|
vent momentaryOutput
|
|
|
|
pumpdown momentaryOutput
|
|
|
|
aboveRough 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
|
|
|
|
}
|
|
|
|
|
|
|
|
type piraniDetection uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
// piraniDetectionUnknown means the system isn't yet sure whether the pirani
|
|
|
|
// gauge is connected.
|
|
|
|
piraniDetectionUnknown piraniDetection = iota
|
|
|
|
// piraniDetectionConnected means the system assumes the pirani gauge is
|
|
|
|
// connected.
|
|
|
|
piraniDetectionConnected = iota
|
|
|
|
// piraniDetectionDisconnected means the system assumes the pirani gauge is
|
|
|
|
// disconnected.
|
|
|
|
piraniDetectionDisconnected = iota
|
|
|
|
)
|
|
|
|
|
2024-09-28 07:35:41 +00:00
|
|
|
func piraniVoltsToMbar(v float32) float32 {
|
|
|
|
// Per Pirani probe docs.
|
|
|
|
bar := math.Pow(10.0, float64(v)-8.5)
|
|
|
|
return float32(bar * 1000.0)
|
|
|
|
}
|
|
|
|
|
2024-09-28 06:10:33 +00:00
|
|
|
// piraniDetection guesses whether the pirani gauge is connected.
|
|
|
|
func (d *daemonState) piraniDetection() piraniDetection {
|
2024-09-28 07:35:41 +00:00
|
|
|
if len(d.piraniVolts3.data) < int(d.piraniVolts3.limit) {
|
2024-09-28 06:10:33 +00:00
|
|
|
return piraniDetectionUnknown
|
|
|
|
}
|
2024-09-28 07:35:41 +00:00
|
|
|
mbar := piraniVoltsToMbar(d.piraniVolts3.avg)
|
2024-09-28 06:10:33 +00:00
|
|
|
if mbar < 4e-6 {
|
|
|
|
return piraniDetectionDisconnected
|
|
|
|
}
|
|
|
|
return piraniDetectionConnected
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemonState) pirani() (volts float32, mbar float32) {
|
2024-09-28 07:35:41 +00:00
|
|
|
volts = d.piraniVolts100.avg
|
|
|
|
mbar = piraniVoltsToMbar(volts)
|
2024-09-28 06:10:33 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemonState) vacuumStatus() (rough, high bool) {
|
|
|
|
rough = !d.aboveRough.output
|
|
|
|
high = !d.aboveHigh.output
|
|
|
|
return
|
|
|
|
}
|