Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Improved support for multiple batteries#4

Open
jceb wants to merge 19 commits into
denilsonsa:masterfrom
jceb:master
Open

Improved support for multiple batteries#4
jceb wants to merge 19 commits into
denilsonsa:masterfrom
jceb:master

Conversation

@jceb
Copy link
Copy Markdown

@jceb jceb commented Dec 23, 2012

The current implementation of batterymon lets every Battery object send updates to the UI. I changed this behavior and let the PowerManagement collect the information from all batteries and ac adapters. The power management than computes the battery lifetime based on all the available devices.
I also implemented a reinitialization of ac adapters and batteries to detect newly added / removed devices.

h3xx and others added 19 commits February 13, 2012 11:24
This fixes an issue where the battery constantly reads at 0%.

It's because (at least on my system) the naming conventions for the
special files inside the sysfs tree are different from what the script
expects.

The script expects:
 /sys/class/power_supply/BAT*/energy_full
 /sys/class/power_supply/BAT*/energy_now
 /sys/class/power_supply/BAT*/power_now

My sysfs has:
 /sys/class/power_supply/BAT*/charge_full
 /sys/class/power_supply/BAT*/charge_now
 /sys/class/power_supply/BAT*/current_now

Unfortunately I am unable to find the exact commit log where this naming
convention changed, but now the script will support both and everyone
will be happy.

This bug was also observed in kernel 2.6.38.7.

* Evidence *

$ uname -a

Linux delicious 3.2.2 denilsonsa#1 SMP Fri Jan 27 15:19:49 CST 2012 x86_64 Intel(R) Atom(TM) CPU N455   @ 1.66GHz GenuineIntel GNU/Linux

$ ls -la /sys/class/power_supply/BAT1/
total 0
drwxr-xr-x 3 root root    0 Feb  8 15:20 .
drwxr-xr-x 3 root root    0 Feb  8 15:20 ..
-rw-r--r-- 1 root root 4096 Feb 13 10:44 alarm
-r--r--r-- 1 root root 4096 Feb  8 15:20 charge_full
-r--r--r-- 1 root root 4096 Feb 13 10:44 charge_full_design
-r--r--r-- 1 root root 4096 Feb  8 15:20 charge_now
-r--r--r-- 1 root root 4096 Feb  8 15:20 current_now
-r--r--r-- 1 root root 4096 Feb 13 10:44 cycle_count
lrwxrwxrwx 1 root root    0 Feb 13 10:44 device -> ../../../PNP0C0A:00
-r--r--r-- 1 root root 4096 Feb 13 10:44 manufacturer
-r--r--r-- 1 root root 4096 Feb 13 10:44 model_name
drwxr-xr-x 2 root root    0 Feb 13 10:44 power
-r--r--r-- 1 root root 4096 Feb  8 15:20 present
-r--r--r-- 1 root root 4096 Feb 13 10:44 serial_number
-r--r--r-- 1 root root 4096 Feb  8 15:20 status
lrwxrwxrwx 1 root root    0 Feb  8 16:01 subsystem -> ../../../../../../class/power_supply
-r--r--r-- 1 root root 4096 Feb 13 10:44 technology
-r--r--r-- 1 root root 4096 Feb 13 10:33 type
-rw-r--r-- 1 root root 4096 Feb  8 16:01 uevent
-r--r--r-- 1 root root 4096 Feb 13 10:44 voltage_min_design
-r--r--r-- 1 root root 4096 Feb  8 15:20 voltage_now
Caveats: `'0' or 2` will return `'0'`

{power,current}_now can contain a 0 when charging. This is normal.
I don't have DistUtilsExtra on my system, it's not part of vanilla python packaging.
This is a simple script I wrote that will hopefully work on most distros
for:

A) Warning the user that the battery level is critical.
B) Automating the power state change process (optional, on by default).

Tested on Slackware 13.37 x86_64 with 3.2.7 vanilla kernel.
Tested with Xdialog 2.3.1 and xmessage 1.0.3.

To use with batterymon, start batterymon with the `--on-critical'
option pointed at this script.
Add -W flag for display-only operation. Hopefully this script will serve
as many needs as possible.
Saves 5995 bytes, or 5.8 KB.
Replace with `which' which is not a built-in.
@denilsonsa
Copy link
Copy Markdown
Owner

Just to let you know, it might take a while until I review and accept this pull request. Feel free to message me again in case it takes too long.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants