Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add battery charge thresholds #637

Merged
merged 13 commits into from Feb 7, 2024
Merged

add battery charge thresholds #637

merged 13 commits into from Feb 7, 2024

Conversation

PurpleWazard
Copy link
Contributor

hello, ive been using auto-cpufreq since i moved from TLP however i miss being able to set charge thresholds to prolong battery health. i would like to add this feature to auto-cpufreq, this allows you to set charge thresholds to support laptops. currently this only supports lenovo laptops and thinkpads however other laptops can be added easily. this feature is by default turned off users who want to use it will have to specify.

to change and enable the battery thresholds add these lines to /etc/auto-cpufreq.conf under [battery]

enable_thresholds = true
start_threshold = 0
stop_threshold = 100

default thresholds are 0 and 100

auto-cpufreq --daemon will set the charge thresholds on boot
auto-cpufreq --monitor will set and print the charge thresholds once

there was an issue with --live so i remove it from live.

this feture requires the correct kernel modules to be loaded to identify the laptop type. example for thinkpads the thinkpad_acpi must be listed in lsmod | grep thinkpad_acpi to add the thinkpad module to thinkpads run modprobe thinkpad_acpi

there may be some bugs however i fixed all the ones i could find.

this is also my first pull request, suggestions are appreciated.

@PurpleWazard
Copy link
Contributor Author

i found a bug with reading values from the conf file im currently working on it

@AdnanHodzic
Copy link
Owner

From code POV, it LGTM.

I have 2 small requests:

1:

Only thing I would ask for is to update auto-cpufreq.conf-example file with commented examples, i.e:

# Add battery charging threshold (currently only available to Lenovo)
#enable_thresholds = true
#start_threshold = 0
#stop_threshold = 100

and update README file accordingly, maybe also add this part, just rephrase it if needed:

this feture requires the correct kernel modules to be loaded to identify the laptop type. example for thinkpads the >thinkpad_acpi must be listed in lsmod | grep thinkpad_acpi to add the thinkpad module to thinkpads run modprobe >thinkpad_acpi

2:

Code wise, it would be good if stop_threshold = 80 following change was made, it would stop charging at 80%, as currently if 80 is set, it'll stop charging at 79%.

@shadeyg56
Copy link
Collaborator

Yeah, LGTM as well. Of course, I can't test it since I do not have a Thinkpad laptop, but it seems to be working.

and update README file accordingly,

This was going to be my main comment. We should include a new section in the README about battery thresholds including instructions, list of supported devices, and information on how to request that your device be added. I don't mind doing this myself since you might be as familiar with the structure of the README file.

@PurpleWazard
Copy link
Contributor Author

PurpleWazard commented Feb 5, 2024

Code wise, it would be good if stop_threshold = 80 following change was made, it would stop charging at 80%, as currently if 80 is set, it'll stop charging at 79%.

from what im understanding is when you set stop threshold to 80 your battery says it stops at 79% instead? this could be your windows manager or desktop environment, ive noticed when reading battery percentage is could be + or - 1%

or it could be that there is always a small load on the battery when its pluged in. this could be battery controllers, bios, lenovo stuff? example on my thinkpad with battery thresholds set while plugged in the battery percentage dropped ~7% over the course of 3 hours
my suggestion to your problem is set the stop threshold to 81

as for the readme and conf example sure i can add it and shadyg56 if you would like to help me out that would be great!

@AdnanHodzic
Copy link
Owner

Clear, let's merge this and @shadeyg56 I hope you will create a follow up PR to update the README.

@PurpleWazard thank you for your contribution, you will be credited for your work as part of future release.

@AdnanHodzic AdnanHodzic merged commit 1abad4d into AdnanHodzic:master Feb 7, 2024
@PurpleWazard PurpleWazard deleted the battery branch February 9, 2024 21:37
shadeyg56 pushed a commit to shadeyg56/auto-cpufreq that referenced this pull request Feb 12, 2024
* added battery files

* finished main battery script

* added battery_script in auto_cpufreq

* fix some errors with batterys

* setup some battery stat printing

* added battery config printing to monitor and live modes

* fix some bugs now works on daemon and monitor mode

* cleaned up battery.py

* started to fix writing issue

* still debuging fixes

* bug fixed thinkpad stop threshold cant do below 65

* updated auto-cpufreq.conf-example with battery thresholds
rootCircle pushed a commit to rootCircle/auto-cpufreq that referenced this pull request Feb 16, 2024
* added battery files

* finished main battery script

* added battery_script in auto_cpufreq

* fix some errors with batterys

* setup some battery stat printing

* added battery config printing to monitor and live modes

* fix some bugs now works on daemon and monitor mode

* cleaned up battery.py

* started to fix writing issue

* still debuging fixes

* bug fixed thinkpad stop threshold cant do below 65

* updated auto-cpufreq.conf-example with battery thresholds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants