Ok, so I've been teaching myself some Objective C/Cocoa, using Xcode 4.2 on Lion. The goal is to get something like Coconut Battery with some added functionality. I've got it running and it works fine, but right now I'm unhappy with the way I get the battery information.
What I do is call "ioreg -c AppleSmartBattery" from within the class that provides the battery information, and then I read out the information I want from the output. This is not very elegant, and I think there should be a better way to get this information, without calling a shell program.
I found three places that give access to detailed battery information:
1) ioreg in the console
2) system report -> Power
3) IOregistryExplorer in /Developer/Tools
Now, there is the IOKit class in the OSX Dev package. In particular, IOPowerSources.h and IOPSKeys.h provide methods to get battery information, so tried to use those. To my surprise, the information is much less detailed, I only got the current and maximal charge in %, and the battery health, also in %. This was somewhat disappointing.
There must be a better way to get this information, after all the IOregistryExplorer must do it somehow. It seems I will have to find a way to access the IOservices tree. If anyone has any ideas or hints, I would be thankful.
What I do is call "ioreg -c AppleSmartBattery" from within the class that provides the battery information, and then I read out the information I want from the output. This is not very elegant, and I think there should be a better way to get this information, without calling a shell program.
I found three places that give access to detailed battery information:
1) ioreg in the console
2) system report -> Power
3) IOregistryExplorer in /Developer/Tools
Now, there is the IOKit class in the OSX Dev package. In particular, IOPowerSources.h and IOPSKeys.h provide methods to get battery information, so tried to use those. To my surprise, the information is much less detailed, I only got the current and maximal charge in %, and the battery health, also in %. This was somewhat disappointing.
There must be a better way to get this information, after all the IOregistryExplorer must do it somehow. It seems I will have to find a way to access the IOservices tree. If anyone has any ideas or hints, I would be thankful.