Mercurial > sdl-ios-xcode
comparison test/testpower.c @ 3170:b7a48f533966
Initial work on power subsystem for SDL 1.3.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 07 Jun 2009 06:06:35 +0000 |
parents | |
children | 51750b7a966f |
comparison
equal
deleted
inserted
replaced
3169:f294338ca6eb | 3170:b7a48f533966 |
---|---|
1 /* Simple test of power subsystem. */ | |
2 | |
3 #include <stdio.h> | |
4 #include "SDL.h" | |
5 | |
6 static void report_power(void) | |
7 { | |
8 int seconds, percent; | |
9 const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent); | |
10 char *statestr = NULL; | |
11 | |
12 printf("SDL-reported power info...\n"); | |
13 switch(state) | |
14 { | |
15 case SDL_POWERSTATE_UNKNOWN: | |
16 statestr = "Unknown"; | |
17 break; | |
18 case SDL_POWERSTATE_ON_BATTERY: | |
19 statestr = "On battery"; | |
20 break; | |
21 case SDL_POWERSTATE_NO_BATTERY: | |
22 statestr = "No battery"; | |
23 break; | |
24 case SDL_POWERSTATE_CHARGING: | |
25 statestr = "Charging"; | |
26 break; | |
27 case SDL_POWERSTATE_CHARGED: | |
28 statestr = "Charged"; | |
29 break; | |
30 default: | |
31 statestr = "!!API ERROR!!"; | |
32 break; | |
33 } | |
34 | |
35 printf("State: %s\n", statestr); | |
36 | |
37 if (percent == -1) { | |
38 printf("Percent left: unknown\n"); | |
39 } else { | |
40 printf("Percent left: %d%%\n", percent); | |
41 } | |
42 | |
43 if (seconds == -1) { | |
44 printf("Time left: unknown\n"); | |
45 } else { | |
46 printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60), (int) (seconds % 60)); | |
47 } | |
48 } | |
49 | |
50 | |
51 int main(int argc, char *argv[]) | |
52 { | |
53 if (SDL_Init(SDL_INIT_VIDEO) == -1) { | |
54 fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); | |
55 return 1; | |
56 } | |
57 | |
58 report_power(); | |
59 | |
60 SDL_Quit(); | |
61 return 0; | |
62 } | |
63 | |
64 /* end of testpower.c ... */ | |
65 |