Mercurial > sdl-ios-xcode
comparison src/power/windows/SDL_syspower.c @ 3186:51750b7a966f
indent
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Jun 2009 13:34:20 +0000 |
parents | b7a48f533966 |
children | f7b03b6838cb |
comparison
equal
deleted
inserted
replaced
3185:44d5474c2c8a | 3186:51750b7a966f |
---|---|
28 #include <windows.h> | 28 #include <windows.h> |
29 | 29 |
30 #include "SDL_power.h" | 30 #include "SDL_power.h" |
31 | 31 |
32 SDL_bool | 32 SDL_bool |
33 SDL_GetPowerInfo_Windows(SDL_PowerState *state, int *seconds, int *percent) | 33 SDL_GetPowerInfo_Windows(SDL_PowerState * state, int *seconds, int *percent) |
34 { | 34 { |
35 SYSTEM_POWER_STATUS status; | 35 SYSTEM_POWER_STATUS status; |
36 SDL_bool need_details = SDL_FALSE; | 36 SDL_bool need_details = SDL_FALSE; |
37 | 37 |
38 /* This API should exist back to Win95 and Windows CE. */ | 38 /* This API should exist back to Win95 and Windows CE. */ |
39 if (!GetSystemPowerStatus(&status)) { | 39 if (!GetSystemPowerStatus(&status)) { |
40 /* !!! FIXME: push GetLastError() into SDL_GetError() */ | 40 /* !!! FIXME: push GetLastError() into SDL_GetError() */ |
41 *state = SDL_POWERSTATE_UNKNOWN; | 41 *state = SDL_POWERSTATE_UNKNOWN; |
42 } else if (status.BatteryFlag == 0xFF) { /* unknown state */ | 42 } else if (status.BatteryFlag == 0xFF) { /* unknown state */ |
43 *state = SDL_POWERSTATE_UNKNOWN; | 43 *state = SDL_POWERSTATE_UNKNOWN; |
44 } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ | 44 } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ |
45 *state = SDL_POWERSTATE_NO_BATTERY; | 45 *state = SDL_POWERSTATE_NO_BATTERY; |
46 } else if (status.BatteryFlag & (1 << 3)) { /* charging */ | 46 } else if (status.BatteryFlag & (1 << 3)) { /* charging */ |
47 *state = SDL_POWERSTATE_CHARGING; | 47 *state = SDL_POWERSTATE_CHARGING; |
48 need_details = SDL_TRUE; | 48 need_details = SDL_TRUE; |
49 } else if (status.ACLineStatus == 1) { | 49 } else if (status.ACLineStatus == 1) { |
50 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ | 50 *state = SDL_POWERSTATE_CHARGED; /* on AC, not charging. */ |
51 need_details = SDL_TRUE; | 51 need_details = SDL_TRUE; |
52 } else { | 52 } else { |
53 *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */ | 53 *state = SDL_POWERSTATE_ON_BATTERY; /* not on AC. */ |
54 need_details = SDL_TRUE; | 54 need_details = SDL_TRUE; |
55 } | 55 } |
56 | 56 |
57 *percent = -1; | 57 *percent = -1; |
58 *seconds = -1; | 58 *seconds = -1; |
59 if (need_details) { | 59 if (need_details) { |
60 const int pct = (int) status.BatteryLifePercent; | 60 const int pct = (int) status.BatteryLifePercent; |
61 const int secs = (int) status.BatteryLifeTime; | 61 const int secs = (int) status.BatteryLifeTime; |
62 | 62 |
63 if (pct != 255) { /* 255 == unknown */ | 63 if (pct != 255) { /* 255 == unknown */ |
64 *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ | 64 *percent = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ |
65 } | 65 } |
66 if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ | 66 if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ |
67 *seconds = secs; | 67 *seconds = secs; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 return SDL_TRUE; /* always the definitive answer on Windows. */ | 71 return SDL_TRUE; /* always the definitive answer on Windows. */ |
72 } | 72 } |
73 | 73 |
74 #endif /* SDL_POWER_WINDOWS */ | 74 #endif /* SDL_POWER_WINDOWS */ |
75 #endif /* SDL_POWER_DISABLED */ | 75 #endif /* SDL_POWER_DISABLED */ |
76 | 76 |
77 /* vi: set ts=4 sw=4 expandtab: */ | 77 /* vi: set ts=4 sw=4 expandtab: */ |
78 |