- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
def get_decrease_fan_speed_delta(fan_speed: float, delta: float, turn_off: bool):
# if the fan is already running slower than minimum speed
if fan_speed < MIN_FAN_SPEED:
# we ignore the turn_off argument and always set the fan off
return -fan_speed
# if fan would be running slower than minimum speed after decreasing it by delta:
if (fan_speed - delta) < MIN_FAN_SPEED:
if turn_off:
return -fan_speed # turn the fan off
else:
return -fan_speed + MIN_FAN_SPEED # make it run at minimum speed
return -delta
def get_increase_fan_speed_delta(fan_speed, delta):
new_fan_speed = fan_speed + delta
# if fan would be running faster than maximum speed
if new_fan_speed > 100:
return 100 - fan_speed # cap it at 100%
elif new_fan_speed < MIN_FAN_SPEED:
return MIN_FAN_SPEED - fan_speed # jump to minimum fan speed
return delta
def compute_fan_speed_delta(temp: float, temp_delta: float, fan_speed: float):
if temp >= HOT:
return get_increase_fan_speed_delta(fan_speed, 100.0)
if temp <= COLD:
# if temperature is decreasing, we slowly decrease the fan speed
if temp_delta < 0.0:
return get_decrease_fan_speed_delta(fan_speed, FAN_DELTA, turn_off=True)
# if temperature is constant or increasing we don't change fan speed
# until it rises above COLD
return 0.0
# if temperature is decreasing we decrease fan speed slowly
if temp_delta < 0.0:
return get_decrease_fan_speed_delta(fan_speed, FAN_DELTA, turn_off=False)
# if temperature is increasing we increase fan speed slowly
if temp_delta > 0.0:
return get_increase_fan_speed_delta(fan_speed, FAN_DELTA)
# if temperature is not changing, don't change the fan speed
return 0.0