We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5014 - [PATCH] PS4 Controller Lightbar always reset to default blue
Summary: [PATCH] PS4 Controller Lightbar always reset to default blue
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.10
Hardware: x86 Windows 10
: P2 trivial
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-05 22:20 UTC by Vitor
Modified: 2020-11-05 17:44 UTC (History)
1 user (show)

See Also:


Attachments
Added support for indicating player index on DS4 controllers (3.28 KB, patch)
2020-03-07 21:22 UTC, Cameron Gutman
Details | Diff
Clear the old player index slot when moving to a new one (1.06 KB, patch)
2020-03-08 03:28 UTC, Cameron Gutman
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vitor 2020-03-05 22:20:30 UTC
If a user has altered the lightbar color, their color will change back to blue when using the hidapi drivers. Tested on 2.0.10, compared against 2.0.8 (which doesn't have said drivers). The PS4 controller is connected via USB.

If it's not feasible to keep the previous color (which seems the case from a cursory look at the code), it'd be ideal to be able to set the color in some way at runtime.

The pertinent part of the code is likely in SDL_hidapi_PS4.c, in HIDAPI_DriverPS4_Rumble:
effects->ucLedRed = 0;
effects->ucLedGreen = 0;
effects->ucLedBlue = 80;


I have provided all the information I have, and cannot provide further, because I am not the one experiencing the issue. This is based on the issue on https://github.com/citra-emu/citra/issues/5118
Comment 1 Cameron Gutman 2020-03-07 21:22:36 UTC
Created attachment 4238 [details]
Added support for indicating player index on DS4 controllers

This patch sets the DS4 LED to indicate the player index like the PS4 does. It also matches the colors that the hid-sony driver uses in the Linux kernel when the player count exceeds 4 (max supported on PS4).
Comment 2 Sam Lantinga 2020-03-08 01:37:19 UTC
Thanks, your patch is in:
https://hg.libsdl.org/SDL/rev/ea9492fc2eae

Can you adapt it so it adjusts the color when someone sets the player index?
Comment 3 Cameron Gutman 2020-03-08 03:28:52 UTC
Created attachment 4242 [details]
Clear the old player index slot when moving to a new one

HIDAPI_DriverPS4_SetDevicePlayerIndex() should properly handle changing player index on the fly.

After some additional testing, I think I may have found the issue you are seeing. SDL_SetJoystickIDForPlayerIndex() isn't clearing the old location in SDL_joystick_players[], so you wouldn't be able to go from 0 -> 1 -> 0, since the check added in https://hg.libsdl.org/SDL/rev/36aabb2051e9 would see it as a no-op.

With the attached patch, I can SDL_SetJoystickIDForPlayerIndex() to whatever index I want and the LED color is set correctly both over BT (with SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE=1) and USB.
Comment 4 Sam Lantinga 2020-03-08 22:46:51 UTC
Great, I applied your second patch, but the first one doesn't apply cleanly to Mercurial. Can you rebase and test it?

Thanks!
Comment 5 Cameron Gutman 2020-03-09 02:44:57 UTC
The first patch was already applied as https://hg.libsdl.org/SDL/rev/ea9492fc2eae

This bug can be resolved now unless you see something else broken.
Comment 6 Sam Lantinga 2020-03-09 03:10:22 UTC
Thanks Cameron.

Vitor, how did the user originally change their PS4 light bar color? It doesn't look like it's possible to read back the existing color, and I don't think anyone will go to the trouble of using an SDL API to set it to match a specific color, so if nobody wants more specific control, I'll go ahead and close this bug.
Comment 7 Vitor 2020-03-09 04:26:31 UTC
Hello,
first of all thank you Cameron for the quick patch.
Sam, from what I understand, the user set the color via Steam's big picture mode.
With that in mind, it is possible the observed behavior has a different underlying cause (maybe the user set the color but has since exited big picture mode/Steam? Or maybe it's a different bug in Steam or SDL?), and so some investigation is needed.
Nevertheless I see this as a good solution for the presented problem. 
Having an API for setting the lightbar color would be a little overkill. While I don't think it would go totally unused, it's probably more trouble than it's worth.

I'll keep investigating the issue, but I believe the bug as presented here is fixed. The solution of using the same colors as the PS4 is quite nice.
Comment 8 Sam Lantinga 2020-11-05 17:44:43 UTC
It looks like this is resolved. Feel free to reopen it if that's not the case.