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 piraniVolts100 ringbufferInput piraniVolts3 ringbufferInput rpOn bool dpOn bool 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 ) func piraniVoltsToMbar(v float32) float32 { // Per Pirani probe docs. bar := math.Pow(10.0, float64(v)-8.5) return float32(bar * 1000.0) } // piraniDetection guesses whether the pirani gauge is connected. func (d *daemonState) piraniDetection() piraniDetection { if !d.piraniVolts3.saturated() { return piraniDetectionUnknown } mbar := piraniVoltsToMbar(d.piraniVolts3.avg) if mbar < 4e-6 { return piraniDetectionDisconnected } return piraniDetectionConnected } func (d *daemonState) pirani() (volts float32, mbar float32) { volts = d.piraniVolts100.avg mbar = piraniVoltsToMbar(volts) return } func (d *daemonState) vacuumStatus() (rough, high bool) { rough = !d.aboveRough.output high = !d.aboveHigh.output return }