• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Polling battery data, missing cycle count
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Polling battery data, missing cycle count


  • Subject: Re: Polling battery data, missing cycle count
  • From: Claudio Procida <email@hidden>
  • Date: Wed, 23 Aug 2006 09:27:24 +0200


Il giorno 22 ago 2006, alle ore 21:51, Claudio Procida ha scritto:

I'm trying to retrieve informations from the battery using the following code (adapted from an example by A.Hillegass on this list):

( used SystemConfiguration APIs)

<snip />

Since this code just registers my app as a passive listener of the power changes, I also added the following method to directly poll the battery data when needed:

( used IOPowerSources APIs)

<snip />

Anyway I still can't figure how I can get some advanced information like the cycles count or the voltage. In IOPSKeys.h I see all the relevant keys but the psDict dictionary holds no values for those keys.

Any hints? Thanks in advance, as usual

Ok, I've probably found the missing piece: I can get all the low- level informations (amperage, voltage, cycle count and more) using the IOPMCopyBatteryInfo API from IOPMLib.h


Now I'm using IOPowerManagement APIs too. And that's three :(

I bet there's a better way to handle this without mixing those APIs. For those who are interested in the topic, this is the method I've written:

- (NSString *)getBatteryInfo
{
mach_port_t master_device_port;
kern_return_t kr;
CFArrayRef battery_info;
NSString *ret = nil;

kr = IOMasterPort(bootstrap_port,&master_device_port);
if ( kr == kIOReturnSuccess )
{
if(kIOReturnSuccess != IOPMCopyBatteryInfo(master_device_port, &battery_info))
{
NSLog(@"Are you sure that this computer has a battery?\n");
}
else
{
ret = [NSString stringWithFormat:@"%@", (NSDictionary *) CFArrayGetValueAtIndex(battery_info, batteryIndex)];
CFRelease(battery_info);
}
}
return ret;
}


Claudio
--
http://www.emeraldion.it
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Polling battery data, missing cycle count (From: Claudio Procida <email@hidden>)

  • Prev by Date: Loading an URL in Safari
  • Next by Date: NSTableColumn sort indicator
  • Previous by thread: Polling battery data, missing cycle count
  • Next by thread: Borderless NSBrowser
  • Index(es):
    • Date
    • Thread