21 #include "../../SDL_internal.h" 23 #ifndef SDL_POWER_DISABLED 26 #import <UIKit/UIKit.h> 31 #include "SDL_syspower.h" 35 static const int BATTERY_MONITORING_TIMEOUT = 3000;
36 static Uint32 SDL_UIKitLastPowerInfoQuery = 0;
39 SDL_UIKit_UpdateBatteryMonitoring(
void)
41 if (SDL_UIKitLastPowerInfoQuery) {
43 UIDevice *uidev = [UIDevice currentDevice];
44 SDL_assert([uidev isBatteryMonitoringEnabled] == YES);
45 [uidev setBatteryMonitoringEnabled:NO];
46 SDL_UIKitLastPowerInfoQuery = 0;
52 SDL_UIKit_UpdateBatteryMonitoring(
void)
67 UIDevice *uidev = [UIDevice currentDevice];
69 if (!SDL_UIKitLastPowerInfoQuery) {
70 SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
71 uidev.batteryMonitoringEnabled = YES;
83 switch (uidev.batteryState) {
84 case UIDeviceBatteryStateCharging:
88 case UIDeviceBatteryStateFull:
92 case UIDeviceBatteryStateUnplugged:
96 case UIDeviceBatteryStateUnknown:
102 const float level = uidev.batteryLevel;
103 *percent = ( (level < 0.0f) ? -1 : ((
int) ((level * 100) + 0.5
f)) );
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
#define SDL_assert(condition)
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *)
SDL_PowerState
The basic state for the system's power supply.
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.