From b8a55407400646892ead1b48936876074c28d971 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 24 Jul 2022 15:19:02 -0500 Subject: [PATCH] testgamecontroller: Add battery reporting --- test/testgamecontroller.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index bd2281077..ef54d698d 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -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);