Documentation
¶
Index ¶
- Variables
- func FormatFanOriginalState(state persistence.FanOriginalState) string
- type DefaultFanController
- func (f *DefaultFanController) GetFanId() string
- func (f *DefaultFanController) GetLastSetPwm() (int, bool)
- func (f *DefaultFanController) GetRpmAvg() (float64, bool)
- func (f *DefaultFanController) GetStatistics() FanControllerStatistics
- func (f *DefaultFanController) GetStatus() status.Status
- func (f *DefaultFanController) IsInitializing() bool
- func (f *DefaultFanController) Run(ctx context.Context) (err error)
- func (f *DefaultFanController) RunInitialization(ctx context.Context) (map[int]float64, error)
- func (f *DefaultFanController) RunInitializationAndRestore(ctx context.Context) (curveData map[int]float64, err error)
- func (f *DefaultFanController) SetClock(clock util.Clock)
- func (f *DefaultFanController) SetCurveCycles(cycles <-chan struct{})
- func (f *DefaultFanController) SetWarnings(store *warnings.Store)
- func (f *DefaultFanController) UpdateCurve(curve curves.SpeedCurve)
- func (f *DefaultFanController) UpdateFanSpeed() error
- type FanController
- type FanControllerStatistics
- type FanCurveAnalyzer
- type FanStateSnapshot
Constants ¶
This section is empty.
Variables ¶
var ( ErrFanStalledAtMaxPwm = errors.New("fan stalled at max pwm") // ErrCurveEvaluation is returned (wrapped) by UpdateFanSpeed when the curve of the fan can't be evaluated. // The onSensorFailure action of the fan has been applied then, and the controller keeps running. ErrCurveEvaluation = errors.New("curve evaluation failed") // ErrPwmWriteFailed is returned (wrapped) by UpdateFanSpeed when setting the PWM value of the fan // kept failing for pwmWriteFailureTimeout. The controller stops then. ErrPwmWriteFailed = errors.New("setting the PWM value kept failing") )
Functions ¶
func FormatFanOriginalState ¶
func FormatFanOriginalState(state persistence.FanOriginalState) string
FormatFanOriginalState formats a saved original fan state for log messages.
Types ¶
type DefaultFanController ¶
type DefaultFanController struct {
// contains filtered or unexported fields
}
func NewFanController ¶
func NewFanController( persistence persistence.Persistence, fan fans.Fan, curve curves.SpeedCurve, controlLoop control_loop.ControlLoop, updateRate time.Duration, assumePwmMapIdentity bool, ) *DefaultFanController
func (*DefaultFanController) GetFanId ¶
func (f *DefaultFanController) GetFanId() string
func (*DefaultFanController) GetLastSetPwm ¶
func (f *DefaultFanController) GetLastSetPwm() (int, bool)
GetLastSetPwm returns the raw pwm value (after applying the pwmMap) that the controller last set to the fan, and false if it hasn't set one yet. Safe to call while the controller is running.
func (*DefaultFanController) GetRpmAvg ¶
func (f *DefaultFanController) GetRpmAvg() (float64, bool)
GetRpmAvg returns the RPM moving average of the fan, and false until the RPM monitor has seeded it (it starts after the fan initialization). Safe to call while the controller is running.
func (*DefaultFanController) GetStatistics ¶
func (f *DefaultFanController) GetStatistics() FanControllerStatistics
GetStatistics returns a copy of the controller statistics. Safe to call while the controller is running.
func (*DefaultFanController) GetStatus ¶
func (f *DefaultFanController) GetStatus() status.Status
GetStatus returns the current state of the controller. Safe to call while the controller is running.
func (*DefaultFanController) IsInitializing ¶
func (f *DefaultFanController) IsInitializing() bool
IsInitializing returns true while Run analyzes the fan or runs the setPwm -> getPwm sweep (or waits for the initialization lock to do so).
func (*DefaultFanController) Run ¶
func (f *DefaultFanController) Run(ctx context.Context) (err error)
Run controls the fan until ctx is done or an error occurs, and restores the fan settings when it stops. A panic in Run or one of its goroutines is returned as an error, and also restores the fan settings if fan2go may have written to the fan already.
func (*DefaultFanController) RunInitialization ¶
RunInitialization runs the fan initialization sequence. If it fails, the fan settings are restored. If it succeeds, the fan is left in manual mode, at the last PWM value of the analysis. If runFanInitializationInParallel is false, it waits until no other fan is being initialized.
func (*DefaultFanController) RunInitializationAndRestore ¶
func (f *DefaultFanController) RunInitializationAndRestore(ctx context.Context) (curveData map[int]float64, err error)
RunInitializationAndRestore runs the fan initialization sequence (see RunInitialization) on its own, outside of Run (e.g. for `fan2go fan init`), and restores the fan settings afterwards, also if it panics (unless it failed before it wrote to the fan). A panic is returned as an error. It measures everything again (the setPwmToGetPwmMap, the pwmMap and the RPM curve) without using the saved analysis data, and replaces the saved data only if it succeeds: a failed or interrupted analysis keeps it. Must not be called while Run is running on the same controller.
func (*DefaultFanController) SetClock ¶
func (f *DefaultFanController) SetClock(clock util.Clock)
SetClock replaces the time source used for all waits, tickers and timestamps of the controller. Intended for tests, which can then advance time deterministically instead of sleeping.
func (*DefaultFanController) SetCurveCycles ¶
func (f *DefaultFanController) SetCurveCycles(cycles <-chan struct{})
func (*DefaultFanController) SetWarnings ¶
func (f *DefaultFanController) SetWarnings(store *warnings.Store)
SetWarnings sets the store the controller reports the warnings it detects about the fan to. Must not be called while Run is running.
func (*DefaultFanController) UpdateCurve ¶
func (f *DefaultFanController) UpdateCurve(curve curves.SpeedCurve)
func (*DefaultFanController) UpdateFanSpeed ¶
func (f *DefaultFanController) UpdateFanSpeed() error
UpdateFanSpeed updates the fan speed by: - calculating the target PWM value using the control loop and fan curve - applying clamping - mapping the resulting target value to the [minPwm, maxPwm] range of the fan - applying sanity checks to ensure the fan never stops (if specified)
If the curve can't be evaluated, the onSensorFailure action of the fan is applied instead (see handleCurveFailure), and an error wrapping ErrCurveEvaluation is returned. Once the curve can be evaluated again, normal control resumes.
returns ErrFanStalledAtMaxPwm if no rpm is detected even at fan.maxPwm
type FanController ¶
type FanController interface {
// Run starts the control loop
Run(ctx context.Context) error
GetFanId() string
GetStatistics() FanControllerStatistics
// GetLastSetPwm returns the raw pwm value (after applying the pwmMap) that the controller
// last set to the fan, and false if it hasn't set one yet. Safe to call while the controller is running.
GetLastSetPwm() (int, bool)
// GetRpmAvg returns the RPM moving average of the fan, and false until the controller's RPM monitor
// has seeded it. Safe to call while the controller is running.
GetRpmAvg() (float64, bool)
// GetStatus returns the current state of the controller. Safe to call while the controller is running.
GetStatus() status.Status
UpdateFanSpeed() error
// UpdateCurve dynamically updates the curve reference
UpdateCurve(curve curves.SpeedCurve)
// SetCurveCycles sets the notifications of the curve evaluator (see curves.CurveEvaluator.Subscribe)
// that drive the update loop. Must be called before Run.
SetCurveCycles(cycles <-chan struct{})
// RunInitialization runs the fan initialization sequence.
RunInitialization(ctx context.Context) (map[int]float64, error)
// IsInitializing returns true while Run analyzes the fan (or waits to do so) because it has no usable saved
// fan curve data or setPwmToGetPwmMap. Safe to call while the controller is running.
IsInitializing() bool
}
type FanControllerStatistics ¶
type FanControllerStatistics struct {
UnexpectedPwmValueCount int
// PwmReadGlitchCount is the number of PWM mismatches of the pwmValueChangedByThirdParty check that a second
// read didn't confirm (see pendingConfirmation)
PwmReadGlitchCount int
// ControlModeReadGlitchCount is the number of control mode mismatches of the fanModeChangedByThirdParty check
// that a second read didn't confirm
ControlModeReadGlitchCount int
IncreasedMinPwmCount int
MinPwmOffset int
// StallCount is the number of times the stall check of a fan without neverStop found the fan stopped
// (once per stall, see checkStall)
StallCount int
// KickStartCount is the number of kicks that should start the fan from standstill (each attempt counts)
KickStartCount int
// FailedKickStartCount is the number of kicks after which the RPM sensor didn't show the fan spinning
FailedKickStartCount int
// KickStartPwm is the PWM value (before the pwmMap) of the last kick, 0 if there was none in this Run
KickStartPwm int
}
type FanCurveAnalyzer ¶
type FanCurveAnalyzer struct {
// contains filtered or unexported fields
}
func NewFanCurveAnalyzer ¶
func NewFanCurveAnalyzer( fanController *DefaultFanController, ) *FanCurveAnalyzer
func (*FanCurveAnalyzer) RunInitializationSequence ¶
type FanStateSnapshot ¶
type FanStateSnapshot struct {
// the ControlMode the fan was in before the controller started,
// nil if it is unknown (not readable, or reading it failed)
ControlMode *fans.ControlMode
// the raw pwm value read from the fan before the controller started,
// nil if it is unknown (not readable, or reading it failed)
// Note: this is the raw value, no pwmMap is applied to it
PwmValue *int
// the driver specific value behind ControlModeAutomatic (e.g. pwm_enable=5 of hwmon fans),
// nil if unknown or not applicable (see fans.AutomaticControlModeKeeper)
AutomaticControlModeValue *int
}