Battery indicator inside programs?


mjohansson

Supporter
Joined
Feb 10, 2011
Messages
409
Is it possible to get a read from battery to make an battery indicator inside a program?
 
Yes. Check this link and follow there for details.


It's simple like cat /sys/class/power_supply/bq27500-0
 
Thanks, that displays in the terminal, but how do I get the value from capacity into a variable in my program?


Printing out the value from a program can be done like this:


#include <cstdlib>


std::system("cat /sys/class/power_supply/bq27500-0/capacity");


Note the space inbetween cat and /sys. Im talking to potential other Linux and programming noobs should there be any :)


Here is something that might be of interest, Ill try later unless anyone knows of a simple way to get capacity value into a variable? http://stackoverflow.com/questions/7753006/reading-terminal-response-to-bash-commands-into-c-variable
 
I cant find the right folder? I know it works cos copying the capacity file into mysorce directory and typing myfile.open("capacity")


gives the myfile>>variableXXX the right value. But typing myfile.open("/sys/bla bla bla/capacity") gives my variable random numbers depending on what type the variable is, and none of them is the battery capacity.
 
Back
Top