mirror of
https://github.com/libretro/RetroArch
synced 2025-01-18 13:23:40 +00:00
(iOS) Implement get_powerstate
This commit is contained in:
parent
b810f7579d
commit
99894c831e
@ -65,6 +65,41 @@ void apple_rarch_exited(void)
|
||||
|
||||
apple_frontend_settings_t apple_frontend_settings;
|
||||
|
||||
enum frontend_powerstate ios_get_powerstate(int *seconds, int *percent)
|
||||
{
|
||||
float level;
|
||||
enum frontend_powerstate ret = FRONTEND_POWERSTATE_NONE;
|
||||
UIDevice *uidev = [UIDevice currentDevice];
|
||||
|
||||
if (!uidev)
|
||||
return ret;
|
||||
|
||||
[uidev setBatteryMonitoringEnabled:true];
|
||||
|
||||
switch (uidev.batteryState)
|
||||
{
|
||||
case UIDeviceBatteryStateCharging:
|
||||
ret = FRONTEND_POWERSTATE_CHARGING;
|
||||
break;
|
||||
case UIDeviceBatteryStateFull:
|
||||
ret = FRONTEND_POWERSTATE_CHARGED;
|
||||
break;
|
||||
case UIDeviceBatteryStateUnplugged:
|
||||
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
|
||||
break;
|
||||
case UIDeviceBatteryStateUnknown:
|
||||
break;
|
||||
}
|
||||
|
||||
level = uidev.batteryLevel;
|
||||
|
||||
*percent = ((level < 0.0f) ? -1 : ((int)((level * 100) + 0.5f)));
|
||||
|
||||
[uidev setBatteryMonitoringEnabled:false];
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void get_ios_version(int *major, int *minor)
|
||||
{
|
||||
NSArray *decomposed_os_version = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
|
||||
|
@ -33,10 +33,12 @@
|
||||
|
||||
#if defined(IOS)
|
||||
void get_ios_version(int *major, int *minor);
|
||||
|
||||
enum frontend_powerstate ios_get_powerstate(int *seconds, int *percent);
|
||||
#endif
|
||||
|
||||
#if defined(OSX)
|
||||
/* Carbon is so verbose... */
|
||||
|
||||
#define PMGMT_STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
|
||||
#define PMGMT_GETVAL(k,v) CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v)
|
||||
|
||||
@ -456,7 +458,8 @@ static enum frontend_powerstate frontend_apple_get_powerstate(int *seconds, int
|
||||
end:
|
||||
if (blob)
|
||||
CFRelease(blob);
|
||||
|
||||
#elif defined(IOS)
|
||||
ret = ios_get_powerstate(seconds, percent);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user