Skip to content

Commit

Permalink
USB: Fix FFB quality and dropouts for most wheels, make workaround op…
Browse files Browse the repository at this point in the history
…tional

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.
  • Loading branch information
badfontkeming authored and F0bes committed Oct 23, 2024
1 parent a044b7c commit f46f788
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
44 changes: 36 additions & 8 deletions pcsx2/USB/usb-pad/usb-pad-sdl-ff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 <typename T>
Expand Down
10 changes: 9 additions & 1 deletion pcsx2/USB/usb-pad/usb-pad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions pcsx2/USB/usb-pad/usb-pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f46f788

Please sign in to comment.