From aa0673c43f478032349c2d171694d6b506f38695 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 23 Mar 2023 22:55:46 -0500 Subject: [PATCH] Print the device name and GUID for connected pads --- src/d_main.c | 10 +++++++-- src/i_joy.h | 2 ++ src/sdl/i_system.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 7b75ff8d0..e93ea3042 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -38,6 +38,7 @@ #include "f_finale.h" #include "g_game.h" #include "hu_stuff.h" +#include "i_joy.h" #include "i_sound.h" #include "i_system.h" #include "i_time.h" @@ -174,11 +175,16 @@ boolean capslock = 0; // gee i wonder what this does. static void HandleGamepadDeviceAdded(event_t *ev) { + char guid[64]; + char name[256]; + I_Assert(ev != NULL); I_Assert(ev->type == ev_gamepad_device_added); G_RegisterAvailableGamepad(ev->device); - CONS_Debug(DBG_GAMELOGIC, "Registered available gamepad device %d\n", ev->device); + I_GetGamepadGuid(ev->device, guid, sizeof(guid)); + I_GetGamepadName(ev->device, name, sizeof(name)); + CONS_Alert(CONS_NOTICE, "Gamepad device %d connected: %s (%s)\n", ev->device, name, guid); } static void HandleGamepadDeviceRemoved(event_t *ev) @@ -188,7 +194,7 @@ static void HandleGamepadDeviceRemoved(event_t *ev) I_Assert(ev->type == ev_gamepad_device_removed); G_UnregisterAvailableGamepad(ev->device); - CONS_Debug(DBG_GAMELOGIC, "Unregistered available gamepad device %d\n", ev->device); + CONS_Alert(CONS_NOTICE, "Gamepad device %d disconnected\n", ev->device); // Downstream responders need to update player gamepad assignments, pause, etc diff --git a/src/i_joy.h b/src/i_joy.h index 15e3b264f..925e69bcf 100644 --- a/src/i_joy.h +++ b/src/i_joy.h @@ -60,6 +60,8 @@ extern JoyType_t Joystick[MAXSPLITSCREENPLAYERS]; void I_SetGamepadPlayerIndex(INT32 device_id, INT32 index); void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue); +void I_GetGamepadGuid(INT32 device_id, char *out, int out_len); +void I_GetGamepadName(INT32 device_id, char *out, int out_len); #ifdef __cplusplus } // extern "C" diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 92938e3f7..4a8999cd3 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -963,6 +963,62 @@ void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 b #endif } +void I_GetGamepadGuid(INT32 device_id, char *out, int out_len) +{ + SDL_GameController *controller; + SDL_Joystick *joystick; + SDL_JoystickGUID guid; + + I_Assert(device_id > 0); + I_Assert(out != NULL); + I_Assert(out_len > 0); + + if (out_len < 33) + { + out[0] = 0; + return; + } + + controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + out[0] = 0; + return; + } + joystick = SDL_GameControllerGetJoystick(controller); + if (joystick == NULL) + { + out[0] = 0; + return; + } + + guid = SDL_JoystickGetGUID(joystick); + SDL_JoystickGetGUIDString(guid, out, out_len); +} + +void I_GetGamepadName(INT32 device_id, char *out, int out_len) +{ + SDL_GameController *controller; + const char *name; + int name_len; + + I_Assert(device_id > 0); + I_Assert(out != NULL); + I_Assert(out_len > 0); + + controller = SDL_GameControllerFromInstanceID(device_id - 1); + if (controller == NULL) + { + out[0] = 0; + return; + } + + name = SDL_GameControllerName(controller); + name_len = strlen(name) + 1; + memcpy(out, name, out_len < name_len ? out_len : name_len); + out[out_len - 1] = 0; +} + // // I_StartupInput //