Skip to content

Commit d8f5e93

Browse files
committed
staircase: Rename threshold to hysteresis
1 parent 9b12fca commit d8f5e93

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

internal/configuration/curves.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type LinearCurveConfig struct {
3030
type StaircaseCurveConfig struct {
3131
// Sensor is the id of the sensor to use for this curve
3232
Sensor string `json:"sensor"`
33-
// Threshold is the temperature threshold in degrees
34-
Threshold int `json:"threshold"`
33+
// Hysteresis configuration
34+
Hysteresis HysteresisConfig `json:"hysteresis"`
3535
// Steps is a map of temperature to relative speed value (in range of 0..255 or alternatively 0%..100%)
3636
// InSteps contains the speed values as strings (like "42" or "11%"), as read from fan2go.yaml
3737
InSteps map[int]string `mapstructure:"steps" json:"-"`
@@ -41,6 +41,11 @@ type StaircaseCurveConfig struct {
4141
Steps map[int]float64 `json:"steps" mapstructure:"-"`
4242
}
4343

44+
type HysteresisConfig struct {
45+
// Temperature drop threshold in degrees before reducing fan speed
46+
Down int `json:"down,omitempty"`
47+
}
48+
4449
type PidCurveConfig struct {
4550
// Sensor is the id of the sensor to use for this curve
4651
Sensor string `json:"sensor"`

internal/curves/staircase.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (c *StaircaseSpeedCurve) Evaluate() (value float64, err error) {
3737
targetTemp = max(targetTemp, temp)
3838
}
3939
}
40-
if targetTemp < c.LastTemp && (c.LastTemp-int(measured/1000)) < c.Config.Staircase.Threshold {
40+
if targetTemp < c.LastTemp && (c.LastTemp-int(measured/1000)) < c.Config.Staircase.Hysteresis.Down {
4141
targetTemp = c.LastTemp
4242
}
4343

internal/curves/staircase_test.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import (
1212
func createStaircaseCurveConfig(
1313
id string,
1414
sensorId string,
15-
threshold int,
15+
hysteresis configuration.HysteresisConfig,
1616
steps map[int]float64,
1717
) (curve configuration.CurveConfig) {
1818
curve = configuration.CurveConfig{
1919
ID: id,
2020
Staircase: &configuration.StaircaseCurveConfig{
21-
Sensor: sensorId,
22-
Threshold: threshold,
23-
Steps: steps,
21+
Sensor: sensorId,
22+
Hysteresis: hysteresis,
23+
Steps: steps,
2424
},
2525
}
2626
return curve
@@ -38,7 +38,9 @@ func TestStaircaseCurveWithStepsAtMin(t *testing.T) {
3838
curveConfig := createStaircaseCurveConfig(
3939
"curve",
4040
s.GetId(),
41-
8,
41+
configuration.HysteresisConfig{
42+
Down: 8,
43+
},
4244
map[int]float64{
4345
50: 30,
4446
60: 100,
@@ -69,7 +71,9 @@ func TestStaircaseCurveWithStepsInMiddle(t *testing.T) {
6971
curveConfig := createStaircaseCurveConfig(
7072
"curve",
7173
s.GetId(),
72-
8,
74+
configuration.HysteresisConfig{
75+
Down: 8,
76+
},
7377
map[int]float64{
7478
50: 30,
7579
60: 100,
@@ -121,7 +125,9 @@ func TestStaircaseCurveWithStepsAtMax(t *testing.T) {
121125
curveConfig := createStaircaseCurveConfig(
122126
"curve",
123127
s.GetId(),
124-
8,
128+
configuration.HysteresisConfig{
129+
Down: 8,
130+
},
125131
map[int]float64{
126132
50: 30,
127133
60: 100,
@@ -152,7 +158,9 @@ func TestStaircaseCurveWithNegativeTemperatures(t *testing.T) {
152158
curveConfig := createStaircaseCurveConfig(
153159
"curve_neg",
154160
s.GetId(),
155-
3,
161+
configuration.HysteresisConfig{
162+
Down: 3,
163+
},
156164
map[int]float64{
157165
-10: 10,
158166
10: 50,
@@ -192,7 +200,9 @@ func TestStaircaseCurveWithStepAtZero(t *testing.T) {
192200
curveConfig := createStaircaseCurveConfig(
193201
"curve_zero",
194202
s.GetId(),
195-
5,
203+
configuration.HysteresisConfig{
204+
Down: 5,
205+
},
196206
map[int]float64{
197207
0: 5,
198208
40: 50,

0 commit comments

Comments
 (0)