forked from AdnanHodzic/auto-cpufreq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add battery charge thresholds limit (AdnanHodzic#637)
* 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
- Loading branch information
1 parent
9cba0be
commit ec0691e
Showing
5 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/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") and 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 | ||
|
||
|
||
def battery_get_thresholds(): | ||
conf = get_config() | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters