2015-06-21 09:33:46 -06:00
|
|
|
/*
|
2022-01-03 10:40:00 -07:00
|
|
|
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 09:33:46 -06: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-26 21:43:38 -07:00
|
|
|
#include <SDL3/SDL.h>
|
2022-12-14 21:58:20 -07:00
|
|
|
#include <SDL3/SDL_main.h>
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
static void
|
|
|
|
report_power(void)
|
|
|
|
{
|
|
|
|
int seconds, percent;
|
|
|
|
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
|
2021-11-19 15:02:02 -07:00
|
|
|
const char *statestr = NULL;
|
2015-06-21 09:33:46 -06: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-01 14:07:03 -07:00
|
|
|
SDL_Log("Time left: %d minutes, %d seconds\n", seconds / 60, seconds % 60);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
int main(int argc, char *argv[])
|
2015-06-21 09:33:46 -06:00
|
|
|
{
|
|
|
|
/* Enable standard application logging */
|
|
|
|
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
|
|
|
|
|
|
|
if (SDL_Init(0) == -1) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
report_power();
|
|
|
|
|
|
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of testpower.c ... */
|
2022-11-26 02:41:46 -07:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|