From f46f788d803ac50944d2a114deb5434a1a1da963 Mon Sep 17 00:00:00 2001 From: badfontkeming <107527585+badfontkeming@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:44:55 -0500 Subject: [PATCH] USB: Fix FFB quality and dropouts for most wheels, make workaround optional The original workaround for FFB issues simply restarted the constant force each time it was updated. Turns out that a lot of wheels don't behave perfectly during this. A better fix was found, which is to set the effect duration to infinite. However, some wheels are so bugged that they don't even respect THAT, so the workaround needs to stick around in some capacity. --- pcsx2/USB/usb-pad/usb-pad-sdl-ff.cpp | 44 +++++++++++++++++++++++----- pcsx2/USB/usb-pad/usb-pad.cpp | 10 ++++++- pcsx2/USB/usb-pad/usb-pad.h | 2 ++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/pcsx2/USB/usb-pad/usb-pad-sdl-ff.cpp b/pcsx2/USB/usb-pad/usb-pad-sdl-ff.cpp index 529d8a7af5..8d14f21be6 100644 --- a/pcsx2/USB/usb-pad/usb-pad-sdl-ff.cpp +++ b/pcsx2/USB/usb-pad/usb-pad-sdl-ff.cpp @@ -59,7 +59,23 @@ namespace usb_pad void SDLFFDevice::CreateEffects(const std::string_view device) { - constexpr u32 length = 10000; // 10 seconds since NFS games seem to not issue new commands while rotating. + // Most games appear to assume that requested forces will be applied indefinitely. + // Gran Turismo 4 uses a single indefinite spring(?) force to center the wheel in menus, + // and both GT4 and the NFS games have been observed using only a single constant force + // command over long, consistent turns on smooth roads. + // + // An infinite force is necessary as the normal mechanism for looping FFB effects, + // the iteration count, isn't implemented by a large number of new wheels. This deficiency + // exists at a firmware level and can only be dealt with by manually restarting forces. + // + // Manually restarting forces causes problems on some wheels, however, so infinite forces + // are preferred for the vast majority of wheels which do correctly handle them. + // + // Known "Problem" wheels which don't implement effect iterations + // - Moza series: DOES implement infinite durations + // - Accuforce v2: DOES implement infinite durations (deduced from anecdote, not confirmed manually) + // - Simagic Alpha Mini: Does NOT implement infinite durations (stops after some time, seeking hard numbers) + constexpr u32 length = SDL_HAPTIC_INFINITY; const unsigned int supported = SDL_HapticQuery(m_haptic); if (supported & SDL_HAPTIC_CONSTANT) @@ -187,13 +203,25 @@ namespace usb_pad Console.Warning("SDL_HapticUpdateEffect() for constant failed: %s", SDL_GetError()); } - // Always 'run' the constant force effect, even when already running. This - // mitigates FFB timeout issues experienced by some modern direct-drive - // wheels, such as Moza R5, R9, etc... - if (SDL_HapticRunEffect(m_haptic, m_constant_effect_id, SDL_HAPTIC_INFINITY) == 0) - m_constant_effect_running = true; - else - Console.Error("SDL_HapticRunEffect() for constant failed: %s", SDL_GetError()); + // Avoid re-running already-running effects by default. Re-running a running effect + // causes a variety of issues on different wheels, ranging from quality/detail loss, + // to abrupt judders of the wheel's FFB rapidly cutting out and back in. + // + // Known problem wheels: + // Most common (Moza, Simagic, likely others): Loss of definition or quality + // Accuforce v2: Split-second FFB drop with each update + // + // Wheels that need it anyway: + // Simagic Alpha Mini: It doesn't properly handle infinite durations, leaving you to choose + // between fuzzy/vague FFB, or FFB that may cut out occasionally. + // This is the reason for use_ffb_dropout_workaround. + if (!m_constant_effect_running || use_ffb_dropout_workaround) + { + if (SDL_HapticRunEffect(m_haptic, m_constant_effect_id, SDL_HAPTIC_INFINITY) == 0) + m_constant_effect_running = true; + else + Console.Error("SDL_HapticRunEffect() for constant failed: %s", SDL_GetError()); + } } template diff --git a/pcsx2/USB/usb-pad/usb-pad.cpp b/pcsx2/USB/usb-pad/usb-pad.cpp index 10b25a4b99..345ecfbd7f 100644 --- a/pcsx2/USB/usb-pad/usb-pad.cpp +++ b/pcsx2/USB/usb-pad/usb-pad.cpp @@ -163,7 +163,10 @@ namespace usb_pad "0", "0", "100", "1", TRANSLATE_NOOP("USB", "%d%%"), nullptr, nullptr, 1.0f}, {SettingInfo::Type::StringList, "SteeringCurveExponent", TRANSLATE_NOOP("USB", "Steering Damping"), TRANSLATE_NOOP("USB", "Applies power curve filter to steering axis values. Dampens small inputs."), - "Off", nullptr, nullptr, nullptr, nullptr, SteeringCurveExponentOptions} + "Off", nullptr, nullptr, nullptr, nullptr, SteeringCurveExponentOptions}, + {SettingInfo::Type::Boolean, "FfbDropoutWorkaround", TRANSLATE_NOOP("USB", "Workaround for Intermittent FFB Loss"), + TRANSLATE_NOOP("USB", "Works around bugs in some wheels' firmware that result in brief interruptions in force. Leave this disabled unless you need it, as it has negative side effects on many wheels."), + "false"} }; return info; @@ -226,6 +229,11 @@ namespace usb_pad mFFdevName = std::move(ffdevname); OpenFFDevice(); } + if (mFFdev != NULL) + { + const bool use_ffb_dropout_workaround = USB::GetConfigBool(si, port, devname, "FfbDropoutWorkaround", false); + mFFdev->use_ffb_dropout_workaround = use_ffb_dropout_workaround; + } } } diff --git a/pcsx2/USB/usb-pad/usb-pad.h b/pcsx2/USB/usb-pad/usb-pad.h index d57e69b7fb..4a8da1f21a 100644 --- a/pcsx2/USB/usb-pad/usb-pad.h +++ b/pcsx2/USB/usb-pad/usb-pad.h @@ -287,6 +287,8 @@ namespace usb_pad virtual void SetAutoCenter(int value) = 0; //virtual void SetGain(int gain) = 0; virtual void DisableForce(EffectID force) = 0; + + bool use_ffb_dropout_workaround = false; }; struct PadState