Skip to content

battery warning level for FreeBSD control method batteries.

Notifications You must be signed in to change notification settings

random532/FreeBSD_Battery_Trip_Point

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FreeBSD Battery Warnings

Affected file:
sys/dev/acpica/acpi_cmbat.c


Short description:
You don't need to poll the battery periodically.
You can set a percentage level for your battery (ranging from 0-100) via sysctl.
If the level is reached, it will cause a /dev/devd event Notify(0x80). So a script can be triggered.

Long description: A New Battery Warning Level

The ACPI specification defines an optional acpi method called "_BTP", which stands for battery trip point.
However, currently the FreeBSD cmbat driver only supports mandatory methods (bif, bix, ..), but not optional ones.

Try the command: "acpidump -dt |grep _BTP". If it returns something, your battery supports this method.

If supported by the battery, a new sysctl is created: dev.battery.X.Warning_Level
Replace the X with your battery index (0, 1, ...).

You can set the warning level ("trip point") with this sysctl (values between 0-100 are allowed).
If the battery reaches that percentage level, devd will be notified.
A value of 0 disables the warning.

Get the notification:
Next add an entry in /etc/devd.conf:
notify 10 {
match "system" "ACPI";
match "subsystem" "CMBAT";
action "/home/myuser/myscript.sh $notify";
};

Replace myuser with your local user. Replace myscript.sh with a script of your choice.

Note:
If the battery gets unplugged/plugged in, an identical notification will be issued (at least on my laptop).
So the script needs to take that into account.

Note:
There is a slight delay in the devd notification.
E.g. if you set the warning level to 20%, you may get notified at 19,5%. This is due to granularity.

Personal note:
If you have any questions, please write me. Then I will look at this again.
Tested on a thinkpad x220.
Thanks. :-)

Installation guide for beginners:

Step 1: Try the command: "acpidump -dt |grep _BTP". If it returns something, your battery supports this function.

Step 2: Donwload the Freebsd source code.
Replace the file from this repo with the file /usr/src/sys/dev/acpica/acpi_cmbat.c

Step 3: Build and install the new kernel.

Step 4: Add an entry in /etc/devd.conf:
notify 10 {
match "system" "ACPI";
match "subsystem" "CMBAT";
action "/home/myuser/myscript.sh $notify";
};

Step 5: Replace mysuser and myscript with an actual user and an actual script.

Step 6: Set the sysctl dev.battery.0.Warning_Level to your desired warning level. If it works, give me feedback.

About

battery warning level for FreeBSD control method batteries.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages