Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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