21 #include "../../SDL_internal.h" 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) {
42 UIDevice *uidev = [UIDevice currentDevice];
43 SDL_assert([uidev isBatteryMonitoringEnabled] == YES);
44 [uidev setBatteryMonitoringEnabled:NO];
45 SDL_UIKitLastPowerInfoQuery = 0;
54 UIDevice *uidev = [UIDevice currentDevice];
56 if (!SDL_UIKitLastPowerInfoQuery) {
57 SDL_assert(uidev.isBatteryMonitoringEnabled == NO);
58 uidev.batteryMonitoringEnabled = YES;
70 switch (uidev.batteryState) {
71 case UIDeviceBatteryStateCharging:
75 case UIDeviceBatteryStateFull:
79 case UIDeviceBatteryStateUnplugged:
83 case UIDeviceBatteryStateUnknown:
89 const float level = uidev.batteryLevel;
90 *percent = ( (level < 0.0f) ? -1 : ((
int) ((level * 100) + 0.5
f)) );
uint32_t Uint32
An unsigned 32-bit integer type.
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *)
Uint32 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.
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.