Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Improve evdev heuristic #7599

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

smcv
Copy link
Contributor

@smcv smcv commented Apr 11, 2023

Description

  • evdev: Guess that devices with a driving controller axis are joysticks

    This fixes the classification of the "Vitaly [mega_mozg] Naidentsev
    ODDOR-handbrake" in our test data, which originally came from
    USB joystick device (pedals) works via wine and proton, but not when run via Steam client ValveSoftware/Proton#5126.

  • evdev: Note ambiguity of having only [R]XYZ axes

    Some sets of 3 pedals for driving simulators are known to report as
    either X, Y, Z, which is indistinguishable from an accelerometer
    (unless we assume a kernel and driver that report
    INPUT_PROP_ACCELEROMETER, which at least the various Wiimote devices do
    not) or RX, RY, RZ, which is indistinguishable from a gyro (again, unless
    we assume we can use INPUT_PROP_ACCELEROMETER to distinguish).

    This could perhaps be solved by parsing HID descriptors, but that would
    be out of scope for a heuristic based on evdev properties.

  • evdev: Guess devices with game-related buttons are joysticks

    This seems a reasonable assumption to make, and in particular is enough
    to detect the Wii Balance Board and Wii Nunchuck as game controllers.
    The Wiimote and Wii Classic Controller are still detected as keyboards,
    because they have a mixture of gaming and keyboard buttons, and we
    currently prioritize "is a keyboard" as more convincing than "is a
    gamepad".

  • joystick: Add device IDs for some known simulation controllers

    Helps: Rudder pedals "CH Pro Pedals" incorrectly detected as accelerometer on Linux without udev #7500
    Co-authored-by: Felix Hädicke

  • udev: Factor out a function to get an input device's product info

  • udev: Extend input_dev_get_product_info to get the bus type

  • linux: Pass bus/vendor/product/version tuple when guessing device type

    Helps: Rudder pedals "CH Pro Pedals" incorrectly detected as accelerometer on Linux without udev #7500

  • linux: Have a table of known joysticks

    These simulation control devices are known to be joysticks, but don't
    all have enough information in their evdev capabilities for us to be
    able to distinguish them from an accelerometer by capabilities alone.
    If we look at the bus type, vendor ID and product ID as well, then
    that gives us enough information to distinguish.

    Resolves: Rudder pedals "CH Pro Pedals" incorrectly detected as accelerometer on Linux without udev #7500
    Co-authored-by: Felix Hädicke

Existing Issue(s)

Fixes #7500

/* If it has a driving/flight simulation axis (THROTTLE, RUDDER, WHEEL,
* GAS, BRAKE) then it's probably a game or simulation controller */
if (test_bit(EV_ABS, bitmask_ev)) {
for (i = ABS_THROTTLE; i <= ABS_BRAKE; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggests another possible way to deal with flight and driving sim controllers: give them appropriate quirks in the kernel to get their HID axes reported according to evdev conventions (for example flight sim rudder pedals as ABS_RUDDER). I don't know enough about the kernel's HID to evdev mapping to know how feasible that is.

static const struct input_id known_joysticks[] = {
{ BUS_USB, USB_VENDOR_CH_PRODUCTS, USB_PRODUCT_CH_PRO_PEDALS }, /* https://github.com/libsdl-org/SDL/issues/7500 */
{ BUS_USB, USB_VENDOR_HEUSINKVELD, USB_PRODUCT_HEUSINKVELD_SIM_PEDALS_ULTIMATE }, /* https://github.com/ValveSoftware/Proton/issues/5126 */
{ BUS_USB, USB_VENDOR_LEO_BODNAR, USB_PRODUCT_LEO_BODNAR_LOGITECH_G25_PEDALS }, /* https://github.com/ValveSoftware/Proton/issues/5126 */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be https://www.leobodnar.com/shop/index.php?main_page=product_info&products_id=187, a third-party serial-to-USB adapter to connect Logitech G25 pedals (only) as a separate game controller, so USB_PRODUCT_LEO_BODNAR_G25_PEDAL_ADAPTER might be a better name for it.

{ BUS_USB, USB_VENDOR_CH_PRODUCTS, USB_PRODUCT_CH_PRO_PEDALS }, /* https://github.com/libsdl-org/SDL/issues/7500 */
{ BUS_USB, USB_VENDOR_HEUSINKVELD, USB_PRODUCT_HEUSINKVELD_SIM_PEDALS_ULTIMATE }, /* https://github.com/ValveSoftware/Proton/issues/5126 */
{ BUS_USB, USB_VENDOR_LEO_BODNAR, USB_PRODUCT_LEO_BODNAR_LOGITECH_G25_PEDALS }, /* https://github.com/ValveSoftware/Proton/issues/5126 */
{ BUS_USB, USB_VENDOR_STMICRO, USB_PRODUCT_STMICRO_VRS_DIRECTFORCE_PRO_PEDALS }, /* https://github.com/ValveSoftware/Proton/issues/5126 */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be https://virtualracingschool.com/dfpro-pedals/, presumably borrowing ST Microelectronics' vendor ID.

@@ -46,6 +49,7 @@
#define USB_VENDOR_SHANWAN 0x2563
#define USB_VENDOR_SHANWAN_ALT 0x20bc
#define USB_VENDOR_SONY 0x054c
#define USB_VENDOR_STMICRO 0x0483
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or USB_VENDOR_ST or USB_VENDOR_STMICROELECTRONICS? Is there a policy for how we abbreviate vendors?

@smcv
Copy link
Contributor Author

smcv commented Apr 11, 2023

Do SDL maintainers think this is a good design for how we overrule the heuristic for which game controller is which?

I don't know whether this is sufficient to make these devices behave as requested on ValveSoftware/Proton#5126.

@slouken
Copy link
Collaborator

slouken commented Aug 6, 2024

Is there anything left to move this out of draft status?

@smcv
Copy link
Contributor Author

smcv commented Aug 6, 2024

Is there anything left to move this out of draft status?

Honestly, I don't remember making this change, or whether some of it already got applied elsewhere.

I have never had the necessary hardware to test this "in real life", so all I can do is to try to gather the necessary information to fake these devices in test/testevdev.c (I've lost track of whether we ever got that info from the submitter of #7500 or not), and test via that.

@smcv
Copy link
Contributor Author

smcv commented Aug 6, 2024

Looking back at the history, I think the reason this was draft is that I asked

Do SDL maintainers think this is a good design for how we overrule the heuristic for which game controller is which?

and didn't see an answer.

@slouken
Copy link
Collaborator

slouken commented Aug 6, 2024

Looking back at the history, I think the reason this was draft is that I asked

Do SDL maintainers think this is a good design for how we overrule the heuristic for which game controller is which?

and didn't see an answer.

Yes, I think this is fine. I don't have these devices either, so I'm not sure how best to verify this. Do we know which devices are mis-detected by udev at this point?

@smcv
Copy link
Contributor Author

smcv commented Aug 6, 2024

Do we know which devices are mis-detected by udev at this point?

This isn't about whether devices are mis-detected by udev, so much as whether devices are mis-detected in situations where we can't use udev (notably Steam Linux Runtime containers).

For now, I've done a quick rebase of this branch onto current SDL3. I think it's approximately right, but I haven't tested it at all (not even with gamepads). Good enough for a preliminary review, perhaps?

Sorry, I'm not a SDL core developer and spend most of my time working on not-SDL, so my ability to come back to a change after a year and a bit and remember how I was intending it to work is fairly limited. If this functionality is seen as important, perhaps someone a bit closer to SDL could pick it up?

smcv and others added 8 commits August 6, 2024 17:50
This fixes the classification of the "Vitaly [mega_mozg] Naidentsev
ODDOR-handbrake" in our test data, which originally came from
<ValveSoftware/Proton#5126>.

Signed-off-by: Simon McVittie <[email protected]>
Some sets of 3 pedals for driving simulators are known to report as
either X, Y, Z, which is indistinguishable from an accelerometer
(unless we assume a kernel and driver that report
INPUT_PROP_ACCELEROMETER, which at least the various Wiimote devices do
not) or RX, RY, RZ, which is indistinguishable from a gyro (again, unless
we assume we can use INPUT_PROP_ACCELEROMETER to distinguish).

This could perhaps be solved by parsing HID descriptors, but that would
be out of scope for a heuristic based on evdev properties.

Signed-off-by: Simon McVittie <[email protected]>
This seems a reasonable assumption to make, and in particular is enough
to detect the Wii Balance Board and Wii Nunchuck as game controllers.
The Wiimote and Wii Classic Controller are still detected as keyboards,
because they have a mixture of gaming and keyboard buttons, and we
currently prioritize "is a keyboard" as more convincing than "is a
gamepad".

Signed-off-by: Simon McVittie <[email protected]>
These simulation control devices are known to be joysticks, but don't
all have enough information in their evdev capabilities for us to be
able to distinguish them from an accelerometer by capabilities alone.
If we look at the bus type, vendor ID and product ID as well, then
that gives us enough information to distinguish.

Resolves: libsdl-org#7500
Co-authored-by: Felix Hädicke <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rudder pedals "CH Pro Pedals" incorrectly detected as accelerometer on Linux without udev
2 participants