You are not logged in.

#1 2011-11-27 19:18:22

JamieKitson
Member
From: UK
Registered: 2010-10-18
Posts: 134
Website

charge vs energy in /sys/class/power_supply/BAT0/

Hi,

the files in my /sys/class/power_supply/BAT0/ directory seem to keep changing between "charge_" and "energy_", so for example the file containing the battery charge has just switched from "energy_now" to "charge_now", which makes it difficult to maintain scripts to interrogate these values. Are others experiencing this too, or is it just me? Will there be a final naming convention settled upon or will they keep changing? Is there a way I can abstract my scripts to work with any file names in that directory?

Thanks, Jamie

Offline

#2 2011-11-28 21:29:36

JamieKitson
Member
From: UK
Registered: 2010-10-18
Posts: 134
Website

Re: charge vs energy in /sys/class/power_supply/BAT0/

So if boot with AC plugged in the /sys/class/power_supply/BAT0/ directory is populated with charge_*, but if I boot on battery the directory is populated with energy_*. Is this true for everyone? I'm running a Thinkpad X220.

btw, (un)plugging AC while running does not alter the file names.

Last edited by JamieKitson (2011-11-28 21:32:05)

Offline

#3 2011-11-29 04:23:08

hendry
Member
From: Singapore
Registered: 2009-09-08
Posts: 121
Website

Re: charge vs energy in /sys/class/power_supply/BAT0/

Hi Jamie,

Just booted off battery and I have:

x220:~$ ls /sys/class/power_supply/BAT0/ | sort
alarm
charge_full
charge_full_design
charge_now
current_now
cycle_count
device
manufacturer
model_name
power
present
serial_number
status
subsystem
technology
type
uevent
voltage_min_design
voltage_no

Same as what I did when I booted off AC.

Linux x220 3.1.2-1-ARCH #1 SMP PREEMPT Tue Nov 22 09:17:56 CET 2011 x86_64 Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz GenuineIntel GNU/Linux

Offline

#4 2011-12-29 11:39:35

hendry
Member
From: Singapore
Registered: 2009-09-08
Posts: 121
Website

Re: charge vs energy in /sys/class/power_supply/BAT0/

Woops, I can now confirm the same behaviour that Jamie notices.

Boot off AC and I can get charge_. Boot off battery and I get energy_.

Linux x220 3.1.5-1-ARCH #1 SMP PREEMPT Sat Dec 10 14:43:09 CET 2011 x86_64 Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz GenuineIntel GNU/Linux

Offline

#5 2012-01-12 05:41:03

Ahadiel
Member
From: Vancouver, BC
Registered: 2008-05-11
Posts: 31
Website

Re: charge vs energy in /sys/class/power_supply/BAT0/

Booting on battery gives me energy_ and resuming from suspend changes it to charge_.

(also an x220)
Linux thinkpad 3.1.8-1-ARCH #1 SMP PREEMPT Sat Jan 7 08:59:43 CET 2012 x86_64 Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz GenuineIntel GNU/Linux

Offline

#6 2012-01-12 10:01:20

JamieKitson
Member
From: UK
Registered: 2010-10-18
Posts: 134
Website

Re: charge vs energy in /sys/class/power_supply/BAT0/

Apparently this is a feature/bug in the X220 acpi firmware. It reports units in either amps (current/charge) or watts (energy).

http://comments.gmane.org/gmane.linux.acpi.devel/51602

Offline

#7 2013-01-20 19:54:30

macpd
Member
Registered: 2013-01-20
Posts: 2

Re: charge vs energy in /sys/class/power_supply/BAT0/

I too found this rather annoying, so I wrote a python script to find and parse the files for me.

it's still a work in a progress, but works well enough.

Offline

Board footer

Powered by FluxBB