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

Change the device's serial ID #212

Open sonik-br opened 2 years ago

sonik-br commented 2 years ago

Describe your feature request Some systems differentiate arduino projects with same PID/VID by using the serial too. It's possible to edit the serial info per sketch without editing the IDE/SDK files.

@MickGyver have done it on some projects like this one: SegaTwoControllersUSB

I would love to have this feature implemented in this lib but I don't have the skill to do it.

MHeironimus commented 2 years ago

I think there is an explanation of how to do this at the end of the following video: https://www.youtube.com/watch?v=hoCOq9Ngp44 around 19:20.

sonik-br commented 2 years ago

Yeah that's one way to do it. But would be a good option to edit it from the sketch file without having to edit the arduino ide files.

I see that the lib creates a serial based on the descriptorSize. It is an elegant solution to differentiate sketches with different descriptors.

I changed it to a custom string inside the method DynamicHID_::getShortName(char *name). And it worked. Would like to have a way to set this custom string on the constructor of the joystick lib.

CDRXavier commented 2 years ago

I changed it to a custom string inside the method DynamicHID_::getShortName(char *name). And it worked. Would like to have a way to set this custom string on the constructor of the joystick lib.

The upside of the library is that it tried to avoid all the nasty bits of USB (by not including code for "Arduino core"), but the downside is that in this way, the Arduino you use still appear to the computer as a Arduino (and not, say, a "sonik-br" brand joystick). And the library is "unsightly", or incredibly garbled. I had tried to "start from scratch", but it just keep getting deep. Like, very deep. Deep enough that you can write USB code for a fresh 32U4 out of the factory (stuff written with Assembly).

sonik-br commented 2 years ago

The idea is not to change the "name" that appears on the OS. But to change the "serial" that goes along with the VID/PID. Currently it's generated based on the HID Descriptor Size. (see DynamicHID.cpp).

As there's a lot of joystick adapters using arduinos and they all share the same VID/PID, some projects (like the MiSTer) uses the serial to identify different arduino projects.