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

Update README with new battery thresholds feature #643

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
925a9ec
Support for pyproject.toml (#576)
rootCircle Oct 13, 2023
8c61379
refactor(nix): reorganise files
isabelroses Oct 13, 2023
92ccf1d
revert: changes to module
isabelroses Oct 13, 2023
e57e789
Nix: remove darwin and fix icon
shadeyg56 Oct 13, 2023
ea6bbe4
Nix: inherit system in module
shadeyg56 Oct 13, 2023
7c260e8
auto-cpufreq-installer: removed dependence on record files for remova…
rootCircle Oct 14, 2023
80b1293
Add support for shell completion (#580)
rootCircle Oct 14, 2023
a5fe67e
Bump urllib3 from 2.0.6 to 2.0.7
dependabot[bot] Oct 17, 2023
fadf170
README: update expired discord link
shadeyg56 Oct 19, 2023
30f2035
skip temp sensor that report as 0
shadeyg56 Oct 24, 2023
68ce70b
Feature: Allow GUI to detect available update and install it (#587)
shadeyg56 Oct 27, 2023
efe92e1
Fix img link and adjust text (#584)
theDrake Oct 28, 2023
f4b8d1f
Add zenpower for AMD CPU temps (#590)
fredinj Nov 3, 2023
26806a6
Add Syntax Highlighting to the Configuration File Example (#591)
blackpill0w Nov 3, 2023
bc8bc83
fix dubious ownership error in auto-cpufreq-installer (#597)
amogus07 Nov 12, 2023
ce9d36e
v2.1.0 tag update (#605)
MusicalArtist12 Nov 22, 2023
bf1a0b4
Update README to match changes to the AUR package (#606)
MusicalArtist12 Nov 22, 2023
ba2d57c
Update snapcraft.yaml to pick up version from pyproject.toml
AdnanHodzic Nov 22, 2023
238c59e
nix: bump version to 2.1.0 and update lock file (#609)
shadeyg56 Nov 25, 2023
8aff959
Bump cryptography from 41.0.4 to 41.0.6 (#610)
dependabot[bot] Dec 10, 2023
7e8f6ed
Update README.md (#611)
avatar1024 Dec 10, 2023
1a6b36a
fix typo in dialog box (#618)
natewu Dec 17, 2023
140b18b
Update nix flake instructions (#617)
hughobrien Dec 17, 2023
b25494e
Add support for configuring/overriding "Energy Performance Preference…
murbot Dec 29, 2023
876f99a
Change check_for_update to not exit process on server connection erro…
hingen Jan 21, 2024
a757dd9
Update README: add instruction for failing buildings in case of missi…
rootCircle Jan 21, 2024
62d93a9
Add ability to build snap for both amd64 & arm64 architecture
AdnanHodzic Jan 21, 2024
9cba0be
Fix dynamic boosting being incorrectly diagnosed (#631)
PhoenixCausesOof Jan 24, 2024
ec0691e
Add battery charge thresholds limit (#637)
PurpleWazard Feb 7, 2024
18aeecb
Bump cryptography from 41.0.6 to 42.0.0 (#638)
dependabot[bot] Feb 7, 2024
7815995
enable_tresholds config file improvements (Closes: #641)
PurpleWazard Feb 10, 2024
ad67d32
README: add battery threshold sections
shadeyg56 Feb 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 160 additions & 102 deletions README.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ function setup_venv {

source "${venv_dir}/bin/activate"
python3 -m pip install --upgrade pip wheel
python3 -m pip install -r requirements.txt
}

# tool install
function install {
python3 setup.py install --record files.txt
git config --global --add safe.directory $(pwd)
python -m pip install .
mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/
cp -r images/ /usr/local/share/auto-cpufreq/
Expand Down Expand Up @@ -119,7 +119,7 @@ function manual_install {

-----

python3 setup.py install --record files.txt
pip3 install .
mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/

Expand Down Expand Up @@ -208,7 +208,7 @@ fi
}

function tool_remove {
files="files.txt"
# files="files.txt"
share_dir="/usr/local/share/auto-cpufreq/"

srv_install="/usr/local/bin/auto-cpufreq-install"
Expand Down Expand Up @@ -249,7 +249,7 @@ function tool_remove {
fi

# remove auto-cpufreq and all its supporting files
[ -f $files ] && cat $files | xargs sudo rm -rf && rm -f $files
# [ -f $files ] && cat $files | xargs sudo rm -rf && rm -f $files
[ -d $share_dir ] && rm -rf $share_dir

# files cleanup
Expand Down
20 changes: 20 additions & 0 deletions auto-cpufreq.conf-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# preferred governor.
governor = performance

# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = performance

# minimum cpu frequency (in kHz)
# example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000
# see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html
Expand All @@ -25,6 +28,9 @@ turbo = auto
# preferred governor
governor = powersave

# EPP: see available preferences by running: cat /sys/devices/system/cpu/cpu0/cpufreq/energy_performance_available_preferences
energy_performance_preference = power

# minimum cpu frequency (in kHz)
# example: for 800 MHz = 800000 kHz --> scaling_min_freq = 800000
# see conversion info: https://www.rapidtables.com/convert/frequency/mhz-to-hz.html
Expand All @@ -39,3 +45,17 @@ governor = powersave

# turbo boost setting. possible values: always, auto, never
turbo = auto

# experimental

# Add battery charging threshold (currently only available to Lenovo)
# checkout README.md for more info

# enable thresholds true or false
#enable_thresholds = true
#
# start threshold (defaults to 0 ) can be 0 - 100
#start_threshold = 0
#
# stop threshold (defaults to 100) this value must be greater or equal to 65
#stop_threshold = 100
66 changes: 66 additions & 0 deletions auto_cpufreq/battery_scripts/battery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
import subprocess
from auto_cpufreq.core import get_config, root_check

from auto_cpufreq.battery_scripts.thinkpad import *
from auto_cpufreq.battery_scripts.ideapad import *


def lsmod(module):
output = subprocess.run(['lsmod'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if module in output.stdout:
return True
else:
return False


def battery_start_threshold():
conf = get_config()
if conf.has_option("battery", "start_threshold"):
start_threshold = conf["battery"]["start_threshold"]
return int(start_threshold)
else:
return 0


def battery_stop_threshold():
conf = get_config()
if conf.has_option("battery", "stop_threshold"):
stop_threshold = conf["battery"]["stop_threshold"]
return int(stop_threshold)
else:
return 100


def battery_setup():
root_check()
conf = get_config()
if conf.has_option("battery", "enable_thresholds"):
if conf["battery"]["enable_thresholds"] == "true":
if lsmod("thinkpad_acpi"):
thinkpad_setup(battery_start_threshold(), battery_stop_threshold())
elif lsmod("ideapad_acpi"):
ideapad_setup(battery_start_threshold(), battery_stop_threshold())
else:
pass
else:
pass
else:
pass


def battery_get_thresholds():
conf = get_config()
if conf.has_option("battery", "enable_thresholds"):
if conf["battery"]["enable_thresholds"] == "true":
print("-" * 30 )
if lsmod("thinkpad_acpi"):
thinkpad_print_thresholds()
elif lsmod("ideapad_acpi"):
ideapad_print_thresholds()
else:
pass
else:
return
else:
return
44 changes: 44 additions & 0 deletions auto_cpufreq/battery_scripts/ideapad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import os
from auto_cpufreq.core import root_check


def ideapad_setup(start_threshold, stop_threshold):
root_check()
# this path is specific to ideapads
path_to_bats = '/sys/class/power_supply/'
# gets the numb of batteries
battery_count = len([name for name in os.listdir(path_to_bats) if name.startswith('BAT')])

for b in range(battery_count):

try:
with open(f'{path_to_bats}BAT{b}/charge_start_threshold', 'w') as f:
f.write(str(start_threshold) + '\n')
f.close()

with open(f'{path_to_bats}BAT{b}/charge_stop_threshold', 'w') as f:
f.write(str(stop_threshold) + '\n')
f.close()

except Exception:
pass


def ideapad_print_thresholds():
root_check()
path_to_bats = '/sys/class/power_supply/'
battery_count = len([name for name in os.listdir(path_to_bats) if name.startswith('BAT')])
print(f"number of batteries = {battery_count}")
for b in range(battery_count):
try:
with open(f'{path_to_bats}BAT{b}/charge_start_threshold', 'r') as f:
print(f'battery{b} start threshold is set to {f.read()}')
f.close()

with open(f'{path_to_bats}BAT{b}/charge_stop_threshold', 'r') as f:
print(f'battery{b} stop threshold is set to {f.read()}')
f.close()

except Exception as e:
print(f"Error reading battery thresholds: {e}")
51 changes: 51 additions & 0 deletions auto_cpufreq/battery_scripts/thinkpad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
import os
from auto_cpufreq.core import root_check


def thinkpad_setup(start_threshold, stop_threshold):
root_check()
# this path is specific to thinkpads
path_to_bats = '/sys/class/power_supply/'
# gets the numb of batteries
battery_count = len([name for name in os.listdir(path_to_bats) if name.startswith('BAT')])

for b in range(battery_count):

try:
with open(f'{path_to_bats}BAT{b}/charge_start_threshold', 'w') as f:
f.write(str(start_threshold) + '\n')
f.close()
except Exception as e:
print(f"could not write to BAT{b} start threshold")
print(e)

try:
with open(f'{path_to_bats}BAT{b}/charge_stop_threshold', 'w') as f:
f.write(str(stop_threshold) + '\n')
f.close()

except Exception as e:
print(f"could not write to BAT{b} stop threshold you might be setting it too low try < 65")
print(e)
pass


def thinkpad_print_thresholds():
root_check()
# this path is specific to thinkpads
path_to_bats = '/sys/class/power_supply/'
battery_count = len([name for name in os.listdir(path_to_bats) if name.startswith('BAT')])
print(f"number of batteries = {battery_count}")
for b in range(battery_count):
try:
with open(f'{path_to_bats}BAT{b}/charge_start_threshold', 'r') as f:
print(f'battery{b} start threshold is set to {f.read()}')
f.close()

with open(f'{path_to_bats}BAT{b}/charge_stop_threshold', 'r') as f:
print(f'battery{b} stop threshold is set to {f.read()}')
f.close()

except Exception as e:
print(f"Error reading battery thresholds: {e}")
Empty file added auto_cpufreq/bin/__init__.py
Empty file.
33 changes: 28 additions & 5 deletions bin/auto-cpufreq → auto_cpufreq/bin/auto_cpufreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from click import UsageError
from subprocess import call, run

sys.path.append("../")
# sys.path.append("../")
from auto_cpufreq.core import *
from auto_cpufreq.power_helper import *

from auto_cpufreq.battery_scripts.battery import *
# cli
@click.command()
@click.option("--monitor", is_flag=True, help="Monitor and see suggestions for CPU optimizations")
Expand All @@ -34,9 +34,10 @@
@click.option("--debug", is_flag=True, help="Show debug info (include when submitting bugs)")
@click.option("--version", is_flag=True, help="Show currently installed version")
@click.option("--donate", is_flag=True, help="Support the project")
@click.option("--completions", is_flag=False, help="Enables shell completions for bash, zsh and fish.\n Possible values bash|zsh|fish")
@click.option("--log", is_flag=True, hidden=True)
@click.option("--daemon", is_flag=True, hidden=True)
def main(config, daemon, debug, update, install, remove, live, log, monitor, stats, version, donate, force, get_state):
def main(config, daemon, debug, update, install, remove, live, log, monitor, stats, version, donate, force, get_state, completions):

# display info if config file is used
def config_info_dialog():
Expand All @@ -50,7 +51,6 @@ def config_info_dialog():
set_override(force) # Calling set override, only if force has some values

if len(sys.argv) == 1:

print("\n" + "-" * 32 + " auto-cpufreq " + "-" * 33 + "\n")
print("Automatic CPU speed & power optimizer for Linux")

Expand All @@ -67,6 +67,7 @@ def config_info_dialog():
if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled":
gnome_power_detect_snap()
tlp_service_detect_snap()
battery_setup()
while True:
footer()
gov_check()
Expand All @@ -78,6 +79,7 @@ def config_info_dialog():
elif os.getenv("PKG_MARKER") != "SNAP":
gnome_power_detect()
tlp_service_detect()
battery_setup()
while True:
footer()
gov_check()
Expand All @@ -94,6 +96,8 @@ def config_info_dialog():
config_info_dialog()
root_check()
print('\nNote: You can quit monitor mode by pressing "ctrl+c"')
battery_setup()
battery_get_thresholds()
if os.getenv("PKG_MARKER") == "SNAP":
gnome_power_detect_snap()
tlp_service_detect_snap()
Expand Down Expand Up @@ -248,7 +252,9 @@ def config_info_dialog():
elif subprocess.run(["bash", "-c", "command -v pacman >/dev/null 2>&1"]).returncode == 0 and subprocess.run(["bash", "-c", "pacman -Q auto-cpufreq >/dev/null 2>&1"]).returncode == 0:
print("Arch-based distribution with AUR support detected. Please refresh auto-cpufreq using your AUR helper.")
else:
verify_update()
is_new_update = check_for_update()
if not is_new_update:
return
ans = input("Do you want to update auto-cpufreq to the latest release? [Y/n]: ").strip().lower()
if not os.path.exists(custom_dir):
os.makedirs(custom_dir)
Expand All @@ -265,5 +271,22 @@ def config_info_dialog():
else:
print("Aborted")

elif completions:
if completions == "bash":
print("Run the below command in your current shell!\n")
print("echo 'eval \"$(_AUTO_CPUFREQ_COMPLETE=bash_source auto-cpufreq)\"' >> ~/.bashrc")
print("source ~/.bashrc")
elif completions == "zsh":
print("Run the below command in your current shell!\n")
print("echo 'eval \"$(_AUTO_CPUFREQ_COMPLETE=zsh_source auto-cpufreq)\"' >> ~/.zshrc")
print("source ~/.zshrc")
elif completions == "fish":
print("Run the below command in your current shell!\n")
print("echo '_AUTO_CPUFREQ_COMPLETE=fish_source auto-cpufreq | source' > ~/.config/fish/completions/auto-cpufreq.fish")
else:
print("Invalid Option, try bash|zsh|fish as argument to --completions")



if __name__ == "__main__":
main()
10 changes: 7 additions & 3 deletions bin/auto-cpufreq-gtk → auto_cpufreq/bin/auto_cpufreq_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
from gi.repository import Gtk, GLib
from auto_cpufreq.gui.app import ToolWindow

if __name__ == "__main__":
def main():
GLib.set_prgname("auto-cpufreq")
win = ToolWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
GLib.set_prgname("auto-cpufreq")
Gtk.main()
win.handle_update()
Gtk.main()

if __name__ == "__main__":
main()
Loading