Jump to content

Help me with IO/Kit programming


3 posts in this topic

Recommended Posts

Hello.

 

I am trying to create a simple KEXT which disables the C4 state of the processor when the notebook is running on the AC power and I hope I could use your help a little.

 

I have a MacBook Pro and I had my logic board replaced a few days ago. Now the whine on battery is gone, but it still remains on AC power. This whine is slightly higher pitched than the whine on battery so most people can't hear it, but I can and it's extremely annoying.

 

The problem I currently have is that I am not good at using IO/Kit and I can't figure out how to create a function that determines if the computer is running of a battery or an AC power connection. I believe I have to do something with IOPMPowerSource or IOPowerSources, but I am completely clueless about how I could use them. I couldn't find any sample code or a good reference to aid me.

 

Your help will be much appreciated.

 

Thank you.

 

Cheers,

raingrove

Link to comment
Share on other sites

#import <IOKit/ps/IOPSKeys.h>
#import <IOKit/ps/IOPowerSources.h>

-(BOOL)runningOnAC
{
CFTypeRef		   ps_info = IOPSCopyPowerSourcesInfo();
	CFStringRef		 ps_name = NULL;
char				strbuf[100];

ps_name = (CFStringRef)IOPSGetProvidingPowerSourceType(ps_info);
CFStringGetCString(ps_name, strbuf, 100, kCFStringEncodingUTF8);
int result = strncmp(strbuf,"AC POWER",4);
if(result==0)
	return YES;
	else
			return NO;
}

 

 

thats how i do it. Its not really pretty, but it works..

Link to comment
Share on other sites

Thanks alot, that should be Objective-C code you are writing, but I am sure it will work in C++ as well with a little modification.

 

Edit: I am sorry, but it seems like IOPowerSources is not available in kernel framework. :) It seems like I gotta use pwr_mgt/IOPMPowerSource .... hmm :/

Link to comment
Share on other sites

 Share

×
×
  • Create New...