Skip to content

Commit

Permalink
onepad: allow to save/reload SDL2 mapping from OnePAD2.ini file
Browse files Browse the repository at this point in the history
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,
  • Loading branch information
gregory38 committed May 3, 2017
1 parent 03899a6 commit 36528bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions plugins/onepad/Linux/ini.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();

Expand Down
10 changes: 6 additions & 4 deletions plugins/onepad/SDL/joystick.cpp
Expand Up @@ -57,11 +57,13 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
// SDL forget to add const for SDL_RWFromMem API...
void *data = const_cast<void *>(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());
}
}

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions plugins/onepad/controller.h
Expand Up @@ -52,6 +52,7 @@ class PADconf
u32 log;
map<u32, u32> keysym_map[GAMEPAD_NUMBER];
std::array<size_t, GAMEPAD_NUMBER> unique_id;
std::vector<std::string> sdl2_mapping;

PADconf() { init(); }

Expand All @@ -64,6 +65,7 @@ class PADconf
keysym_map[pad].clear();
}
unique_id.fill(0);
sdl2_mapping.clear();
}

void set_joy_uid(u32 pad, size_t uid)
Expand Down

0 comments on commit 36528bb

Please sign in to comment.