Skip to content

Commit 03341f2

Browse files
committed
Implement filterTrigger for PS3 controllers
The hid-sony driver has both analog and digital buttons for the triggers, and the analog values range from -32767 to 32767, which can cause two unwanted input events (digital button and negative axis) per press. Implement a function to filter out unwanted input events during configuration, but isolate detection to known PS3 controllers with 6 axes so that older versions of hid-sony and the sixad driver (which use 25+ axes) are not impacted negatively.
1 parent d8ae0ea commit 03341f2

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

es-core/src/InputManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ void InputManager::deinit()
171171
}
172172

173173
int InputManager::getNumJoysticks() { return (int)mJoysticks.size(); }
174+
175+
int InputManager::getAxisCountByDevice(SDL_JoystickID id)
176+
{
177+
return SDL_JoystickNumAxes(mJoysticks[id]);
178+
}
179+
174180
int InputManager::getButtonCountByDevice(SDL_JoystickID id)
175181
{
176182
if(id == DEVICE_KEYBOARD)

es-core/src/InputManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class InputManager
4848
void deinit();
4949

5050
int getNumJoysticks();
51+
int getAxisCountByDevice(int deviceId);
5152
int getButtonCountByDevice(int deviceId);
5253
int getNumConfiguredDevices();
5354

es-core/src/guis/GuiInputConfig.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
133133
return false;
134134
}
135135

136+
137+
// filter for input quirks specific to Sony DualShock 3
138+
if(filterTrigger(input, config))
139+
return false;
140+
136141
// we are configuring
137142
if(input.value != 0)
138143
{
@@ -331,3 +336,24 @@ void GuiInputConfig::clearAssignment(int inputId)
331336
{
332337
mTargetConfig->unmapInput(GUI_INPUT_CONFIG_LIST[inputId].name);
333338
}
339+
340+
bool GuiInputConfig::filterTrigger(Input input, InputConfig* config)
341+
{
342+
#if defined(__linux__)
343+
// match PlayStation joystick with 6 axes only
344+
if((strstr(config->getDeviceName().c_str(), "PLAYSTATION") != NULL \
345+
|| strstr(config->getDeviceName().c_str(), "PS3 Game") != NULL \
346+
|| strstr(config->getDeviceName().c_str(), "PS(R) Game") != NULL) \
347+
&& InputManager::getInstance()->getAxisCountByDevice(config->getDeviceId()) == 6)
348+
{
349+
// digital triggers are unwanted
350+
if (input.type == TYPE_BUTTON && (input.id == 6 || input.id == 7))
351+
return true;
352+
// ignore analog values < 0
353+
if (input.type == TYPE_AXIS && (input.id == 2 || input.id == 5) && input.value < 0)
354+
return true;
355+
}
356+
#endif
357+
358+
return false;
359+
}

es-core/src/guis/GuiInputConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class GuiInputConfig : public GuiComponent
2828

2929
bool assign(Input input, int inputId);
3030
void clearAssignment(int inputId);
31+
bool filterTrigger(Input input, InputConfig* config);
3132

3233
void rowDone();
3334

0 commit comments

Comments
 (0)