testgamecontroller: Add battery reporting

This commit is contained in:
Cameron Gutman 2022-07-24 15:19:02 -05:00
parent 4d8bb89c46
commit b8a5540740
1 changed files with 15 additions and 0 deletions

View File

@ -69,6 +69,17 @@ static const struct { int x; int y; double angle; } axis_positions[] = {
};
SDL_COMPILE_TIME_ASSERT(axis_positions, SDL_arraysize(axis_positions) == SDL_CONTROLLER_AXIS_MAX);
/* This is indexed by SDL_JoystickPowerLevel + 1. */
static const char* power_level_strings[] = {
"unknown", /* SDL_JOYSTICK_POWER_UNKNOWN */
"empty", /* SDL_JOYSTICK_POWER_EMPTY */
"low", /* SDL_JOYSTICK_POWER_LOW */
"medium", /* SDL_JOYSTICK_POWER_MEDIUM */
"full", /* SDL_JOYSTICK_POWER_FULL */
"wired", /* SDL_JOYSTICK_POWER_WIRED */
};
SDL_COMPILE_TIME_ASSERT(power_level_strings, SDL_arraysize(power_level_strings) == SDL_JOYSTICK_POWER_MAX + 1);
static SDL_Window *window = NULL;
static SDL_Renderer *screen = NULL;
static SDL_bool retval = SDL_FALSE;
@ -587,6 +598,10 @@ loop(void *arg)
}
break;
case SDL_JOYBATTERYUPDATED:
SDL_Log("Controller %d battery state changed to %s\n", event.jbattery.which, power_level_strings[event.jbattery.level + 1]);
break;
case SDL_MOUSEBUTTONDOWN:
if (virtual_joystick) {
VirtualControllerMouseDown(event.button.x, event.button.y);