23 #ifndef SDL_POWER_DISABLED
26 #import <UIKit/UIKit.h>
34 static const int BATTERY_MONITORING_TIMEOUT = 3000;
35 static Uint32 SDL_UIKitLastPowerInfoQuery = 0;
38 SDL_UIKit_UpdateBatteryMonitoring(
void)
40 if (SDL_UIKitLastPowerInfoQuery) {
41 const Uint32 prev = SDL_UIKitLastPowerInfoQuery;
43 const UInt32 ticks = now - prev;
45 if ((now < prev) || (ticks >= BATTERY_MONITORING_TIMEOUT)) {
46 UIDevice *uidev = [UIDevice currentDevice];
47 SDL_assert([uidev isBatteryMonitoringEnabled] == YES);
48 [uidev setBatteryMonitoringEnabled:NO];
49 SDL_UIKitLastPowerInfoQuery = 0;
57 UIDevice *uidev = [UIDevice currentDevice];
59 if (!SDL_UIKitLastPowerInfoQuery) {
60 SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
61 [uidev setBatteryMonitoringEnabled:YES];
73 switch ([uidev batteryState])
75 case UIDeviceBatteryStateCharging:
79 case UIDeviceBatteryStateFull:
83 case UIDeviceBatteryStateUnplugged:
87 case UIDeviceBatteryStateUnknown:
93 const float level = [uidev batteryLevel];
94 *percent = ( (level < 0.0f) ? -1 : (((
int) (level + 0.5
f)) * 100) );
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *)
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC Uint32 SDLCALL SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
#define SDL_assert(condition)
SDL_PowerState
The basic state for the system's power supply.