#!/bin/sh # Usage: # $0 START_LIMIT STOP_LIMIT # Sources: # https://github.com/teleshoes/tpacpi-bat/blob/master/battery_asl # https://www.reddit.com/r/freebsd/comments/lsygde/acpi_controlling_battery_charging_thresholds_on/ # https://forums.freebsd.org/threads/how-to-set-battery-charging-thresholds-on-laptop.79807/page-2 # Requirements: # 1. Packages: # - acpi_call # 2. Kernel modules: # - acpi_call # - acpi_ibm # ACPI Calls: # - BCTG - Get battery capacity start charge (1-99 or 0 = default) # - BCCS - Set battery capacity start charge (1-99 or 0 = default) # - BCSG - Get battery capacity stop charge (1-99 or 0 = default) # - BCSS - Set battery capacity stop charge (1-99 or 0 = default) ACPI_PATH="$(sysctl -n dev.acpi_ibm.0.%location | cut -d'=' -f2)" if [ $# -eq 2 ]; then echo "Setting battery capacity start charge to $1%" acpi_call -p "$ACPI_PATH.BCCS" -i $1 >> /dev/null sleep 1 echo "Setting battery capacity stop charge to $2%" acpi_call -p "$ACPI_PATH.BCSS" -i $2 >> /dev/null fi ACPI_BCTG="$(acpi_call -p "$ACPI_PATH.BCTG" -i 1)" ACPI_BCSG="$(acpi_call -p "$ACPI_PATH.BCSG" -i 1)" BAT_START_CHG=$(($ACPI_BCTG - 768)) BAT_STOP_CHG=$(($ACPI_BCSG - 768)) if [ $BAT_STOP_CHG -eq 0 ]; then BAT_STOP_CHG=100; fi echo "Battery will start charge at: $BAT_START_CHG%" echo "Battery will stop charge at: $BAT_STOP_CHG%"