Rebuilt battery scripts (#645)
* rebuilt thinkpad and ideapad * updated conf example
This commit is contained in:
parent
005b4aa178
commit
539914a545
|
@ -54,8 +54,8 @@ turbo = auto
|
|||
# enable thresholds true or false
|
||||
#enable_thresholds = true
|
||||
#
|
||||
# start threshold (defaults to 0 ) can be 0 - 100
|
||||
# start threshold (0 is off ) can be 0-99
|
||||
#start_threshold = 0
|
||||
#
|
||||
# stop threshold (defaults to 100) this value must be greater or equal to 65
|
||||
# stop threshold (100 is off) can be 1-100
|
||||
#stop_threshold = 100
|
||||
|
|
|
@ -7,7 +7,8 @@ from auto_cpufreq.battery_scripts.ideapad import *
|
|||
|
||||
|
||||
def lsmod(module):
|
||||
output = subprocess.run(['lsmod'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
output = subprocess.run(
|
||||
['lsmod'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
if module in output.stdout:
|
||||
return True
|
||||
else:
|
||||
|
@ -38,9 +39,11 @@ def battery_setup():
|
|||
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())
|
||||
thinkpad_setup(battery_start_threshold(),
|
||||
battery_stop_threshold())
|
||||
elif lsmod("ideapad_acpi"):
|
||||
ideapad_setup(battery_start_threshold(), battery_stop_threshold())
|
||||
ideapad_setup(battery_start_threshold(),
|
||||
battery_stop_threshold())
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
|
@ -53,7 +56,7 @@ def battery_get_thresholds():
|
|||
conf = get_config()
|
||||
if conf.has_option("battery", "enable_thresholds"):
|
||||
if conf["battery"]["enable_thresholds"] == "true":
|
||||
print("-" * 30 )
|
||||
print("-" * 30)
|
||||
if lsmod("thinkpad_acpi"):
|
||||
thinkpad_print_thresholds()
|
||||
elif lsmod("ideapad_acpi"):
|
||||
|
|
|
@ -1,42 +1,37 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
from auto_cpufreq.core import root_check
|
||||
|
||||
|
||||
def set_battery(value, mode, bat):
|
||||
file_path = f'/sys/class/power_supply/BAT{bat}/charge_{mode}_threshold'
|
||||
try:
|
||||
subprocess.check_output(f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
|
||||
except Exception as e:
|
||||
print(f"Error writing to {file_path}: {e}")
|
||||
|
||||
|
||||
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
|
||||
battery_count = len([name for name in os.listdir("/sys/class/power_supply/") if name.startswith('BAT')])
|
||||
for bat in range(battery_count):
|
||||
set_battery(start_threshold, "start", bat)
|
||||
set_battery(stop_threshold, "stop", bat)
|
||||
|
||||
|
||||
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')])
|
||||
battery_count = len([name for name in os.listdir(
|
||||
"/sys/class/power_supply/") 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:
|
||||
with open(f'/sys/class/power_supply/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:
|
||||
with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
|
||||
print(f'battery{b} stop threshold is set to {f.read()}')
|
||||
f.close()
|
||||
|
||||
|
|
|
@ -1,49 +1,37 @@
|
|||
#!/usr/bin/env python3
|
||||
import os
|
||||
import subprocess
|
||||
from auto_cpufreq.core import root_check
|
||||
|
||||
|
||||
def set_battery(value, mode, bat):
|
||||
file_path = f'/sys/class/power_supply/BAT{bat}/charge_{mode}_threshold'
|
||||
try:
|
||||
subprocess.check_output(f"echo {value} | tee /sys/class/power_supply/BAT{bat}/charge_{mode}_threshold", shell=True, text=True)
|
||||
except Exception as e:
|
||||
print(f"Error writing to {file_path}: {e}")
|
||||
|
||||
|
||||
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
|
||||
battery_count = len([name for name in os.listdir("/sys/class/power_supply/") if name.startswith('BAT')])
|
||||
for bat in range(battery_count):
|
||||
set_battery(start_threshold, "start", bat)
|
||||
set_battery(stop_threshold, "stop", bat)
|
||||
|
||||
|
||||
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')])
|
||||
battery_count = len([name for name in os.listdir(
|
||||
"/sys/class/power_supply/") 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:
|
||||
with open(f'/sys/class/power_supply/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:
|
||||
with open(f'/sys/class/power_supply/BAT{b}/charge_stop_threshold', 'r') as f:
|
||||
print(f'battery{b} stop threshold is set to {f.read()}')
|
||||
f.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue