Skip to content

Instantly share code, notes, and snippets.

@moyashi
Created June 26, 2010 08:20
Show Gist options
  • Save moyashi/453900 to your computer and use it in GitHub Desktop.
Save moyashi/453900 to your computer and use it in GitHub Desktop.
//
// batterylevel
//
// Ver.0.1
// Created by moyashi on 18.01.09.
//
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <IOKit/ps/IOPowerSources.h>
#import <IOKit/ps/IOPSKeys.h>
int main (int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
char str[255];
id info = (id)IOPSCopyPowerSourcesInfo();
if (info)
{
NSArray *list = (NSArray*)IOPSCopyPowerSourcesList(info);
if (list)
{
NSDictionary *ups_info =
(NSDictionary*)IOPSGetPowerSourceDescription(info, [list objectAtIndex:0]);
if (ups_info)
{
NSLog(@"%@", ups_info);
float currentcap =
[[ups_info objectForKey:
[NSString stringWithUTF8String:kIOPSCurrentCapacityKey]] floatValue];
float maxcap =
[[ups_info objectForKey:
[NSString stringWithUTF8String:kIOPSMaxCapacityKey]] floatValue];
if (currentcap && maxcap)
{
sprintf(str, "echo `date \"+%%Y-%%m-%%d\t%%H:%%M:%%S\"`\t%.1f >>/var/mobile/battery-log/battlog`date +%%Y-%%m-%%d`.txt", currentcap);
system("mkdir /var/mobile/battery-log/ >/dev/null 2>&1");
system(str);
}
}
}
}
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment