succd: roll process_state.go back into process.go

This commit is contained in:
Serge Bazanski 2024-09-28 09:48:50 +02:00
parent 185525ca30
commit 3d81a1f56c
2 changed files with 69 additions and 73 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math"
"sync"
"time"
@ -28,6 +29,74 @@ type daemon struct {
daemonState
}
// 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 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
}
piraniVolts100 ringbufferInput
piraniVolts3 ringbufferInput
rpOn bool
dpOn bool
vent momentaryOutput
pumpdown momentaryOutput
aboveRough thresholdOutput
aboveHigh thresholdOutput
}
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
}
// process runs the pain acquisition and control loop of succd.
func (d *daemon) process(ctx context.Context) {
ticker := time.NewTicker(time.Millisecond * 100)

View file

@ -1,73 +0,0 @@
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
}