Power Status (was Re: Because LC can't do two things at once.)

Richard Gaskin ambassador at fourthworld.com
Tue Mar 3 10:29:26 EST 2015


Peter M. Brigham wrote:
 > So it looks from your links that I should use "/sys/class/power_supply
 > /BAT0/" for the URL on Unix, and check for "charging" or
 > "discharging" as the first word??

...or "full", as I saw last night while testing this.

So far I'm only seeing one-word values, so using "word 1" would seem a 
safe choice - good call.


We have one remaining mystery, however:  my Dell has only one battery, 
but has no values at /sys/class/power_supply/BAT0/, instead using 
/sys/class/power_supply/BAT1/.

I've read other cases online where folks find the same thing, but 
haven't found the definitive rule governing why.

In my reading I also came across some laptop models (Toshiba came up a 
couple times) in which the battery firmware doesn't report its info in a 
standard way, making it more difficult for generalized utilities to 
obtain it.  But frankly, if an OEM chooses to disregard published 
standards personally I can't see spending much time accommodating them, 
so I'm not too worried about such edge cases.

Given all this, I would feel reasonably safe at this time with the 
following algorithm:

First check BAT0/status
If empty then
     check BAT1/status
end if
If both are empty there's probably no battery
If a value is found then use it

I've seen no mention of BAT2 or more, so I feel this should account for 
a reasonably useful range of contexts.


My own goal here is to know whether I can feel save performing optional 
background processing which can improve performance but at the cost of 
battery life.

So either "full" or "charging" implies that the laptop is plugged into a 
wall socket, so I'd proceed with those background tasks.

And if no battery info can be found at all in either location (BAT0 or 
BAT1), it seems safe to assume we're not on a battery-powered device, so 
I'd also proceed with optional background tasks.

So it's only when the status returns "discharging" that I know a battery 
is present and that it's not plugged into a wall socket, in which case I 
should at least let the user decide whether or not to run optional 
background tasks.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com




More information about the use-livecode mailing list