changeset 4444:42e1092225f9

Implemented SDL power APIs for iPhoneOS.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 30 Apr 2010 00:39:31 -0400
parents c598e440c87c
children 06becafcac89
files Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj include/SDL_config_iphoneos.h src/power/SDL_power.c src/power/uikit/SDL_syspower.m src/video/uikit/SDL_uikitopengles.m
diffstat 6 files changed, 237 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Thu Apr 29 22:53:18 2010 -0400
+++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Fri Apr 30 00:39:31 2010 -0400
@@ -65,6 +65,8 @@
 		04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; };
 		04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; };
 		04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */; };
+		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
+		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
 		FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
 		FD3F495C0DEA5B2100C5B771 /* begin_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CC0DD52EB400FB1D6B /* begin_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		FD3F495D0DEA5B2100C5B771 /* close_code.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99B8CD0DD52EB400FB1D6B /* close_code.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -247,6 +249,8 @@
 		1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
 		1D3623EB0D0F72F000981E51 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
 		1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+		56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; };
+		56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; };
 		FD0BBFEF0E3933DD00D833B1 /* SDL_uikitview.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitview.h; sourceTree = "<group>"; };
 		FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_uikitkeyboard.h; sourceTree = "<group>"; };
 		FD3F4A700DEA620800C5B771 /* SDL_getenv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_getenv.c; sourceTree = "<group>"; };
@@ -488,6 +492,23 @@
 			name = Frameworks;
 			sourceTree = "<group>";
 		};
+		56ED04DE118A8E9A00A56AA6 /* power */ = {
+			isa = PBXGroup;
+			children = (
+				56ED04E0118A8EE200A56AA6 /* SDL_power.c */,
+				56ED04DF118A8EB700A56AA6 /* uikit */,
+			);
+			name = power;
+			sourceTree = "<group>";
+		};
+		56ED04DF118A8EB700A56AA6 /* uikit */ = {
+			isa = PBXGroup;
+			children = (
+				56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */,
+			);
+			name = uikit;
+			sourceTree = "<group>";
+		};
 		FD3F4A6F0DEA620800C5B771 /* stdlib */ = {
 			isa = PBXGroup;
 			children = (
@@ -642,6 +663,7 @@
 				047677B60EA769DF008ABAF1 /* haptic */,
 				FD5F9D080E0E08B3008E885B /* joystick */,
 				FD8BD8150E27E25900B52CD5 /* loadso */,
+				56ED04DE118A8E9A00A56AA6 /* power */,
 				FD3F4A6F0DEA620800C5B771 /* stdlib */,
 				FD99B9E00DD52EDC00FB1D6B /* thread */,
 				FD99BA1E0DD52EDC00FB1D6B /* timer */,
@@ -1103,6 +1125,8 @@
 				043DD77110FD8A0000DED673 /* SDL_blendfillrect.c in Sources */,
 				043DD77210FD8A0000DED673 /* SDL_drawrect.c in Sources */,
 				04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */,
+				56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */,
+				56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
--- a/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Thu Apr 29 22:53:18 2010 -0400
+++ b/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Fri Apr 30 00:39:31 2010 -0400
@@ -7,6 +7,16 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */ = {isa = PBXBuildFile; fileRef = FDA8AAD90E2D33B000EA573E /* icon.bmp */; };
+		56ED0502118A8FE400A56AA6 /* libSDLiPhoneOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD1B48B80E3131CA007AB34E /* libSDLiPhoneOS.a */; };
+		56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
+		56ED0504118A8FE400A56AA6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; };
+		56ED0505118A8FE400A56AA6 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; };
+		56ED0506118A8FE400A56AA6 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89B0E2D111A00EA573E /* CoreGraphics.framework */; };
+		56ED0507118A8FE400A56AA6 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89C0E2D111A00EA573E /* UIKit.framework */; };
+		56ED0508118A8FE400A56AA6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; };
+		56ED0509118A8FE400A56AA6 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; };
+		56ED0511118A904200A56AA6 /* testpower.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED0510118A904200A56AA6 /* testpower.c */; };
 		FDA8A79B0E2D0F8B00EA573E /* common.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A7840E2D0F1F00EA573E /* common.c */; };
 		FDA8A79C0E2D0F9300EA573E /* testwm2.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A75F0E2D0F1600EA573E /* testwm2.c */; };
 		FDA8A89F0E2D111A00EA573E /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
@@ -288,6 +298,10 @@
 
 /* Begin PBXFileReference section */
 		1D6058910D05DD3D006BFB54 /* testwm2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testwm2.app; sourceTree = BUILT_PRODUCTS_DIR; };
+		56ED04F7118A8FCC00A56AA6 /* testpower-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "testpower-Info.plist"; sourceTree = "<group>"; };
+		56ED050D118A8FE400A56AA6 /* testpower.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testpower.app; sourceTree = BUILT_PRODUCTS_DIR; };
+		56ED050F118A8FE400A56AA6 /* Info copy.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info copy.plist"; sourceTree = "<group>"; };
+		56ED0510118A904200A56AA6 /* testpower.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testpower.c; path = ../../test/testpower.c; sourceTree = SOURCE_ROOT; };
 		FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDLiPhoneOS.xcodeproj; path = ../SDL/SDLiPhoneOS.xcodeproj; sourceTree = SOURCE_ROOT; };
 		FDA8A7400E2D0F1600EA573E /* testalpha.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testalpha.c; path = ../../test/testalpha.c; sourceTree = SOURCE_ROOT; };
 		FDA8A7410E2D0F1600EA573E /* testaudioinfo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testaudioinfo.c; path = ../../test/testaudioinfo.c; sourceTree = SOURCE_ROOT; };
@@ -386,6 +400,21 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		56ED0501118A8FE400A56AA6 /* Frameworks */ = {
+			isa = PBXFrameworksBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				56ED0502118A8FE400A56AA6 /* libSDLiPhoneOS.a in Frameworks */,
+				56ED0503118A8FE400A56AA6 /* AudioToolbox.framework in Frameworks */,
+				56ED0504118A8FE400A56AA6 /* QuartzCore.framework in Frameworks */,
+				56ED0505118A8FE400A56AA6 /* OpenGLES.framework in Frameworks */,
+				56ED0506118A8FE400A56AA6 /* CoreGraphics.framework in Frameworks */,
+				56ED0507118A8FE400A56AA6 /* UIKit.framework in Frameworks */,
+				56ED0508118A8FE400A56AA6 /* Foundation.framework in Frameworks */,
+				56ED0509118A8FE400A56AA6 /* CoreAudio.framework in Frameworks */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		FDA8A9220E2D1C0B00EA573E /* Frameworks */ = {
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
@@ -824,6 +853,7 @@
 				FDD2C6B30E2E92D200B7A85F /* threadwin.app */,
 				FDD2C6F40E2E959E00B7A85F /* torturethread.app */,
 				FDC430000F0D866D009C87E1 /* torturethread.app */,
+				56ED050D118A8FE400A56AA6 /* testpower.app */,
 			);
 			name = Products;
 			sourceTree = "<group>";
@@ -831,11 +861,14 @@
 		29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
 			isa = PBXGroup;
 			children = (
+				56ED0510118A904200A56AA6 /* testpower.c */,
 				FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */,
 				FDA8AAD60E2D339A00EA573E /* Resources */,
 				FDA8A7C30E2D10FA00EA573E /* Linked Frameworks */,
 				FDA8A73B0E2D0F0400EA573E /* src */,
 				19C28FACFE9D520D11CA2CBB /* Products */,
+				56ED04F7118A8FCC00A56AA6 /* testpower-Info.plist */,
+				56ED050F118A8FE400A56AA6 /* Info copy.plist */,
 			);
 			name = CustomTemplate;
 			sourceTree = "<group>";
@@ -941,6 +974,23 @@
 			productReference = 1D6058910D05DD3D006BFB54 /* testwm2.app */;
 			productType = "com.apple.product-type.application";
 		};
+		56ED04FC118A8FE400A56AA6 /* testpower */ = {
+			isa = PBXNativeTarget;
+			buildConfigurationList = 56ED050A118A8FE400A56AA6 /* Build configuration list for PBXNativeTarget "testpower" */;
+			buildPhases = (
+				56ED04FD118A8FE400A56AA6 /* Resources */,
+				56ED04FF118A8FE400A56AA6 /* Sources */,
+				56ED0501118A8FE400A56AA6 /* Frameworks */,
+			);
+			buildRules = (
+			);
+			dependencies = (
+			);
+			name = testpower;
+			productName = TestiPhoneOS;
+			productReference = 56ED050D118A8FE400A56AA6 /* testpower.app */;
+			productType = "com.apple.product-type.application";
+		};
 		FDA8A91D0E2D1C0B00EA573E /* graywin */ = {
 			isa = PBXNativeTarget;
 			buildConfigurationList = FDA8A92C0E2D1C0B00EA573E /* Build configuration list for PBXNativeTarget "graywin" */;
@@ -1437,6 +1487,7 @@
 				FDD2C46B0E2E77D700B7A85F /* testlock */,
 				FDD2C4A60E2E79C300B7A85F /* testpalette */,
 				FDD2C4F90E2E7F4800B7A85F /* testplatform */,
+				56ED04FC118A8FE400A56AA6 /* testpower */,
 				FDD2C5170E2E807600B7A85F /* testsem */,
 				FDD2C53D0E2E80E400B7A85F /* testsprite2 */,
 				FDD2C5740E2E8C7400B7A85F /* testtimer */,
@@ -1468,6 +1519,14 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		56ED04FD118A8FE400A56AA6 /* Resources */ = {
+			isa = PBXResourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				56ED04FE118A8FE400A56AA6 /* icon.bmp in Resources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		FDA8A91E0E2D1C0B00EA573E /* Resources */ = {
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
@@ -1681,6 +1740,14 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
+		56ED04FF118A8FE400A56AA6 /* Sources */ = {
+			isa = PBXSourcesBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+				56ED0511118A904200A56AA6 /* testpower.c in Sources */,
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+		};
 		FDA8A91F0E2D1C0B00EA573E /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
@@ -1929,6 +1996,32 @@
 			};
 			name = Release;
 		};
+		56ED050B118A8FE400A56AA6 /* Debug */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				COPY_PHASE_STRIP = NO;
+				GCC_DYNAMIC_NO_PIC = NO;
+				GCC_OPTIMIZATION_LEVEL = 0;
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "";
+				INFOPLIST_FILE = "Info copy.plist";
+				PRODUCT_NAME = testpower;
+			};
+			name = Debug;
+		};
+		56ED050C118A8FE400A56AA6 /* Release */ = {
+			isa = XCBuildConfiguration;
+			buildSettings = {
+				ALWAYS_SEARCH_USER_PATHS = NO;
+				COPY_PHASE_STRIP = YES;
+				GCC_PRECOMPILE_PREFIX_HEADER = YES;
+				GCC_PREFIX_HEADER = "";
+				INFOPLIST_FILE = "Info copy.plist";
+				PRODUCT_NAME = testpower;
+			};
+			name = Release;
+		};
 		C01FCF4F08A954540054247B /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
@@ -2674,6 +2767,15 @@
 			defaultConfigurationIsVisible = 0;
 			defaultConfigurationName = Release;
 		};
+		56ED050A118A8FE400A56AA6 /* Build configuration list for PBXNativeTarget "testpower" */ = {
+			isa = XCConfigurationList;
+			buildConfigurations = (
+				56ED050B118A8FE400A56AA6 /* Debug */,
+				56ED050C118A8FE400A56AA6 /* Release */,
+			);
+			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
+		};
 		C01FCF4E08A954540054247B /* Build configuration list for PBXProject "TestiPhoneOS" */ = {
 			isa = XCConfigurationList;
 			buildConfigurations = (
--- a/include/SDL_config_iphoneos.h	Thu Apr 29 22:53:18 2010 -0400
+++ b/include/SDL_config_iphoneos.h	Fri Apr 30 00:39:31 2010 -0400
@@ -142,7 +142,7 @@
 #define SDL_VIDEO_RENDER_OGL_ES	1
 
 /* Enable system power support */
-#define SDL_POWER_MACOSX 1
+#define SDL_POWER_UIKIT 1
 
 /* enable iPhone keyboard support */
 #define SDL_IPHONE_KEYBOARD 0
--- a/src/power/SDL_power.c	Thu Apr 29 22:53:18 2010 -0400
+++ b/src/power/SDL_power.c	Fri Apr 30 00:39:31 2010 -0400
@@ -36,6 +36,7 @@
 SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
 SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
 SDL_bool SDL_GetPowerInfo_NintendoDS(SDL_PowerState *, int *, int *);
+SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
 
 #ifndef SDL_POWER_DISABLED
 #ifdef SDL_POWER_HARDWIRED
@@ -61,7 +62,10 @@
 #ifdef SDL_POWER_WINDOWS        /* handles Win32, Win64, PocketPC. */
     SDL_GetPowerInfo_Windows,
 #endif
-#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin, iPhone. */
+#ifdef SDL_POWER_UIKIT          /* handles iPhone/iPad/etc */
+    SDL_GetPowerInfo_UIKit,
+#endif
+#ifdef SDL_POWER_MACOSX         /* handles Mac OS X, Darwin. */
     SDL_GetPowerInfo_MacOSX,
 #endif
 #ifdef SDL_POWER_NINTENDODS     /* handles Nintendo DS. */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/power/uikit/SDL_syspower.m	Fri Apr 30 00:39:31 2010 -0400
@@ -0,0 +1,100 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2010 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+#ifndef SDL_POWER_DISABLED
+#ifdef SDL_POWER_UIKIT
+
+#import <UIKit/UIKit.h>
+
+#include "SDL_power.h"
+#include "SDL_timer.h"
+#include "SDL_assert.h"
+
+// turn off the battery monitor if it's been more than X ms since last check.
+static const int BATTERY_MONITORING_TIMEOUT = 3000;
+static Uint32 SDL_UIKitLastPowerInfoQuery = 0;
+
+void
+SDL_UIKit_UpdateBatteryMonitoring(void)
+{
+    if (SDL_UIKitLastPowerInfoQuery) {
+        const Uint32 prev = SDL_UIKitLastPowerInfoQuery;
+        const UInt32 now = SDL_GetTicks();
+        const UInt32 ticks = now - prev;
+        // if timer wrapped (now < prev), shut down, too.
+        if ((now < prev) || (ticks >= BATTERY_MONITORING_TIMEOUT)) {
+            UIDevice *uidev = [UIDevice currentDevice];
+            SDL_assert([uidev isBatteryMonitoringEnabled] == YES);
+            [uidev setBatteryMonitoringEnabled:NO];
+            SDL_UIKitLastPowerInfoQuery = 0;
+        }
+    }
+}
+
+SDL_bool
+SDL_GetPowerInfo_UIKit(SDL_PowerState * state, int *seconds, int *percent)
+{
+    UIDevice *uidev = [UIDevice currentDevice];
+
+    if (!SDL_UIKitLastPowerInfoQuery) {
+        SDL_assert([uidev isBatteryMonitoringEnabled] == NO);
+        [uidev setBatteryMonitoringEnabled:YES];
+    }
+
+    // UIKit_GL_SwapWindow() (etc) will check this and disable the battery
+    //  monitoring if the app hasn't queried it in the last X seconds.
+    //  Apparently monitoring the battery burns battery life.  :)
+    //  Apple's docs say not to monitor the battery unless you need it.
+    SDL_UIKitLastPowerInfoQuery = SDL_GetTicks();
+
+    *seconds = -1;   // no API to estimate this in UIKit.
+
+    switch ([uidev batteryState])
+    {
+        case UIDeviceBatteryStateCharging:
+            *state = SDL_POWERSTATE_CHARGING;
+            break;
+
+        case UIDeviceBatteryStateFull:
+            *state = SDL_POWERSTATE_CHARGED;
+            break;
+
+        case UIDeviceBatteryStateUnplugged:
+            *state = SDL_POWERSTATE_ON_BATTERY;
+            break;
+
+        case UIDeviceBatteryStateUnknown:
+        default:
+            *state = SDL_POWERSTATE_UNKNOWN;
+            break;
+    }
+
+    const float level = [uidev batteryLevel];
+    *percent = ( (level < 0.0f) ? -1 : (((int) (level + 0.5f)) * 100) );
+    return SDL_TRUE;            /* always the definitive answer on iPhoneOS. */
+}
+
+#endif /* SDL_POWER_UIKIT */
+#endif /* SDL_POWER_DISABLED */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/uikit/SDL_uikitopengles.m	Thu Apr 29 22:53:18 2010 -0400
+++ b/src/video/uikit/SDL_uikitopengles.m	Fri Apr 30 00:39:31 2010 -0400
@@ -73,9 +73,14 @@
     return 0;
 }
 
+extern void SDL_UIKit_UpdateBatteryMonitoring(void);
 
 void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
 {
+    #ifdef SDL_POWER_UIKIT
+    // Check once a frame to see if we should turn off the battery monitor.
+    SDL_UIKit_UpdateBatteryMonitoring();
+    #endif
 
 	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;