Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
77 lines (64 loc) · 1.77 KB

testpower.c

File metadata and controls

77 lines (64 loc) · 1.77 KB
 
Apr 8, 2011
Apr 8, 2011
1
2
3
4
5
6
7
8
9
10
11
/*
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
12
13
14
15
16
/* Simple test of power subsystem. */
#include <stdio.h>
#include "SDL.h"
Jun 10, 2009
Jun 10, 2009
17
18
static void
report_power(void)
19
20
21
22
23
24
{
int seconds, percent;
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
char *statestr = NULL;
printf("SDL-reported power info...\n");
Jun 10, 2009
Jun 10, 2009
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
switch (state) {
case SDL_POWERSTATE_UNKNOWN:
statestr = "Unknown";
break;
case SDL_POWERSTATE_ON_BATTERY:
statestr = "On battery";
break;
case SDL_POWERSTATE_NO_BATTERY:
statestr = "No battery";
break;
case SDL_POWERSTATE_CHARGING:
statestr = "Charging";
break;
case SDL_POWERSTATE_CHARGED:
statestr = "Charged";
break;
default:
statestr = "!!API ERROR!!";
break;
44
45
46
47
48
49
50
51
52
53
54
55
56
}
printf("State: %s\n", statestr);
if (percent == -1) {
printf("Percent left: unknown\n");
} else {
printf("Percent left: %d%%\n", percent);
}
if (seconds == -1) {
printf("Time left: unknown\n");
} else {
Jun 10, 2009
Jun 10, 2009
57
58
printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
(int) (seconds % 60));
59
60
61
62
}
}
Jun 10, 2009
Jun 10, 2009
63
64
int
main(int argc, char *argv[])
65
66
67
68
69
70
71
72
73
74
75
76
77
{
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
return 1;
}
report_power();
SDL_Quit();
return 0;
}
/* end of testpower.c ... */