Merge pull request #554 from psyke83/ps3_triggerfilter

Implement filterTrigger for PS3 controllers
This commit is contained in:
Jools Wills 2019-04-09 05:13:23 +01:00 committed by GitHub
commit fd04b153af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 0 deletions

View file

@ -172,6 +172,12 @@ void InputManager::deinit()
}
int InputManager::getNumJoysticks() { return (int)mJoysticks.size(); }
int InputManager::getAxisCountByDevice(SDL_JoystickID id)
{
return SDL_JoystickNumAxes(mJoysticks[id]);
}
int InputManager::getButtonCountByDevice(SDL_JoystickID id)
{
if(id == DEVICE_KEYBOARD)

View file

@ -48,6 +48,7 @@ public:
void deinit();
int getNumJoysticks();
int getAxisCountByDevice(int deviceId);
int getButtonCountByDevice(int deviceId);
int getNumConfiguredDevices();

View file

@ -133,6 +133,11 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
return false;
}
// filter for input quirks specific to Sony DualShock 3
if(filterTrigger(input, config))
return false;
// we are configuring
if(input.value != 0)
{
@ -331,3 +336,24 @@ void GuiInputConfig::clearAssignment(int inputId)
{
mTargetConfig->unmapInput(GUI_INPUT_CONFIG_LIST[inputId].name);
}
bool GuiInputConfig::filterTrigger(Input input, InputConfig* config)
{
#if defined(__linux__)
// match PlayStation joystick with 6 axes only
if((strstr(config->getDeviceName().c_str(), "PLAYSTATION") != NULL \
|| strstr(config->getDeviceName().c_str(), "PS3 Game") != NULL \
|| strstr(config->getDeviceName().c_str(), "PS(R) Game") != NULL) \
&& InputManager::getInstance()->getAxisCountByDevice(config->getDeviceId()) == 6)
{
// digital triggers are unwanted
if (input.type == TYPE_BUTTON && (input.id == 6 || input.id == 7))
return true;
// ignore analog values < 0
if (input.type == TYPE_AXIS && (input.id == 2 || input.id == 5) && input.value < 0)
return true;
}
#endif
return false;
}

View file

@ -28,6 +28,7 @@ private:
bool assign(Input input, int inputId);
void clearAssignment(int inputId);
bool filterTrigger(Input input, InputConfig* config);
void rowDone();