Created
November 26, 2021 16:52
-
-
Save Jacotsu/0d5f035fd2c168b7df6a84fb11819566 to your computer and use it in GitHub Desktop.
A script that writes into the EC in order to stop charging the battery at a specific threshold, requires https://github.com/hirschmann/nbfc ec_probe script
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
#!/usr/bin/env bash | |
THRESHOLD=70 | |
setup() { | |
mount -t debugfs none /sys/kernel/debug | |
tlp ac | |
sv stop tlp acpid | |
echo high >/sys/class/drm/card0/device/power_dpm_force_performance_level | |
echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | |
} | |
cleanup() { | |
echo auto >/sys/class/drm/card0/device/power_dpm_force_performance_level | |
echo ondemand | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor | |
sv start tlp acpid | |
exit | |
} | |
trap cleanup SIGINT | |
setup | |
while true; do | |
BATT_PERC=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 |\ | |
grep -oP "(?<=percentage: )[0-9]*") | |
if [[ $BATT_PERC -ge $THRESHOLD ]]; then | |
./ec_probe write 0x40 0x00 | |
fi | |
sleep 2 | |
done | |
cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment