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
72 stars 5 forks source link

[BUG] Switch Pro Controller can only re-connect when removed from Bluetooth devices #18

Open tparr opened 3 months ago

tparr commented 3 months ago

Describe the bug First time connection to Pro Controller is successful but it won't reconnect after shutoff. Hold Home button for poweroff and then press Start button to reconnect.

Controller (please complete the following information):

NOTE: Wired does work, initial and reconnect.

Initial Successful Connection output:

[P1] Subcommand 03 sent. Data: 3F 
[P1] Response ID 21. Data: 1B 60 00 00 00 EB 77 7A C5 D7 75 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 factory left stick calibration data.
[P1] left stick 1 calibration data: 1488 1584 1952 1926 1518 1608 
[P1] Retrieve factory right stick calibration data.
[P1] right stick calibration data: 1541 1699 1933 1890 1473 1453 
[P1] Retrieve factory sensors calibration data.
[P1] Gyro neutral position: 4 -45 24 
[P1] Subcommand 38 sent. Data: 18 01 10 FF FF 
[P1] Response ID 21. Data: 45 60 00 00 00 EC 77 7A C5 D7 75 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: 4B 60 00 00 00 EC 97 7A C5 D7 75 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: 51 60 00 00 00 EB 77 7A C3 E7 75 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: 57 60 00 00 00 ED 87 7A C5 D7 75 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: 5D 60 00 00 00 EB 87 7A C4 F7 75 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 controller sticks calibration.
[P1] Using controller sensors calibration.
[P1] Ready.
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Rumble data Received: XInput
[P1] Rumble data Received: XInput
[P1] Rumble data Received: XInput
[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] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Rumble data Received: XInput
[P1] Rumble data sent: 10 00 00 01 40 40 00 01 40 40 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 

2nd Connection Attempt:

Motion server started on 127.0.0.1:26760.
All systems go
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error.
[P1] Using Bluetooth.
[P1] Subcommand write error.
[P1] Subcommand write error.
[P1] Subcommand write error.
[P1] Subcommand write error.
[P1] Subcommand write error.
[P1] ReadSPI error
[P1] left stick 1 calibration data: 0 0 0 0 0 0 
[P1] right stick calibration data: 0 0 0 0 0 0 
[P1] Gyro neutral position: 0 0 0 
[P1] Error while reading calibration datas.
[P1] Resetting connection.
[P1] Subcommand 06 sent. Data: 01 
[P1] Subcommand write error.
[P1] Could not connect (reset calibration).
[P1] Pro controller disconnected.
[P1] Pro controller connected...
d3xMachina commented 3 months ago

I cannot reproduce the issue on my end. It looks like hidapi cannot send data to your controller. So I've added more informations on subcommand error in the latest release, it should tell you why it fails. (for the lines "Subcommand write error").

You could also try to :

PizzaPino commented 3 months ago

I've got the exact same problem. I've already enabled HidHide and installed the newest version. To connect after a restart I have to remove the controller in the Windows Settings and re-pair it again, 50% of the time. It worked without problems in 8.4.0 but since 8.4.3 this bug occured.

d3xMachina commented 3 months ago

@PizzaPino Could you provides logs when it fails to connect with the 8.4.3 version ? Be sure to change "DebugType" in the configuration from "None" to "comms" beforehand to have detailed logs.

PizzaPino commented 3 months ago

First connection after Windows boot up.

Motion server started on 127.0.0.1:26760.
All systems go
Configuration applied.
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Response ID 21. Data: 16 40 00 00 00 0A 78 7A 10 B8 79 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: 3C 40 00 00 00 09 B8 7A 12 B8 79 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: 42 40 00 00 00 09 B8 7A 10 B8 79 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: 48 40 00 00 00 09 A8 7A 10 B8 79 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: 4E 40 00 00 00 0A A8 7A 11 D8 79 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: 54 40 00 00 00 0A B8 7A 10 A8 79 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.).

Second attempt without re-pairing (usually works after quickly disconnecting with the Sync button and pressing a button again)

[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error: WriteFile: (0x0000048F) Das Gerät ist nicht angeschlossen.
[P1] Subcommand 30 sent. Data: 00 
[P1] Subcommand write error: WriteFile: (0x0000048F) Das Gerät ist nicht angeschlossen.
[P1] Pro controller disconnected.
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Response ID 21. Data: 1D 40 00 00 00 EF F7 7B 12 C8 79 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: 43 40 00 00 00 F2 F7 7B 11 D8 79 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: 49 40 00 00 00 F3 E7 7B 11 B8 79 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: 52 40 00 00 00 F2 F7 7B 11 D8 79 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: 58 40 00 00 00 F3 F7 7B 13 D8 79 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: 5E 40 00 00 00 F3 07 7C 11 C8 79 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 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF 
[P1] Subcommand 38 sent. Data: 0F 1F 10 11 FF
tparr commented 3 months ago

I've got updated logs after updating to the latest release.

HIDHide is enabled.
Motion server started on 127.0.0.1:26760.
All systems go
Configuration applied.
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Using Bluetooth.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] ReadSPI error
[P1] left stick 1 calibration data: 0 0 0 0 0 0 
[P1] right stick calibration data: 0 0 0 0 0 0 
[P1] Gyro neutral position: 0 0 0 
[P1] Error while reading calibration datas.
[P1] Resetting connection.
[P1] Subcommand 06 sent. Data: 01 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Could not connect (reset calibration).
[P1] Pro controller disconnected.
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Using Bluetooth.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/GetOverlappedResult: (0x000003E3) The I/O operation has been aborted because of either a thread exit or an application request.
[P1] ReadSPI error
[P1] left stick 1 calibration data: 0 0 0 0 0 0 
[P1] right stick calibration data: 0 0 0 0 0 0 
[P1] Gyro neutral position: 0 0 0 
[P1] Error while reading calibration datas.
[P1] Resetting connection.
[P1] Subcommand 06 sent. Data: 01 
[P1] Subcommand write error: WriteFile: (0x0000048F) The device is not connected.
[P1] Could not connect (reset calibration).
[P1] Pro controller disconnected.
tparr commented 3 months ago

This may have been solved in a recent commit in the original hidapi repo https://github.com/libusb/hidapi/pull/577

d3xMachina commented 3 months ago

The hidapi dll included with Betterjoy already includes this fix since early january (overlapfix branch here).

However there was a more recent commit that might fix the issue (we get a connection event for a device which appears to not be connected then no disconnection event).

Here is the updated hidapi dll (put the content in the BetterJoy folder and replace the files) : hidapi.zip

If it still doesn't work, an issue on the hidapi repository needs to be opened.

tparr commented 3 months ago

Just did a test with the updated hidapi.dll's provided and still having issues:

HIDHide is enabled.
Motion server started on 127.0.0.1:26760.
All systems go
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Using Bluetooth.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] ReadSPI error
[P1] left stick 1 calibration data: 0 0 0 0 0 0 
[P1] right stick calibration data: 0 0 0 0 0 0 
[P1] Gyro neutral position: 0 0 0 
[P1] Error while reading calibration datas.
[P1] Resetting connection.
[P1] Subcommand 06 sent. Data: 01 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Could not connect (reset calibration).
[P1] Pro controller disconnected.
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Using Bluetooth.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Subcommand write error: hid_write/GetOverlappedResult: (0x000003E3) The I/O operation has been aborted because of either a thread exit or an application request.
[P1] Subcommand write error: WriteFile: (0x0000048F) The device is not connected.
[P1] Subcommand write error: WriteFile: (0x0000048F) The device is not connected.
[P1] ReadSPI error
[P1] left stick 1 calibration data: 0 0 0 0 0 0 
[P1] right stick calibration data: 0 0 0 0 0 0 
[P1] Gyro neutral position: 0 0 0 
[P1] Error while reading calibration datas.
[P1] Resetting connection.
[P1] Subcommand 06 sent. Data: 01 
[P1] Subcommand write error: WriteFile: (0x0000048F) The device is not connected.
[P1] Could not connect (reset calibration).
[P1] Pro controller disconnected.
[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Subcommand write error: hid_write/WaitForSingleObject: (0x000003E5) Overlapped I/O operation is in progress.
[P1] Using Bluetooth.
PizzaPino commented 3 months ago

Not fixed for me either but seems to be a different error compared to @tparr .

[P1] Pro controller connected.
[P1] Subcommand 03 sent. Data: 3F 
[P1] Response ID 21. Data: 12 40 00 00 00 2F 88 7A 12 68 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: 37 40 00 00 00 31 58 7A 10 78 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: 3D 40 00 00 00 30 68 7A 10 78 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: 43 40 00 00 00 31 78 7A 0F 78 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: 49 40 00 00 00 32 58 7A 10 88 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: 4F 40 00 00 00 31 58 7A 10 88 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 3 months ago

@PizzaPino You're having a completely different issue here. The device connect correctly but ViGEm fails to create the virtual controller. It says there is no error after the "Could not connect" because of a bug with an exception not being handled in ViGEm .NET. I just pushed a fix for that so it will display the proper error. To fix the issue you probably have to reinstall ViGEm, I had this happen twice in the past : after a windows update and after a failed update of ViGEm.

Here is the BetterJoy at the last commit : BetterJoy.zip

Note aside, for the initial issue, @tparr when you try to connect your controller after a restart, is BetterJoy setup to start on windows startup or you start it by hand ? I'm asking this since I saw "Overlapped I/O operation" errors after resuming from standby which lead to a recent commit "wait until Windows resumed fully from standby". But even with those errors it would still connect once windows resumed from standby fully... Also what version of Windows are you on ? I saw reports on hidapi issue tracker with bluetooth and Windows 7.

d3xMachina commented 2 months ago

I've made some changes that might help in the latest release.

d3xMachina commented 1 month ago

I've been able to reproduce this 100% of the time with a shitty USB bluetooth adapter that I stopped using because I had random issues and unreliable connection (a TP Link UB500 V1). For some reason it fails with the pro controller but not the joycons. So trying with a better adapter (not USB if possible as they often suck) would probably work.