From 36528bb723e400aa4a611f6394702bbfaaea7c4e Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Wed, 3 May 2017 11:47:16 +0200 Subject: [PATCH] onepad: allow to save/reload SDL2 mapping from OnePAD2.ini file SDL_GAMECONTROLLERCONFIG is nice but limited to a single entry. (Note it can still be used) Option name is SDL2. Here an example SDL2 = 03000000a306000020f6000011010000,PS2700 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a4,start:b9,x:b0,y:b3,platform:Linux, --- plugins/onepad/Linux/ini.cpp | 7 +++++++ plugins/onepad/SDL/joystick.cpp | 10 ++++++---- plugins/onepad/controller.h | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/plugins/onepad/Linux/ini.cpp b/plugins/onepad/Linux/ini.cpp index 77a867fa6a..161d6e770d 100644 --- a/plugins/onepad/Linux/ini.cpp +++ b/plugins/onepad/Linux/ini.cpp @@ -100,6 +100,9 @@ void SaveConfig() for (auto const &it : conf->keysym_map[pad]) fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second); + for (auto const &it : conf->sdl2_mapping) + fprintf(f, "SDL2 = %s\n", it.c_str()); + fclose(f); } @@ -149,6 +152,10 @@ void LoadConfig() have_user_setting = true; } + char sdl2[512]; + while (fscanf(f, "SDL2 = %511[^\n]\n", sdl2) == 1) + conf->sdl2_mapping.push_back(std::string(sdl2)); + if (!have_user_setting) DefaultKeyboardValues(); diff --git a/plugins/onepad/SDL/joystick.cpp b/plugins/onepad/SDL/joystick.cpp index 75a38c9528..8dc21774bb 100644 --- a/plugins/onepad/SDL/joystick.cpp +++ b/plugins/onepad/SDL/joystick.cpp @@ -57,11 +57,13 @@ void JoystickInfo::EnumerateJoysticks(std::vector> &vjo // SDL forget to add const for SDL_RWFromMem API... void *data = const_cast(g_bytes_get_data(bytes, &size)); - int map = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(data, size), 1); - - fprintf(stdout, "onepad: load %d extra joystick map\n", map); + SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(data, size), 1); g_bytes_unref(bytes); + + // Add user mapping too + for (auto const &map : conf->sdl2_mapping) + SDL_GameControllerAddMapping(map.c_str()); } } @@ -141,7 +143,7 @@ JoystickInfo::JoystickInfo(int id) if (m_controller == nullptr) { fprintf(stderr, "onepad: Joystick (%s,GUID:%s) isn't yet supported by the SDL2 game controller API\n" "Fortunately you can use AntiMicro (https://github.com/AntiMicro/antimicro) or Steam to configure your joystick\n" - "You can add a new mapping with the environment variable SDL_GAMECONTROLLERCONFIG\n" + "The mapping can be stored in OnePAD2.ini as 'SDL2 = <...mapping description...>'\n" "Please report it to us (https://github.com/PCSX2/pcsx2/issues) so we can add your joystick to our internal database.", devname, guid); diff --git a/plugins/onepad/controller.h b/plugins/onepad/controller.h index 526ee291e0..ae1abab390 100644 --- a/plugins/onepad/controller.h +++ b/plugins/onepad/controller.h @@ -52,6 +52,7 @@ public: u32 log; map keysym_map[GAMEPAD_NUMBER]; std::array unique_id; + std::vector sdl2_mapping; PADconf() { init(); } @@ -64,6 +65,7 @@ public: keysym_map[pad].clear(); } unique_id.fill(0); + sdl2_mapping.clear(); } void set_joy_uid(u32 pad, size_t uid)