Skip to content

Using SingleGamepad causes multiple controllers to show on Windows #461

@Blocker226

Description

@Blocker226

Hi, not sure if this project is still actively maintained but, I've found an issue when using the Single-Reporting version of the Game pad API.

When connecting an Arduino Pro Micro using Gamepad1::begin(), it will register as 3 controllers, each one labelled "Arduino Micro" in the Windows 10 "Set Up USB Game Controllers" panel.

Findings and Recommendation

In SingleGamepad.cpp, the declaration of each individual SingleGamepad_ instance causes them to be constructed, and when each one is constructed, they call PluggableUSB().plug(this);, which causes them to register as devices, up to the limit of the MCU or until all 4 controllers are "connected". This, of course, does not make sense if I only want to program the MCU as one gamepad instance. Removing the other declarations of SingleGamepad_ fixes the issue.

See here:
https://github.com/NicoHood/HID/blob/b16be57caef4295c6cd382a7e4c64db5073647f7/src/SingleReport/SingleGamepad.cpp#L150C1-L152C25

One way to fix this, I believe, is to override the begin() function in GamepadAPI to make the call to plug the gamepad instance into the system for any SingleGamepad_ instance.

Another way, which, IMO, might be better, is to remove the pre-declared instances entirely and allow users to declare their own SingleGamepad_ instance in their source file. This goes against the rest of the library's workings, but I think this brings it more in line with the way other libraries expect their users to construct class instances through variable declaration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions