Improve fan state detection and prepare for jupiter fan control
This commit is contained in:
parent
65d0468aeb
commit
8f448b0306
1 changed files with 16 additions and 14 deletions
30
main.py
30
main.py
|
@ -1,11 +1,12 @@
|
|||
import time
|
||||
#import subprocess
|
||||
|
||||
class Plugin:
|
||||
CPU_COUNT = 8
|
||||
SCALING_FREQUENCIES = [1700000, 2400000, 2800000]
|
||||
FAN_VOLTAGES = [0, 1000, 2000, 3000, 4000, 5000, 6000]
|
||||
FAN_SPEEDS = [0, 1000, 2000, 3000, 4000, 5000, 6000]
|
||||
|
||||
set_fan_voltage = None
|
||||
auto_fan = True
|
||||
|
||||
# CPU stuff
|
||||
|
||||
|
@ -74,36 +75,37 @@ class Plugin:
|
|||
# Fan stuff
|
||||
|
||||
async def set_fan_tick(self, tick: int):
|
||||
self.set_fan_voltage = tick # cache voltage set to echo back in get_fan_tick()
|
||||
if tick >= len(self.FAN_VOLTAGES):
|
||||
if tick >= len(self.FAN_SPEEDS):
|
||||
# automatic mode
|
||||
self.auto_fan = True
|
||||
write_to_sys("/sys/class/hwmon/hwmon5/recalculate", 0)
|
||||
write_to_sys("/sys/class/hwmon/hwmon5/fan1_target", 4099) # 4099 is default
|
||||
#subprocess.run(["systemctl", "start", "jupiter-fan-control.service"])
|
||||
else:
|
||||
# manual voltage
|
||||
self.auto_fan = False
|
||||
write_to_sys("/sys/class/hwmon/hwmon5/recalculate", 1)
|
||||
write_to_sys("/sys/class/hwmon/hwmon5/fan1_target", self.FAN_VOLTAGES[tick])
|
||||
write_to_sys("/sys/class/hwmon/hwmon5/fan1_target", self.FAN_SPEEDS[tick])
|
||||
#subprocess.run(["systemctl", "stop", "jupiter-fan-control.service"])
|
||||
|
||||
async def get_fan_tick(self) -> int:
|
||||
fan_target = int(read_from_sys("/sys/class/hwmon/hwmon5/fan1_target", amount=-1).strip())
|
||||
fan_input = int(read_from_sys("/sys/class/hwmon/hwmon5/fan1_input", amount=-1).strip())
|
||||
fan_target_v = float(fan_target) / 1000
|
||||
fan_input_v = float(fan_input) / 1000
|
||||
if self.set_fan_voltage is not None:
|
||||
x = self.set_fan_voltage
|
||||
self.set_fan_voltage = None
|
||||
return x
|
||||
elif fan_target == 4099 or (int(round(fan_target_v)) != int(round(fan_input_v))):
|
||||
if self.auto_fan:
|
||||
return len(self.FAN_SPEEDS)
|
||||
elif fan_target == 4099 or (int(round(fan_target_v)) != int(round(fan_input_v)) and fan_target not in self.FAN_SPEEDS):
|
||||
# cannot read /sys/class/hwmon/hwmon5/recalculate, so guess based on available fan info
|
||||
# NOTE: the fan takes time to ramp up, so fan_target will never approximately equal fan_input
|
||||
# when fan_target was changed recently (hence set voltage caching)
|
||||
return len(self.FAN_VOLTAGES)
|
||||
return len(self.FAN_SPEEDS)
|
||||
else:
|
||||
# quantize voltage to nearest tick (price is right rules; closest without going over)
|
||||
for i in range(len(self.FAN_VOLTAGES)-1):
|
||||
if fan_target <= self.FAN_VOLTAGES[i]:
|
||||
for i in range(len(self.FAN_SPEEDS)-1):
|
||||
if fan_target <= self.FAN_SPEEDS[i]:
|
||||
return i
|
||||
return len(self.FAN_VOLTAGES)-1 # any higher value is considered as highest manual setting
|
||||
return len(self.FAN_SPEEDS)-1 # any higher value is considered as highest manual setting
|
||||
|
||||
# Battery stuff
|
||||
|
||||
|
|
Loading…
Reference in a new issue