Power Status (was Re: Because LC can't do two things at once.)
Richard Gaskin
ambassador at fourthworld.com
Mon Mar 2 10:30:04 EST 2015
Peter M. Brigham wrote:
> On Mar 1, 2015, at 3:16 PM, Richard Gaskin wrote:
>> Thanks to the beautiful simplicity of the Linux /proc directory
>> I was able to find:
>>
>> cat /proc/acpi/battery/BAT1/state
>>
>> The "charging state" field there will contain "charging" or
>> "discharging".
>
> Question: this looks like a file on disk. I didn't know what you
> meant by the "'charging state' field." What is the format of the
> file? Is this a text file, an XML file, or something else?
One of the guiding design principles of Unix is "everything is a file",
which allows us to access not only those byte streams that are actual
files, but also system and process info such as that commonly mounted at
/proc, all with the same common tools (cd, ls, cat, grep, more, less,
etc.) - this page explains it well:
<http://en.wikipedia.org/wiki/Everything_is_a_file>
Being a certified Unix OS X probably has a /proc, but some Unix flavors
don't mount it; most Linux distros do.
> If you could give me a sample to look at I can parse it to get
> the info and complete the handler. I don't have a linux system
> to work with for this.
In my brief searching on this there were two files commonly noted, the
one shown above and also /BAT0/state. I'm not exactly sure why my
laptop has a BAT1 but not a BAT0, and I'll see what I can turn up.
That said, given the increasing role of servers in our connected world,
I can't say enough encouraging things about putting together a VM with
Linux in it. Tons of fun, very educational, and you can't beat the price.
And if you're a history buff, there's a version of Debian with OpenStep
pre-installed so you can explore the look-and-feel of NeXT. :)
Michael Doub wrote:
> I don't know if this helps since the only linux system i have is a
> raspberryPi, but I get a file not found message when typing cat
> /proc/acpi/battery/BAT1/state in a terminal window.
Thanks for trying that, Michael.
It may be helpful to also check for BAT0, but it may also be that
because the Pi doesn't ship with a battery that's not normally part of
the info the system provides.
While battery packs are available for Pi*, the device itself doesn't
distinguish it from running on a wall socket; it's not integrated with
battery monitoring firmware like laptops are.
If that hunch is correct, the absence of a battery info element in /proc
may be an accurate reflection of the system state.
I'll do some more digging and see what I can find....
* I've been looking for a Pi case with an integrated battery pack. I've
seen several battery packs as separate cases, but I'd really prefer
everything in one box. Anyone here seen one?
--
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