Bug 216225
Summary: | hid-nintendo player LED behavior is wrong | ||
---|---|---|---|
Product: | Drivers | Reporter: | tinozzo123 |
Component: | Input Devices | Assignee: | drivers_input-devices |
Status: | RESOLVED IMPLEMENTED | ||
Severity: | normal | CC: | nf.pereira |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | 5.18.9 | Subsystem: | |
Regression: | No | Bisected commit-id: |
Description
tinozzo123
2022-07-09 10:00:02 UTC
I gave a look to hid-nintendo.c to see why it behaves like this. From what I think I've gathered: The static variable that controls the LED number is `input_num`. It increases by 1 (and resets to 1 when it reaches 5) every time after LEDs are initialized (`joycon_leds_create`). It never decreases. Finally, the reason why multiple LEDs are turned on instead of just one, seems to be in `led->brightness = ((i + 1) <= input_num) ? 1 : 0;` (it's a `<=` instead of a `==`). Instead of doing this, would it be possible to have a static variable that increases by 1 when a controller is connected (`nintendo_hid_probe`) and decreases by 1 when disconnected `nintendo_hid_remove`? (With the necessary mutexes, of course.) I don't know how to test kernel stuff, so that's why I'm just leaving this comment. I just realized that using one global counter would have a problem. If two controllers are connected, player one disconnects, then a controller is connected, they will both be "player two" according to the leds. The solution would be to store the controllers in a list, and when a controller disconnects either: - All the player of a higher number will shift to the left, and the leds updated accordingly; - Leave an empty slot. When a controller is connected, it takes the first empty slot available (this is what's done on the Switch console). Yes, any of those 2 solutions would be better than the current implementation IMO. Fixed in Linux 6.10. |