From 2af20b0d8375f9681c16cb165f100df7f833496e Mon Sep 17 00:00:00 2001 From: Dmugetsu <168934208+diegolix29@users.noreply.github.com> Date: Thu, 20 Feb 2025 02:15:54 -0600 Subject: [PATCH] Now lightbar overwrite works on dualsense while using it on bluetooth (#2481) --- src/sdl_window.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index ccc369c53..db6f37e2a 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -97,6 +97,7 @@ void SDLInputEngine::Init() { SDL_CloseGamepad(m_gamepad); m_gamepad = nullptr; } + int gamepad_count; SDL_JoystickID* gamepads = SDL_GetGamepads(&gamepad_count); if (!gamepads) { @@ -108,12 +109,26 @@ void SDLInputEngine::Init() { SDL_free(gamepads); return; } + LOG_INFO(Input, "Got {} gamepads. Opening the first one.", gamepad_count); - if (!(m_gamepad = SDL_OpenGamepad(gamepads[0]))) { + m_gamepad = SDL_OpenGamepad(gamepads[0]); + if (!m_gamepad) { LOG_ERROR(Input, "Failed to open gamepad 0: {}", SDL_GetError()); SDL_free(gamepads); return; } + + SDL_Joystick* joystick = SDL_GetGamepadJoystick(m_gamepad); + Uint16 vendor = SDL_GetJoystickVendor(joystick); + Uint16 product = SDL_GetJoystickProduct(joystick); + + bool isDualSense = (vendor == 0x054C && product == 0x0CE6); + + LOG_INFO(Input, "Gamepad Vendor: {:04X}, Product: {:04X}", vendor, product); + if (isDualSense) { + LOG_INFO(Input, "Detected DualSense Controller"); + } + if (Config::getIsMotionControlsEnabled()) { if (SDL_SetGamepadSensorEnabled(m_gamepad, SDL_SENSOR_GYRO, true)) { m_gyro_poll_rate = SDL_GetGamepadSensorDataRate(m_gamepad, SDL_SENSOR_GYRO); @@ -126,11 +141,22 @@ void SDLInputEngine::Init() { LOG_INFO(Input, "Accel initialized, poll rate: {}", m_accel_poll_rate); } else { LOG_ERROR(Input, "Failed to initialize accel controls for gamepad"); - }; + } } + SDL_free(gamepads); + int* rgb = Config::GetControllerCustomColor(); - SetLightBarRGB(rgb[0], rgb[1], rgb[2]); + + if (isDualSense) { + if (SDL_SetJoystickLED(joystick, rgb[0], rgb[1], rgb[2]) == 0) { + LOG_INFO(Input, "Set DualSense LED to R:{} G:{} B:{}", rgb[0], rgb[1], rgb[2]); + } else { + LOG_ERROR(Input, "Failed to set DualSense LED: {}", SDL_GetError()); + } + } else { + SetLightBarRGB(rgb[0], rgb[1], rgb[2]); + } } void SDLInputEngine::SetLightBarRGB(u8 r, u8 g, u8 b) {