|
Size: 1655
Comment: update content - pointers, structs
|
Size: 2102
Comment: Improved documentation
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 12: | Line 12: |
| SDL_PowerState SDL_GetPowerInfo(int* secs, int* pct) |
SDL_PowerState SDL_GetPowerInfo(int* secs, int* pct) |
| Line 19: | Line 18: |
alternative text: ||'''secs'''||seconds of battery life left; NULL if irrelevant/unimportant|| ||'''pct'''||percent of battery life left (0 - 100); NULL if irrelevant/unimportant|| |
|
| Line 31: | Line 26: |
| <<Color2(green,Above is an include from the enum. Below is text that was listed as param in the header but seems more relevant here or in Remarks.)>> ,,Both parameters will,, return^s^ ,,-1 ,,^a negative error code^ if a value can't be determined, or if not running on a battery. |
Both parameters will return -1 if a value can't be determined, or if not running on a battery. |
| Line 36: | Line 30: |
| You can add your code example here | int secs, pct; if (SDL_GetPowerInfo(&secs, &pct) == SDL_POWERSTATE_ON_BATTERY) { printf("Battery is draining: "); if (secs == -1) { printf("(unknown time left)\n"); } else { printf("(%d seconds left)\n", secs); } if (pct == -1) { printf("(unknown percentage left)\n"); } else { printf("(%d percent left)\n", pct); } } |
| Line 40: | Line 48: |
| ''You can add useful comments here'' | You should never take a battery status as absolute truth. Batteries (especially failing batteries) are delicate hardware, and the values reported here are best estimates based on what that hardware supports. It's not uncommon for older batteries to lose stored power much faster than it reports, or completely drain when reporting it has 20 percent left, etc. |
| Line 42: | Line 50: |
| == Related Functions == | Battery status can change at any time; if you are concerned with power state, you should call this function frequently, and perhaps ignore changes until they seem to be stable for a few seconds. |
DRAFT |
SDL_GetPowerInfo
Use this function to get the current power supply details.
Syntax
SDL_PowerState SDL_GetPowerInfo(int* secs, int* pct)
Function Parameters
secs |
seconds of battery life left. You can pass a NULL here if you don't care. Will return -1 if we can't determine a value, or we're not running on a battery |
pct |
percentage of battery life left, between 0 and 100. You can pass a NULL here if you don't care. Will return -1 if we can't determine a value, or we're not running on a battery |
Return Value
Returns the state of the battery, if any. Return values may be any of the following:
SDL_POWERSTATE_UNKNOWN |
cannot determine power status |
SDL_POWERSTATE_ON_BATTERY |
not plugged in, running on the battery |
SDL_POWERSTATE_NO_BATTERY |
plugged in, no battery available |
SDL_POWERSTATE_CHARGING |
plugged in, charging battery |
SDL_POWERSTATE_CHARGED |
plugged in, battery charged |
See SDL_PowerState for more info.
Both parameters will return -1 if a value can't be determined, or if not running on a battery.
Code Examples
int secs, pct;
if (SDL_GetPowerInfo(&secs, &pct) == SDL_POWERSTATE_ON_BATTERY) {
printf("Battery is draining: ");
if (secs == -1) {
printf("(unknown time left)\n");
} else {
printf("(%d seconds left)\n", secs);
}
if (pct == -1) {
printf("(unknown percentage left)\n");
} else {
printf("(%d percent left)\n", pct);
}
}
Remarks
You should never take a battery status as absolute truth. Batteries (especially failing batteries) are delicate hardware, and the values reported here are best estimates based on what that hardware supports. It's not uncommon for older batteries to lose stored power much faster than it reports, or completely drain when reporting it has 20 percent left, etc.
Battery status can change at any time; if you are concerned with power state, you should call this function frequently, and perhaps ignore changes until they seem to be stable for a few seconds.
