Mercurial > sdl-ios-xcode
annotate src/power/windows/SDL_syspower.c @ 5088:c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 24 Jan 2011 15:46:11 -0800 |
parents | f7b03b6838cb |
children | 327f181542f1 |
rev | line source |
---|---|
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 /* |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
3697 | 3 Copyright (C) 1997-2010 Sam Lantinga |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 Lesser General Public License for more details. |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 Sam Lantinga |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 #include "SDL_config.h" |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 #ifndef SDL_POWER_DISABLED |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 #ifdef SDL_POWER_WINDOWS |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 #define WIN32_LEAN_AND_MEAN |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 #include <windows.h> |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 #include "SDL_power.h" |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 SDL_bool |
3186 | 33 SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent) |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 { |
5088
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
35 #ifdef _WIN32_WCE |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
36 SYSTEM_POWER_STATUS_EX status; |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
37 #else |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 SYSTEM_POWER_STATUS status; |
5088
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
39 #endif |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 SDL_bool need_details = SDL_FALSE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 /* This API should exist back to Win95 and Windows CE. */ |
5088
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
43 #ifdef _WIN32_WCE |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
44 if (!GetSystemPowerStatusEx(&status, FALSE)) |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
45 #else |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
46 if (!GetSystemPowerStatus(&status)) |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
47 #endif |
c2539ff054c8
Fixed compiling on Windows Mobile SDK 5.0 with Visual Studio 2008
Sam Lantinga <slouken@libsdl.org>
parents:
3697
diff
changeset
|
48 { |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 /* !!! FIXME: push GetLastError() into SDL_GetError() */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 *state = SDL_POWERSTATE_UNKNOWN; |
3186 | 51 } else if (status.BatteryFlag == 0xFF) { /* unknown state */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 *state = SDL_POWERSTATE_UNKNOWN; |
3186 | 53 } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 *state = SDL_POWERSTATE_NO_BATTERY; |
3186 | 55 } else if (status.BatteryFlag & (1 << 3)) { /* charging */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 *state = SDL_POWERSTATE_CHARGING; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 } else if (status.ACLineStatus == 1) { |
3186 | 59 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 } else { |
3186 | 62 *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 need_details = SDL_TRUE; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 *percent = -1; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 *seconds = -1; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 if (need_details) { |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 const int pct = (int) status.BatteryLifePercent; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 const int secs = (int) status.BatteryLifeTime; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
3186 | 72 if (pct != 255) { /* 255 == unknown */ |
73 *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ | |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 } |
3186 | 75 if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 *seconds = secs; |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
3186 | 80 return SDL_TRUE; /* always the definitive answer on Windows. */ |
3170
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
81 } |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
82 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
83 #endif /* SDL_POWER_WINDOWS */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
84 #endif /* SDL_POWER_DISABLED */ |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
85 |
b7a48f533966
Initial work on power subsystem for SDL 1.3.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
86 /* vi: set ts=4 sw=4 expandtab: */ |