From 3d06fb02581d8994422eebc3205b980baa0fb405 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Wed, 27 May 2020 10:14:16 +0200 Subject: [PATCH] added analog input filtering in UI (fixes #578) --- Changes.txt | 2 ++ src/common/PJoystickHandler.cxx | 37 +++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Changes.txt b/Changes.txt index df70e30c0..681118cc5 100644 --- a/Changes.txt +++ b/Changes.txt @@ -33,6 +33,8 @@ * Added that mouse sensitivity for Driving controller can be adjusted + * Added paddle filtering in UI to avoid unwanted navigation events + * Added selectable dialog fonts * Added separate positioning of launcher, emulator and debugger diff --git a/src/common/PJoystickHandler.cxx b/src/common/PJoystickHandler.cxx index 3b2452798..1af10feac 100644 --- a/src/common/PJoystickHandler.cxx +++ b/src/common/PJoystickHandler.cxx @@ -687,27 +687,32 @@ void PhysicalJoystickHandler::handleAxisEvent(int stick, int axis, int value) } j->axisLastValue[axis] = value; } + #ifdef GUI_SUPPORT else if(myHandler.hasOverlay()) { - // First, clamp the values to simulate digital input - // (the only thing that the underlying code understands) - if(value > Joystick::deadzone()) - value = 32000; - else if(value < -Joystick::deadzone()) - value = -32000; - else - value = 0; - - // Now filter out consecutive, similar values - // (only pass on the event if the state has changed) - if(value != j->axisLastValue[axis]) + // A value change lower than Joystick::deadzone indicates analog input which is ignored + if((abs(j->axisLastValue[axis] - value) > Joystick::deadzone())) { -#ifdef GUI_SUPPORT - myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), convertAxisValue(value), button); -#endif - j->axisLastValue[axis] = value; + // First, clamp the values to simulate digital input + // (the only thing that the underlying code understands) + if(value > Joystick::deadzone()) + value = 32000; + else if(value < -Joystick::deadzone()) + value = -32000; + else + value = 0; + + // Now filter out consecutive, similar values + // (only pass on the event if the state has changed) + if(value != j->axisLastValue[axis]) + { + myHandler.overlay().handleJoyAxisEvent(stick, JoyAxis(axis), convertAxisValue(value), button); + + } } + j->axisLastValue[axis] = value; } + #endif } }