emilyst / hid-nx-dkms

Alternative Linux kernel HID driver for Nintendo Switch controllers
GNU General Public License v2.0
40 stars 6 forks source link

NSO controller joystick calibration failing to load #18

Open Mikhailzrick opened 7 months ago

Mikhailzrick commented 7 months ago

I have 4x switch online N64 controllers and they all seem to have slightly off values for the joystick. Using evtest, the down axis seems to max out around 27,000 out of the reported 32,000 max, and the up axis seems to be somewhere around 3,000 while in a neutral position(this behavior is observed on all 4 of my controllers). This makes things like jumping out of the water in super mario 64, or doing the loop in start fox impossible. I implemented some joystick sensitivity settings that act as a workaround in batocera, but finding the root cause of the problem is ideal. If you need any additional info please let me know.

Something also possibly of note is checking demesg it states fails to read stick cal and loads defaults “e=-22".

This is being used and was tested in current stable version of Batocera (V38) for additional context.

nfp0 commented 7 months ago

~I have tested with my N64 controllers and everything seems to be working correctly.~

EDIT: Please ignore this post and read my next one. I was using a different driver.

The log states:

kernel: nintendo 0005:057E:2019.0005: using factory cal for left stick
kernel: nintendo 0005:057E:2019.0005: using factory cal for right stick

My joystick values correctly max out at 32767 and are at zero when in a neutral position.

Have you tried calibrating your joysticks on a Nintendo Switch? What's the behavior there?

Mikhailzrick commented 7 months ago

I have tested with my N64 controllers and everything seems to be working correctly.

The log states:

kernel: nintendo 0005:057E:2019.0005: using factory cal for left stick
kernel: nintendo 0005:057E:2019.0005: using factory cal for right stick

My joystick values correctly max out at 32767 and are at zero when in a neutral position.

Have you tried calibrating your joysticks on a Nintendo Switch? What's the behavior there?

I tried calibrating 2 of my controllers to make sure on my switch and it still results in inaccurate joystick values(one of which is brand new I just opened out of the package) under linux/batocera and:

5636.616578] input: N64 Controller as /devices/pci0000:00/0000:00:02.1/0000:01:00.0/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:256/0005:057E:2019.0008/input/input19 [ 5889.488474] nx 0005:057E:2009.0009: unknown main item tag 0x0 [ 5889.488868] nx 0005:057E:2009.0009: hidraw4: BLUETOOTH HID v80.01 Gamepad [Pro Controller] on 6c:94:66:06:e4:73 [ 5889.641546] nx 0005:057E:2009.0009: controller MAC = 48:31:77:4D:22:83 [ 5889.658223] nx 0005:057E:2009.0009: using factory cal for left stick [ 5889.691545] nx 0005:057E:2009.0009: using factory cal for right stick [ 5889.724878] nx 0005:057E:2009.0009: Failed to read left stick cal, using defaults; e=-22 [ 5889.761545] nx 0005:057E:2009.0009: Failed to read right stick cal, using defaults; e=-22 [ 5889.808215] nx 0005:057E:2009.0009: using factory cal for IMU

What do you suggest I try?

Mikhailzrick commented 7 months ago

This is my brand new one. But similar off values are seen on all.

sdl2-jstest shows:

NUETRAL

Axes  2:
   0:   2075  [                                                    #                                               ]
   1:  -2862  [                                             #                                                      ]

UP

Axes  2:
   0:   1629  [                                                        #                                                   ]
   1: -32653  [#                                                                                                           ]

DOWN

Axes  2:
   0:   1892  [                                                            #                                                      ]
   1:  27616  [                                                                                                         #         ]

LEFT

Axes  2:
   0: -27872  [        #                                                                                                          ]
   1:   -949  [                                                       #                                                           ]

RIGHT

Axes  2:
   0:  32767  [                                                                                                                  #]
   1:  -2744  [                                                    #                                                              ]

.sdl2 file "050000007e0500001920000001800000_N64 Controller.cache" shows

2
0
0
nfp0 commented 7 months ago

@Mikhailzrick I am sorry, you are correct. I was using the hid-nintendo-nso-dkms driver and not this hid-nx-dkms one.

Indeed after testing with hid-nx-dkms I get the same behaviour as you. I get the Failed to read left stick cal, using defaults; e=-22 error and the joysticks can't reach their maximum value. Also, the neutral position is not correct, as you described.

Mikhailzrick commented 7 months ago

@Mikhailzrick I am sorry, you are correct. I was using the hid-nintendo-nso-dkms driver and not this hid-nx-dkms one.

Indeed after testing with hid-nx-dkms I get the same behaviour as you. I get the Failed to read left stick cal, using defaults; e=-22 error and the joysticks can't reach their maximum value. Also, the neutral position is not correct, as you described.

Any idea how this could be resolved? Other than just trying to use the other driver you mentioned? Are there any differences, or pros/cons I should be aware of? Thank you

nfp0 commented 7 months ago

No idea why the calibration reading is failing. @emilyst would need to take a look at it.

As for the hid-nintendo-nso-dkms it's pretty much the same driver as the kernel one, with added support for all the NSO controllers (N64, SNES, etc). Mind you the button mappings are the going to be different, as hid-nx has modified mappings.

Mikhailzrick commented 7 months ago

A fix for the failed calibration reading would be ideal as we have a decent amount of things auto configured input wise, including the nso n64 controller. But, we may look at additional options if need be.

nfp0 commented 7 months ago

You mean in Batocera? I believe the RetroArch auto configurations are based on the kernel driver, and nso-dkms uses the same mapping, so it's valid for it also. EDIT: I've checked and the N64 mappings seem to be different after all.

The only problem I found with nso-dkms is that the Mega Drive/Genesis controller is reported as a SNES controller. I'll try to contact the dev, as I think it's a pretty easy fix.

Mikhailzrick commented 7 months ago

You mean in Batocera? I believe the RetroArch auto configurations are based on the kernel driver, and nso-dkms uses the same mapping, so it's valid for it also.

The only problem I found with nso-dkms is that the Mega Drive/Genesis controller is reported as a SNES controller. I'll try to contact the dev, as I think it's a pretty easy fix.

We don’t use retroarchs auto configurations as batocera has many emulators that are not Libretro cores. I’ll await any potential fix for the calibration read failure and if there is anything I can do to test/check let me know. Thank you.

Mikhailzrick commented 7 months ago

Just to report back, we have unsuccessfully tried other driver options in batocera. We have decided to continue using hid-nx and will await a fix for the n64 calibration issue upstream.

nfp0 commented 7 months ago

@Mikhailzrick Any reason in particular why hid-nintendo-nso did not work for Batocera?

nfp0 commented 7 months ago

It seems this is not a problem isolated to the N64 controller. I have just now tested the Pro Controller and it also fails to read the calibration data with the same error (even though the miscalibration is not as severe on my case).

So maybe we should change the issue name as this is not N64 specific.

Mikhailzrick commented 6 months ago

@Mikhailzrick Any reason in particular why hid-nintendo-nso did not work for Batocera?

I tried testing a few builds from one of our lead devs that had the other driver option but apparently there’s something happening between evtest and sdl2, causing the controller to not be seen or recognized by emulation station and then by extension none of the other code base. So the lead dev decided it was probably best to just wait for this fix since everything else works fine, just with the calibration issue.

Mikhailzrick commented 6 months ago

It seems this is not a problem isolated to the N64 controller. I have just now tested the Pro Controller and it also fails to read the calibration data with the same error (even though the miscalibration is not as severe on my case).

So maybe we should change the issue name as this is not N64 specific.

Done

nfp0 commented 6 months ago

@Mikhailzrick You'll probably enjoy this! :slightly_smiling_face: I just found out that full support for all the NSO controllers will be released on kernel 6.8! :tada: https://github.com/torvalds/linux/commit/94f18bb19945915fcdfd1903841020ef1b6af44a

emilyst commented 6 months ago

Hi, all, sorry I've been absent in GitHub lately. It's been a rough winter.

The calibration problem is not obvious to me. Maybe something changed between kernel versions to make this behave strangely, because it seemed fine in the past (I think?), and I haven't changed anything that I know of.

I can try to take a look at it, but I don't know how long it's going to take me.

@Mikhailzrick You'll probably enjoy this! 🙂 I just found out that full support for all the NSO controllers will be released on kernel 6.8! 🎉 torvalds/linux@94f18bb

I didn't know about this! Heh, those sure do look like changes I made. Honestly, this is a huge relief, since it means I probably won't have to maintain this out-of-kernel module anymore! Whew.

nfp0 commented 6 months ago

I didn't know about this! Heh, those sure do look like changes I made.

@emilyst Most surely, as they added your name there. image

Having this on the kernel is good news for everyone. Thank you for all your hard work! :slightly_smiling_face:

emilyst commented 6 months ago

I didn't know about this! Heh, those sure do look like changes I made.

@emilyst Most surely, as they added your name there. image

Having this on the kernel is good news for everyone. Thank you for all your hard work! 🙂

Wow, that's wild.

By the by, I want to make sure you know you have my gratitude, @nfp0, for being patient and helping people in these issues, even when I've been scarce. It's been enormously helpful to have you here. Thanks!

nfp0 commented 6 months ago

@emilyst Not at all! I just helped where I could. You did all the hard work and I'm grateful, because I use your driver on a daily basis. :wink:

Mikhailzrick commented 6 months ago

Just wanted to follow up. We tested the kernel driver again and it still has a few issues. The more important one is that the joystick doesn’t reach the full axis values in any direction. It only reaches around 20,000 or so out of 32,000, but this renders it unusable for normal users. That’s the more pressing issue. The other is the led lights on the controller don’t work and will constantly cycle similarly to when it’s in pairing mode.

at this time we have decided to continue using the nx driver and just inform users of our current recommended workaround of increasing sensitivity by +5/10% or so, and wait for either @emilyst to figure out the calibration issue for the nx driver, or wait for better kernel support.

Ideally if we can figure out the failure to load calibration data with the nx drivers this is our current preferred option. If there’s anything I can provide to help let me know.

nfp0 commented 6 months ago

@Mikhailzrick What kernel version have you tried? If the LEDs don't stop spinning, then you're not using a kernel with the updated hid-nintendo driver. The NSO controllers support only landed in 6.8, which isn't released yet, but you can try it on RC2 for example.

I've tested it just now and all controllers work. Joystick calibration is read, and LEDs are fixed.

(There's only a small problem where the N64 controller is being detected as a mouse by udev, but I've already submitted a patch to fix that.)

Mikhailzrick commented 6 months ago

@Mikhailzrick What kernel version have you tried? If the LEDs don't stop spinning, then you're not using a kernel with the updated hid-nintendo driver. The NSO controllers support only landed in 6.8, which isn't released yet, but you can try it on RC2 for example.

I've tested it just now and all controllers work. Joystick calibration is read, and LEDs are fixed.

(There's only a small problem where the N64 controller is being detected as a mouse by udev, but I've already submitted a patch to fix that.)

Dman, one of our lead devs that’s been working with me on this issue, used kernel version 6.7.2 but he manually added the latest hid-Nintendo driver. According to him the build he gave me to test would be no different than using 6.8 in terms of the NSO controller support.

nfp0 commented 6 months ago

@Mikhailzrick I see, but for some reason it seems you're still using the old driver. Ask him to double check that. The LEDs should be fixed after connection. Check if you're definitely not loading any previous hid-nintendo or hid-nx DKMS drivers. I had problems in the past where the DKMS driver was still loading even after I've uninstalled the package. Also, make sure to run modprobe -r hid-nintendo or reboot, after all the cleanup. Otherwise the old driver will still be loaded.