2024-09-28 06:10:33 +00:00
|
|
|
package main
|
|
|
|
|
2024-09-28 08:22:40 +00:00
|
|
|
import "k8s.io/klog"
|
|
|
|
|
2024-09-28 06:10:33 +00:00
|
|
|
// daemonController is the control/data interface passed on to external system
|
|
|
|
// controllers, eg. the web interface.
|
|
|
|
//
|
|
|
|
// This is a subset of daemon functions limited to a safe, explicit subset.
|
|
|
|
type daemonController interface {
|
2024-09-28 12:26:24 +00:00
|
|
|
loopLoad() int64
|
2024-09-28 06:10:33 +00:00
|
|
|
// snapshot returns an internally consistent copy of the daemon state.
|
|
|
|
snapshot() *daemonState
|
|
|
|
// rpSet enables/disables the roughing pump.
|
|
|
|
rpSet(bool)
|
|
|
|
// dpSet enables/disables the diffusion pump.
|
|
|
|
dpSet(bool)
|
|
|
|
// pumpDownPress simulates a pumpdown button press.
|
|
|
|
pumpDownPress()
|
|
|
|
// ventPRess simulates a vent button press.
|
|
|
|
ventPress()
|
2024-10-26 17:42:35 +00:00
|
|
|
// returns the current gpio state of the pump down button
|
|
|
|
gpioPumpDownStatus() bool
|
|
|
|
// returns the current gpio state of the vent button
|
|
|
|
gpioVentStatus() bool
|
|
|
|
gpioBelowRoughStatus() bool
|
|
|
|
gpioBelowHighStatus() bool
|
2024-09-28 06:10:33 +00:00
|
|
|
}
|
|
|
|
|
2024-09-28 12:26:24 +00:00
|
|
|
func (d *daemon) loopLoad() int64 {
|
|
|
|
return d.load.Load()
|
|
|
|
}
|
|
|
|
|
2024-09-28 06:10:33 +00:00
|
|
|
func (d *daemon) snapshot() *daemonState {
|
|
|
|
d.mu.RLock()
|
|
|
|
ds := d.daemonState
|
|
|
|
d.mu.RUnlock()
|
|
|
|
return &ds
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) rpSet(state bool) {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
2024-09-28 08:22:40 +00:00
|
|
|
if !state && d.dpOn {
|
|
|
|
klog.Errorf("SAFETY: Refusing to disable roughing pump while diffusion pump is active")
|
|
|
|
return
|
|
|
|
}
|
2024-09-28 06:10:33 +00:00
|
|
|
d.rpOn = state
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) dpSet(state bool) {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
2024-09-28 08:22:40 +00:00
|
|
|
if state && (d.safety.failsafe || d.safety.highPressure) {
|
|
|
|
klog.Errorf("SAFETY: Refusing to enable diffusion pump with safety alerts present")
|
|
|
|
return
|
|
|
|
}
|
2024-09-28 06:10:33 +00:00
|
|
|
d.dpOn = state
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) pumpDownPress() {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
d.pumpdown.trigger()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) ventPress() {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
d.vent.trigger()
|
|
|
|
}
|
2024-10-26 17:42:35 +00:00
|
|
|
|
|
|
|
func (d *daemon) gpioPumpDownStatus() bool {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
return d.gpioBtnPumpDown.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) gpioVentStatus() bool {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
return d.gpioBtnVent.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) gpioBelowRoughStatus() bool {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
return d.gpioBelowRough.get()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *daemon) gpioBelowHighStatus() bool {
|
|
|
|
d.mu.Lock()
|
|
|
|
defer d.mu.Unlock()
|
|
|
|
return d.gpioBelowHigh.get()
|
|
|
|
}
|