TamtamHero / fw-fanctrl

A simple systemd service to better control Framework Laptop's fan(s)
BSD 3-Clause "New" or "Revised" License
201 stars 35 forks source link

auto switch fan profiles depending on charging status #3

Closed Centurio-Macro closed 2 years ago

Centurio-Macro commented 2 years ago

This updated version enables the automatic switch between two different fan curves depending on whether the Laptop is charging or discharging. There are two new functions: updateStrategy and getBatteryChargingStatus. UpdateStrategy is called from once from init and regularly from run(). UpdateStrategy then calls getBatteryChargingStatus. getBatteryChargingStatus checks whether the charging status changed, compared to the last look up. It returns either no change, or the new charging status. updateStrategy only loads a new fan curve if the charging status changed. The config.json file is only read once, duringinit`. The config.json file contains a new key "strategyOnDischarging". The user is supposed to enter one of the defined fan curves which should be active during discharge. If no separate discharge strategy is specified, the tool uses the same strategy as for charging.

Info: this is my first Github pull request. Any feedback is appreciated. Only the changes from 19.08.2022. are relevant. The ones from 18.08. are me fuzzing around.

TamtamHero commented 2 years ago

Thanks for your contribution ! I've commented on the code itself, but feature wise, could you explain a bit why you think it is useful to have a different speed curve for AC/Battery ?

Centurio-Macro commented 2 years ago

Two different fan profiles for charging/discharging allows for a different optimization goal of the fan curve. On discharging one could have fan curve optimized for low fan speeds in order to save power while accepting a bit more heat. On charging one could have a fan curve that focuses on keeping the CPU from throttling and the system cool, at the expense of fan noise. Somebody who is interested in custom fan curves might be interested in that additional customization aswell. One user stated explicitly the desire for separate fan curves. After announcing my changes, he answered shortly and made suggestions for improvements on my code.