MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.06k stars 403 forks source link

Unable to deal with more than 2 controllers in a single sketch #236

Closed guillaumeparent closed 2 years ago

guillaumeparent commented 2 years ago

Description of Issue

As stated in the title, I am unable to create a sketch able to set more than 2 controllers. The discussion started in Mathiew's blog.

To summarize, I manage to create sketches dealing with 2 controllers, but as soon as I try to deal with more than 2 controllers only the 2 first ones are properly defined.

I attach in the following a minimal reproducible example attempting to define 4 controllers with 1 button each. As one can see on the attache picture, only the 2 first (0x10 and 0x11) controllers are properly detected. The 2 last ones (0x12 and 0x14) are not. The axis are recognized as buttons only.

Capture d’écran 2022-03-21 à 09 24 19

Technical Details

Sketch File that Reproduces Issue

#include <Joystick.h>

#define NbrGamePad 4

Joystick_ Joystick[NbrGamePad] = {
Joystick_(0x10, JOYSTICK_TYPE_GAMEPAD, 1, 0, true, true, false, false, false, false, false, false, false, false, false),
Joystick_(0x11, JOYSTICK_TYPE_GAMEPAD, 1, 0, true, true, false, false, false, false, false, false, false, false, false),
Joystick_(0x12, JOYSTICK_TYPE_GAMEPAD, 1, 0, true, true, false, false, false, false, false, false, false, false, false),
Joystick_(0x13, JOYSTICK_TYPE_GAMEPAD, 1, 0, true, true, false, false, false, false, false, false, false, false, false)
};

void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

Wiring Details

Any pin wiring details that may be relevant.

Additional context

Add any other context about the problem here.

MHeironimus commented 2 years ago

The sketch file above appears to work correctly on Windows 10. It may be a MacOS issue.

For example:

image

First Controller:

image

Fourth Controller:

image

The second and third look the same.

I know Linux machines need an adjustment to work correctly if more than one controller is defined (see https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/FAQ#linux-support for more details). Maybe there is something equivalent for the Mac.

guillaumeparent commented 2 years ago

It may be a MacOS issue

That's what I think too know I have confirmation my sketch works under Windows.

I know Linux machines need an adjustment to work correctly if more than one controller is defined

I saw that on your blog but I did not pay attention to it since my scrip works for 2 controller. I'll give it a try tho.

I'll try to compile my sketch under Windows and see if my full script works. Then i'll try to solve the problem under MacOS.

Thank you a lot for the help.

guillaumeparent commented 2 years ago

Ok, I found the problem. It was indeed the issue mentioned here. I tested the method on a Raspberry Pi (on which I experienced the same 2 controller limitation) and it worked. Now I can see 4 controllers.

Thank you for the help !