2 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
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.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
12 /* Simple test of power subsystem. */
21 const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
22 char *statestr = NULL;
24 SDL_Log("SDL-reported power info...\n");
26 case SDL_POWERSTATE_UNKNOWN:
29 case SDL_POWERSTATE_ON_BATTERY:
30 statestr = "On battery";
32 case SDL_POWERSTATE_NO_BATTERY:
33 statestr = "No battery";
35 case SDL_POWERSTATE_CHARGING:
36 statestr = "Charging";
38 case SDL_POWERSTATE_CHARGED:
42 statestr = "!!API ERROR!!";
46 SDL_Log("State: %s\n", statestr);
49 SDL_Log("Percent left: unknown\n");
51 SDL_Log("Percent left: %d%%\n", percent);
55 SDL_Log("Time left: unknown\n");
57 SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
58 (int) (seconds % 60));
64 main(int argc, char *argv[])
66 /* Enable standard application logging */
67 SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
69 if (SDL_Init(0) == -1) {
70 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
80 /* end of testpower.c ... */