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

Issue #698: Add --fullcharge flag to set battery thresholds to max #719

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ start_threshold = 20
stop_threshold = 80
```

Use `auto-cpufreq --fullcharge` to temporarily set thresholds 99

### Lenovo_laptop conservation mode

this works only with `lenovo_laptop` kernel module compatable laptops.
Expand Down
20 changes: 20 additions & 0 deletions auto_cpufreq/battery_scripts/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from auto_cpufreq.battery_scripts.ideapad_acpi import ideapad_acpi_setup, ideapad_acpi_print_thresholds
from auto_cpufreq.battery_scripts.ideapad_laptop import ideapad_laptop_setup, ideapad_laptop_print_thresholds

from auto_cpufreq.battery_scripts.thinkpad import thinkpad_set_fullcharge
from auto_cpufreq.battery_scripts.ideapad_acpi import ideapad_acpi_set_fullcharge
from auto_cpufreq.battery_scripts.ideapad_laptop import ideapad_laptop_set_fullcharge

from auto_cpufreq.utils.config import config
from auto_cpufreq.core import footer

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

def battery_setup():
Expand All @@ -18,3 +25,16 @@ def battery_get_thresholds():
elif lsmod("ideapad_acpi"): ideapad_acpi_print_thresholds()
elif lsmod("ideapad_laptop"): ideapad_laptop_print_thresholds()
else: return

def fullcharge_thresholds():
conf = config.get_config()
if not (conf.has_option("battery", "enable_thresholds") and conf["battery"]["enable_thresholds"] == "true"):
print("\n" + "-" * 33 + " Fullcharge " + "-" * 34 + "\n")
print("ERROR:\n\nCan only run this command if default start/stop thresholds are set in a config file!")
footer()
exit(1)

if lsmod("thinkpad_acpi"): thinkpad_set_fullcharge()
elif lsmod("ideapad_acpi"): ideapad_acpi_set_fullcharge()
elif lsmod("ideapad_laptop"): ideapad_laptop_set_fullcharge()
else: return
9 changes: 9 additions & 0 deletions auto_cpufreq/battery_scripts/ideapad_acpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def set_battery(value, mode, bat):
if os.path.isfile(path): subprocess.check_output(f"echo {value} | tee {path}", shell=True, text=True)
else: print(f"WARNING: {path} does NOT exist")

def ideapad_acpi_set_fullcharge():
if os.path.exists(POWER_SUPPLY_DIR):
batteries = [name for name in os.listdir(POWER_SUPPLY_DIR) if name.startswith('BAT')]

for bat in batteries:
set_battery("98", "start", bat)
set_battery("99", "stop", bat)
else: print(f"WARNING {POWER_SUPPLY_DIR} does NOT esixt")

def get_threshold_value(mode):
conf = config.get_config()
return conf["battery"][f"{mode}_threshold"] if conf.has_option("battery", f"{mode}_threshold") else (0 if mode == "start" else 100)
Expand Down
9 changes: 9 additions & 0 deletions auto_cpufreq/battery_scripts/ideapad_laptop.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ def set_battery(value, mode, bat):
subprocess.check_output(f"echo {value} | tee {POWER_SUPPLY_DIR}{bat}/charge_{mode}_threshold", shell=True, text=True)
else: print(f"WARNING: {path} does NOT exist")

def ideapad_laptop_set_fullcharge():
if os.path.exists(POWER_SUPPLY_DIR):
batteries = [name for name in os.listdir(POWER_SUPPLY_DIR) if name.startswith('BAT')]

for bat in batteries:
set_battery("98", "start", bat)
set_battery("99", "stop", bat)
else: print(f"WARNING {POWER_SUPPLY_DIR} does NOT esixt")

def get_threshold_value(mode):
conf = config.get_config()
return conf["battery"][f"{mode}_threshold"] if conf.has_option("battery", f"{mode}_threshold") else (0 if mode == "start" else 100)
Expand Down
10 changes: 9 additions & 1 deletion auto_cpufreq/battery_scripts/thinkpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ def set_battery(value, mode, bat):
if os.path.isfile(path): subprocess.check_output(f"echo {value} | tee {path}", shell=True, text=True)
else: print(f"WARNING: {path} does NOT exist")

def thinkpad_set_fullcharge():
if os.path.exists(POWER_SUPPLY_DIR):
batteries = [name for name in os.listdir(POWER_SUPPLY_DIR) if name.startswith('BAT')]

for bat in batteries:
set_battery("98", "start", bat)
set_battery("99", "stop", bat)
else: print(f"WARNING {POWER_SUPPLY_DIR} does NOT esixt")

def get_threshold_value(mode):
conf = config.get_config()
return conf["battery"][f"{mode}_threshold"] if conf.has_option("battery", f"{mode}_threshold") else (0 if mode == "start" else 100)
Expand All @@ -27,7 +36,6 @@ def thinkpad_setup():
set_battery(get_threshold_value("stop"), "stop", bat)
else: print(f"WARNING {POWER_SUPPLY_DIR} does NOT esixt")


def thinkpad_print_thresholds():
batteries = [name for name in os.listdir(POWER_SUPPLY_DIR) if name.startswith('BAT')]
print("\n-------------------------------- Battery Info ---------------------------------\n")
Expand Down
7 changes: 6 additions & 1 deletion auto_cpufreq/bin/auto_cpufreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
@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, completions):
@click.option("--fullcharge", is_flag=True, help="Temporarily raise battery threshold to 99 until next reboot. (Set the default to return to in config)")
def main(config, daemon, debug, update, install, remove, fullcharge, live, log, monitor, stats, version, donate, force, get_state, completions):
# display info if config file is used
config_path = find_config_file(config)
conf.set_path(config_path)
Expand Down Expand Up @@ -268,5 +269,9 @@ def config_info_dialog():
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")
elif fullcharge:
root_check()
fullcharge_thresholds()
battery_get_thresholds()

if __name__ == "__main__": main()