Hi scorp!! First of all, I want to thank you for this great project.
I recently got a second hand Logitech ThunderPad Digital, as this was the first controller I used on my childhood PC. I first tested it on several retro rigs, with varing results, as I suspect that the original Logitech drivers don't work on fast CPUs or integrated gameports, as it worked fine on a AMD K6-2 with an ISA Sound Blaster, but on a Pentium 4 with integrated gameport, the operating system completely freezes when loading the driver.
Anyway, soon after, I started thinking on making an USB adapter for this gamepad, and when looking for documentation on the protocol used by these devices, I found your GitHub repo. I assembled the adapter but, sadly, it didn't work at all. Luckily, as you code is nicely written and documented, I was able to quickly debug and fix the issues preventing this gamepad from working.
I'm going to add a Pull Request to your GitHub repo but, just in case you don't like the way I coded the changes, or you want to address the issues in a completely different way, I leave here details of the issues:
- The first issue is that the controller is not initialized at all. Enabling the debug output reveals the following error: "Meta data package size mismatch, expected 128 but got 146" (the numbers are reversed, I think, but this is irrelevant). I initially thought it must be some kind of stupid bug in the gamepad's firmware, but then I saw you defined the packet buffer to have 128 elements, so I increased it to 255 and the gamepad was correctly detected.
- This controller defines itself as having 12 buttons an 0 axes. While this is not strictly an issue, I feel that considering up, down, left and right as buttons and not as axes is very inconvenient. I wrote two code blocks that are executed only if the device name is "ThunderPad". The first block, on the init() function, manually redefines the gamepad layout to have 2 axes and 8 buttons. The second block, on the update() function, manually remaps up, down, left and right buttons to X and Y axes.
- The third issue was a bit more subtle. After making all the modifications I realised that if I disconnect and reconnect the USB, the gamepad doesn't work at all, but if I reflash the firmware from the Arduino IDE, without making any changes, it starts working again. On another words, it only works if the Arduino is rebooted after powering the adapter, otherwise the gamepad seems to ignore the enableDigitalMode command and remains in analog mode. I assumed this is because the microcontroller on the gamepad takes a while to initialize, and the enableDigitalMode comes too early. I inserted a 100ms delay in the Setup() function an the problem got fixed. Bigger delays start to cause problems with the USB initialization. There seems to be a time frame within the custom USB descriptor must be defined, otherwise the USB behaves only as a COM port. I suppose this has to do with the way the bootloader or the Arduino IDE code handles the USB initialization. Anyway, 100ms seems to be enough and safe.
If you want to implent this in another way, I would be pleased to help you testing the code. I think it would be nice to add the ThunderPad to the supported list of controllers. After making these changes, I completed several Metal Slugs without any single issue, so it seems pretty solid.
Thanks again for your work.