Skip to content

Commit

Permalink
Merge pull request #554 from psyke83/ps3_triggerfilter
Browse files Browse the repository at this point in the history
Implement filterTrigger for PS3 controllers
  • Loading branch information
joolswills authored Apr 9, 2019
2 parents 91d0b6c + 03341f2 commit fd04b15
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions es-core/src/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions es-core/src/InputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class InputManager
void deinit();

int getNumJoysticks();
int getAxisCountByDevice(int deviceId);
int getButtonCountByDevice(int deviceId);
int getNumConfiguredDevices();

Expand Down
26 changes: 26 additions & 0 deletions es-core/src/guis/GuiInputConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions es-core/src/guis/GuiInputConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GuiInputConfig : public GuiComponent

bool assign(Input input, int inputId);
void clearAssignment(int inputId);
bool filterTrigger(Input input, InputConfig* config);

void rowDone();

Expand Down

0 comments on commit fd04b15

Please sign in to comment.