d3xMachina / BetterJoy

Allows the Nintendo Switch Pro Controller, Joycons and SNES controller to be used with CEMU, Citra, Dolphin, Yuzu and as generic XInput
Other
79 stars 6 forks source link

[BUG] Pro Controller sometimes doesn't connect on first try #19

Closed PizzaPino closed 5 months ago

PizzaPino commented 5 months ago

Describe the bug Opening a new issue since this is another problem compared to the other ticket. Pro Controller most of the time disconnects after pairing on the first try after 2 seconds. Usually disconnecting and reconnecting (without re-pairing in the Windows settings) makes it work again.

Expected behavior A clear and concise description of what you expected to happen.

Controller:

I used the newest commit you offered in #18 but the problem still persists even though I reinstalled ViGEm twice now.

Here's the log:

[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Response ID 21. Data: 16 40 00 00 00 18 18 7C 04 38 7B 00 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Using Bluetooth.
[P1] Retrieve user left stick calibration data.
[P1] Retrieve user right stick calibration data.
[P1] Retrieve user sensors calibration data.
[P1] Subcommand 38 sent. Data: 18 01 10 FF FF 
[P1] Response ID 21. Data: 3B 40 00 00 00 18 38 7C 04 58 7B 00 80 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 30 sent. Data: 01 
[P1] Response ID 21. Data: 41 40 00 00 00 19 28 7C 04 58 7B 00 80 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 40 sent. Data: 01 
[P1] Response ID 21. Data: 47 40 00 00 00 19 28 7C 02 58 7B 00 80 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 48 sent. Data: 01 
[P1] Response ID 21. Data: 4D 40 00 00 00 19 38 7C 05 58 7B 00 80 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 03 sent. Data: 30 
[P1] Response ID 21. Data: 53 40 00 00 00 18 38 7C 02 68 7B 09 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Done with init.
[P1] Could not connect (Der Vorgang wurde erfolgreich beendet.).
d3xMachina commented 5 months ago

I've reverted a commit I suspect might be the culprit since you said it worked in 8.4.0. I changed the connection to ViGEm to be before trying to connect the controller since there might be some timing problem involved here or conflict between hidapi and vigem. I also added handling for more exceptions messages in vigem :

BetterJoy.zip

PizzaPino commented 5 months ago

I'm getting a slightly different error now instead once in a while.

[P1] Pro controller connected.
[P1] Connect virtual xbox controller.
[P1] Could not connect (Der Vorgang wurde erfolgreich beendet.).

Also the syncing lights at the bottom of the controller keep blinking from left to right and back now. That didn't happen before. Before it was a disconnect without any lights blinking.

d3xMachina commented 5 months ago

My last build was messed up, it used the cached package instead of the modified one... Here is the (hopefully correctly) updated one : BetterJoy.zip

About the light, it's normal since it tries to connect the virtual controller before the actual controller with the change I made. The same happens if BetterJoy is not opened and you press buttons.

PizzaPino commented 5 months ago

Ok thanks, now it's giving me this:

[P1] Pro controller connected.
[P1] Connect virtual xbox controller.
[P1] Could not connect (Exception of type 'Nefarius.ViGEm.Client.Exceptions.VigemTargetNotPluggedInException' was thrown.).

On successful pairing it's giving me this:

[P1] Pro controller connected.
[P1] Connect virtual xbox controller.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Response ID 21. Data: 18 40 00 00 00 6E 78 7C EA 37 7B 0F 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Using Bluetooth.
[P1] Retrieve user left stick calibration data.
[P1] Retrieve user right stick calibration data.
[P1] Retrieve user sensors calibration data.
[P1] Subcommand 38 sent. Data: 18 01 10 FF FF 
[P1] Response ID 21. Data: 3D 40 00 00 00 6F 68 7C EC 57 7B 00 80 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 30 sent. Data: 01 
[P1] Response ID 21. Data: 43 40 00 00 00 6E 68 7C EA 67 7B 00 80 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 40 sent. Data: 01 
[P1] Response ID 21. Data: 49 40 00 00 00 6F 48 7C EA 47 7B 00 80 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 48 sent. Data: 01 
[P1] Response ID 21. Data: 4F 40 00 00 00 6F 58 7C EA 57 7B 00 80 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 03 sent. Data: 30 
[P1] Response ID 21. Data: 55 40 00 00 00 70 68 7C EC 47 7B 09 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Done with init.
[P1] Using user sticks calibration.
[P1] Using user sensors calibration.
[P1] Ready.
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
d3xMachina commented 5 months ago

I saw there was someone having this exact same issue very recently (few days ago) on the discord of the author of ViGEm and a fix for it. Here is BetterJoy with the fix to the ViGEm client, hopefully it works for you too : BetterJoy.zip

PizzaPino commented 5 months ago

now it's back to this:

[P1] Pro controller connected.
[P1] Connect virtual xbox controller.
[P1] Could not connect (Der Vorgang wurde erfolgreich beendet.).

FYI what I just noticed, instead of resyncing I can just close and open up BetterJoy again, that works as well.

d3xMachina commented 5 months ago

Flags were missing in the ViGEm code to actually get the proper error from the WinAPI. Try this it should show the error reported by Windows : BetterJoy.zip

If it still show the error "Der Vorgang wurde erfolgreich beendet" then I have no idea. Also you told me you didn't have the issue with the 8.4 version so it would be nice to test if it's still the case or if it was unrelated.

Note to myself, for future reference : it fails at GetOverlappedResult here

PizzaPino commented 5 months ago

Yes 8.4 connects my controller every time. But I noticed that once in a while it has trouble connecting it on the first try so it disconnects but then immediately connects it again.

8.4 with HidHide_1.4.192_x64

Unable to add program to whitelist.
Starting server on 127.0.0.1:26760.
All systems go
Pro controller connected.
Could not connect Pro controller (Der Vorgang wurde erfolgreich beendet.). Dropped.
Pro controller disconnected.
Pro controller connected.
[P1] Subcommand 0x03 sent. Data: 0x3F 
[P1] Rumble data Received: XInput
[P1] Rumble data Received: XInput
[P1] No response.
[P1] Rumble data Received: XInput
[P1] Using Bluetooth.
[P1] No response.
[P1] Using user left stick calibration data.
[P1] left stick 1 calibration data: 1509 1689 2136 1966 1603 1585 
[P1] Using user right stick calibration data.
[P1] right stick calibration data: 1576 1654 2051 1949 1539 1592 
[P1] Using user sensors calibration data.
[P1] Gyro neutral position: -13 -39 -51 
[P1] Subcommand 0x38 sent. Data: 0x18 01 10 FF FF 
[P1] Response ID 0x21. Data: 0x2F 20 00 00 00 48 A8 7B 06 48 7B 0C 80 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x30 sent. Data: 0x01 
[P1] Response ID 0x21. Data: 0x35 20 00 00 00 49 98 7B 05 38 7B 09 80 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x40 sent. Data: 0x01 
[P1] Response ID 0x21. Data: 0x3B 20 00 00 00 48 B8 7B 05 48 7B 09 80 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x48 sent. Data: 0x01 
[P1] Response ID 0x21. Data: 0x41 20 00 00 00 49 A8 7B 05 58 7B 09 80 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x03 sent. Data: 0x30 
[P1] Response ID 0x21. Data: 0x47 20 00 00 00 49 A8 7B 05 58 7B 0A 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Done with init.
[P1] Starting poll thread.
[P1] Subcommand 0x38 sent. Data: 0x0F 1F 10 11 FF 
[P1] Rumble data sent: 10 0D 00 01 40 40 00 01 40 40 
[P1] Rumble data Received: XInput
[P1] Rumble data sent: 10 0E 00 01 40 40 00 01 40 40 
[P1] Rumble data Received: XInput
[P1] Rumble data sent: 10 0F 00 01 40 40 00 01 40 40 
[P1] Subcommand 0x38 sent. Data: 0x0F 1F 10 11 FF 

This is 8.4 without errors.

HIDHide is enabled.
Starting server on 127.0.0.1:26760.
All systems go
Pro controller connected.
[P1] Subcommand 0x03 sent. Data: 0x3F 
[P1] Rumble data Received: XInput
[P1] Rumble data Received: XInput
[P1] Rumble data Received: XInput
[P1] Response ID 0x21. Data: 0xA1 20 00 00 00 49 C8 7A E9 57 7B 0A 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Using Bluetooth.
[P1] Using user left stick calibration data.
[P1] left stick 1 calibration data: 1509 1689 2136 1966 1603 1585 
[P1] Using user right stick calibration data.
[P1] right stick calibration data: 1576 1654 2051 1949 1539 1592 
[P1] Using user sensors calibration data.
[P1] Gyro neutral position: -13 -39 -51 
[P1] Subcommand 0x38 sent. Data: 0x18 01 10 FF FF 
[P1] Response ID 0x21. Data: 0xC5 20 00 00 00 4B B8 7A E7 47 7B 0C 80 38 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x30 sent. Data: 0x01 
[P1] Response ID 0x21. Data: 0xCB 20 00 00 00 4B B8 7A E7 47 7B 09 80 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x40 sent. Data: 0x01 
[P1] Response ID 0x21. Data: 0xD1 20 00 00 00 4B B8 7A E7 37 7B 09 80 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x48 sent. Data: 0x01 
[P1] Response ID 0x21. Data: 0xD7 20 00 00 00 4B C8 7A E7 57 7B 09 80 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Subcommand 0x03 sent. Data: 0x30 
[P1] Response ID 0x21. Data: 0xDD 20 00 00 00 4B B8 7A E7 47 7B 0A 80 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
[P1] Done with init.
[P1] Starting poll thread.
[P1] Subcommand 0x38 sent. Data: 0x0F 1F 10 11 FF 

Here's the log for the fixed ViGEm error in 8.4.3 with HidHide_1.5.212_x64.

[P1] Pro controller connected.
[P1] Connect virtual xbox controller.
[P1] Could not connect (Die Anfrage wurde wegen einem enormen Hardwarefehler abgebrochen).

Which means something like "Request error because of fatal hardware error".

Can you maybe just restart the process again because it works when I just restart Betterjoy while the controller is still syncing/blinking? 8.4 seems to do it?

d3xMachina commented 5 months ago

Thanks for the logs. No idea why you get that error but I saw an oversight that prevented to retry connecting after a ViGEm error. I fixed it, now it will try to reconnect properly : BetterJoy.zip

PizzaPino commented 5 months ago

seems to be connecting fine now, thanks!