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,
This commit is contained in:
Gregory Hainaut 2017-05-03 11:47:16 +02:00
parent 03899a6240
commit 36528bb723
3 changed files with 15 additions and 4 deletions

View File

@ -100,6 +100,9 @@ void SaveConfig()
for (auto const &it : conf->keysym_map[pad]) for (auto const &it : conf->keysym_map[pad])
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second); 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); fclose(f);
} }
@ -149,6 +152,10 @@ void LoadConfig()
have_user_setting = true; 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) if (!have_user_setting)
DefaultKeyboardValues(); DefaultKeyboardValues();

View File

@ -57,11 +57,13 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
// SDL forget to add const for SDL_RWFromMem API... // SDL forget to add const for SDL_RWFromMem API...
void *data = const_cast<void *>(g_bytes_get_data(bytes, &size)); void *data = const_cast<void *>(g_bytes_get_data(bytes, &size));
int map = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(data, size), 1); SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(data, size), 1);
fprintf(stdout, "onepad: load %d extra joystick map\n", map);
g_bytes_unref(bytes); 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) { if (m_controller == nullptr) {
fprintf(stderr, "onepad: Joystick (%s,GUID:%s) isn't yet supported by the SDL2 game controller API\n" 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" "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.", "Please report it to us (https://github.com/PCSX2/pcsx2/issues) so we can add your joystick to our internal database.",
devname, guid); devname, guid);

View File

@ -52,6 +52,7 @@ public:
u32 log; u32 log;
map<u32, u32> keysym_map[GAMEPAD_NUMBER]; map<u32, u32> keysym_map[GAMEPAD_NUMBER];
std::array<size_t, GAMEPAD_NUMBER> unique_id; std::array<size_t, GAMEPAD_NUMBER> unique_id;
std::vector<std::string> sdl2_mapping;
PADconf() { init(); } PADconf() { init(); }
@ -64,6 +65,7 @@ public:
keysym_map[pad].clear(); keysym_map[pad].clear();
} }
unique_id.fill(0); unique_id.fill(0);
sdl2_mapping.clear();
} }
void set_joy_uid(u32 pad, size_t uid) void set_joy_uid(u32 pad, size_t uid)