Skip to content

fix(hid-rp): a mouse is not a gamepad (looks_like_gamepad needs an absolute stick, hat or d-pad) - #967

Open
finger563 wants to merge 2 commits into
mainfrom
fix/hid-rp-gamepad-classification
Open

finger563 wants to merge 2 commits into
mainfrom
fix/hid-rp-gamepad-classification

Conversation

@finger563

Copy link
Copy Markdown
Contributor

What

GamepadDecoder::looks_like_gamepad() treated any Button-page field plus a Generic Desktop X / Y / hat / d-pad as a gamepad, without checking whether the axes were relative. Relative X / Y is pointer motion, so all of these classified as gamepads:

  • a plain HID boot mouse (it also classified as a mouse);
  • a keyboard with a built-in pointer (a touchpad or trackpoint on a second report ID);
  • a SpaceMouse (six relative axes plus buttons).

When decoded as a gamepad, a mouse's left click came out as South (A) and all of its motion was dropped.

Now only absolute direction fields count: a stick, a hat or a d-pad.

Who it affects

  • Pass-through bridges: code that checks looks_like_gamepad() alone to accept a device, as the gamepad_map example and README snippet do, accepted a mouse and treated it as a controller. Such a device is now rejected, and the bridge falls back to whatever it does for a non-gamepad.
  • Classifiers that check keyboard, then mouse, then gamepad (the Tab5 USB host example): no change for mice. The example still identifies a SpaceMouse by vendor ID first, because its descriptor now reads as a mouse. Its comment and README are updated to say so.
  • The HID Descriptor Inspector: the SpaceMouse preset now shows gamepad: false, mouse: true.

Keyboards were never affected: they have no Button-page fields.

Tests

hid_rp_report_map_host_test gets a new case, "classification":

  • every controller descriptor hid-rp ships (Xbox, DualSense, DualShock 4, Switch Pro) is a gamepad and nothing else;
  • a boot mouse, a SpaceMouse, a boot keyboard, and a keyboard plus pointer in one descriptor are not gamepads.

Under the old rule, the mouse, SpaceMouse and keyboard-plus-pointer checks fail (3 of 31 assertions); with the fix, all pass.

The inspector host test's SpaceMouse expectation is updated. All 40 host tests pass locally, and so does the inspector's headless-Chrome UI test (8 checks) after rebuilding its WebAssembly module.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

…solute stick, hat or d-pad)

GamepadDecoder::looks_like_gamepad() took any Button-page field plus a
Generic Desktop X / Y / hat / d-pad as a gamepad, without checking whether
the axes were relative. Relative X / Y is pointer motion, so a plain boot
mouse, a keyboard with a built-in pointer and a SpaceMouse all classified
as gamepads; decoded as one, a mouse's left click came out as South (A) and
its motion was dropped. Only absolute direction fields count now.

Keyboards were never affected (no Button-page fields). Tests: every hid-rp
controller descriptor (Xbox, DualSense, DualShock 4, Switch Pro) is still a
gamepad and only a gamepad; a boot mouse, a SpaceMouse, a boot keyboard and
a keyboard + pointer combo are not; the new checks fail under the old rule.
The Tab5 USB host example still recognises a SpaceMouse by vendor id first,
since its descriptor now reads as a mouse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Copilot AI balanced review requested due to automatic review settings December 2, 2026 05:08
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

This PR refines HID device classification so looks_like_gamepad() only treats absolute direction inputs (stick/hat/d-pad) as gamepad signals, preventing mice and other relative-axis devices from being misclassified as controllers.

Changes:

  • Update GamepadDecoder::looks_like_gamepad() to ignore relative X/Y (pointer motion) when deciding gamepad-ness.
  • Add/adjust host tests to validate classification across shipped controller descriptors plus mouse/keyboard/SpaceMouse cases.
  • Update example/inspector documentation/comments to reflect SpaceMouse now classifies as mouse, not gamepad.
File Description
components/​usb_host/​tab5_example/​main/​usb_host_tab5_example.cpp Updates SpaceMouse classification comment to reflect relative axes.
components/​usb_host/​tab5_example/​README.md Updates SpaceMouse note consistent with new classification.
components/​hid-rp/​test/​hid_rp_report_map_host_test.cpp Adds classification test coverage for controllers vs mouse/keyboard/SpaceMouse.
components/​hid-rp/​test/​hid_inspector_host_test.cpp Updates expected SpaceMouse classification JSON.
components/​hid-rp/​include/​hid-rp-report-map.hpp Implements the core classification change (!f.relative).

Review effort: Lite

This branch has not been deployed

No deployments
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.

2 participants