2015-06-21 23:33:46 +08:00
|
|
|
/*
|
2023-01-10 01:41:41 +08:00
|
|
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
/* Simple test of power subsystem. */
|
|
|
|
|
2022-11-27 12:43:38 +08:00
|
|
|
#include <SDL3/SDL.h>
|
2022-12-15 12:58:20 +08:00
|
|
|
#include <SDL3/SDL_main.h>
|
2023-03-17 07:25:39 +08:00
|
|
|
#include <SDL3/SDL_test.h>
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
report_power(void)
|
|
|
|
{
|
|
|
|
int seconds, percent;
|
|
|
|
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
|
2021-11-20 06:02:02 +08:00
|
|
|
const char *statestr = NULL;
|
2015-06-21 23:33:46 +08:00
|
|
|
|
|
|
|
SDL_Log("SDL-reported power info...\n");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Log("State: %s\n", statestr);
|
|
|
|
|
|
|
|
if (percent == -1) {
|
|
|
|
SDL_Log("Percent left: unknown\n");
|
|
|
|
} else {
|
|
|
|
SDL_Log("Percent left: %d%%\n", percent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seconds == -1) {
|
|
|
|
SDL_Log("Time left: unknown\n");
|
|
|
|
} else {
|
2022-12-02 05:07:03 +08:00
|
|
|
SDL_Log("Time left: %d minutes, %d seconds\n", seconds / 60, seconds % 60);
|
2015-06-21 23:33:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 04:51:59 +08:00
|
|
|
int main(int argc, char *argv[])
|
2015-06-21 23:33:46 +08:00
|
|
|
{
|
2023-03-17 07:25:39 +08:00
|
|
|
SDLTest_CommonState *state;
|
|
|
|
|
|
|
|
/* Initialize test framework */
|
|
|
|
state = SDLTest_CommonCreateState(argv, 0);
|
2023-11-10 05:29:15 +08:00
|
|
|
if (!state) {
|
2023-03-17 07:25:39 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
/* Enable standard application logging */
|
|
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
|
|
|
|
2023-03-17 07:25:39 +08:00
|
|
|
/* Parse commandline */
|
|
|
|
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SDL_Init(0) < 0) {
|
2015-06-21 23:33:46 +08:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
report_power();
|
|
|
|
|
|
|
|
SDL_Quit();
|
2023-03-17 07:25:39 +08:00
|
|
|
SDLTest_CommonDestroyState(state);
|
|
|
|
|
2015-06-21 23:33:46 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of testpower.c ... */
|