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