From 3b4458caa8c08671276e71068d2ecab6d2173a81 Mon Sep 17 00:00:00 2001 From: fewtarius Date: Thu, 8 Feb 2024 12:54:50 +0000 Subject: [PATCH] Controller-gen should only return valid controllers. --- .../emulators/tools/control-gen/control-gen.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/emulators/tools/control-gen/control-gen.cpp b/packages/emulators/tools/control-gen/control-gen.cpp index 62cfc1b1c..3c06b1521 100644 --- a/packages/emulators/tools/control-gen/control-gen.cpp +++ b/packages/emulators/tools/control-gen/control-gen.cpp @@ -7,7 +7,9 @@ int main() { - SDL_Init(SDL_INIT_JOYSTICK); + + SDL_GameControllerAddMappingsFromFile("/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt"); + SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); atexit(SDL_Quit); int num_joysticks = SDL_NumJoysticks(); @@ -18,13 +20,17 @@ int main() if (js) { SDL_JoystickGUID guid = SDL_JoystickGetGUID(js); + bool is_controller = SDL_IsGameController(i); + char guid_str[1024]; SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str)); - const char* name = SDL_JoystickName(js); - - printf("controlfolder=\"/storage/.config/gptokeyb\"\nESUDO=\"sudo\"\nESUDOKILL=\"-sudokill\"\nexport SDL_GAMECONTROLLERCONFIG_FILE=\"$controlfolder/gamecontrollerdb.txt\"\nSDLDBFILE=\"${SDL_GAMECONTROLLERCONFIG_FILE}\"\n[ -z \"${SDLDBFILE}\" ] && SDLDBFILE=\"${controlfolder}/gamecontrollerdb.txt\"\nSDLDBUSERFILE=\"/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt\"\nget_controls() {\nANALOGSTICKS=\"2\"\nDEVICE=\"%s\"\nparam_device=\"%s\"\n}\nGPTOKEYB=\"$controlfolder/gptokeyb $ESUDOKILL\"", - guid_str, name); + if (is_controller) + { + const char* name = SDL_JoystickName(js); + printf("controlfolder=\"/storage/.config/gptokeyb\"\nESUDO=\"sudo\"\nESUDOKILL=\"-sudokill\"\nexport SDL_GAMECONTROLLERCONFIG_FILE=\"$controlfolder/gamecontrollerdb.txt\"\nSDLDBFILE=\"${SDL_GAMECONTROLLERCONFIG_FILE}\"\n[ -z \"${SDLDBFILE}\" ] && SDLDBFILE=\"${controlfolder}/gamecontrollerdb.txt\"\nSDLDBUSERFILE=\"/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt\"\nget_controls() {\nANALOGSTICKS=\"2\"\nDEVICE=\"%s\"\nparam_device=\"%s\"\n}\nGPTOKEYB=\"$controlfolder/gptokeyb $ESUDOKILL\"", + guid_str, name); + } SDL_JoystickClose(js); } }