Skip to content

Instantly share code, notes, and snippets.

@Jacotsu
Created November 26, 2021 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jacotsu/0d5f035fd2c168b7df6a84fb11819566 to your computer and use it in GitHub Desktop.
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
#!/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