controller: enable the DualSense HIDAPI driver, light bar and adaptive triggers #437

Manually merged
github merged 2 commits from gh-pr/437/head into gh-pr/437/base 2026-11-26 09:20:53 +00:00
Owner

@⁠CheesyPoofs346 on GitHub · 2026-09-01 03:05 UTC · original
CheesyPoofs346:feat/dualsense-support → main · +178 −18 · 4 files · 2 commits · merged 2026-09-01 20:53 UTC

Summary

  • Enable SDL's PS5 HIDAPI driver, without which a DualSense exposes neither its light bar nor its touchpad.
  • Drive the light bar from PadSetLightBar instead of accepting and discarding the call.
  • Implement PadSetTriggerEffect by translating a title's request into a DualSense trigger block.

Problem

The HIDAPI driver. SDL opens a DualSense through the generic gamepad path unless told otherwise. Logging what SDL reported for a connected pad:

SDL pad opened: DualSense Edge Wireless Controller (LED=0, touchpads=0)

SDL_GameControllerHasLED and SDL_GameControllerGetNumTouchpads both return nothing, so SDL_GameControllerSetLED cannot work and no SDL_CONTROLLERTOUCHPAD* events are ever delivered — the touchpad handling already in tree has nothing to receive. Setting the PS5 hints before SDL_InitSubSystem gives:

SDL pad opened: DualSense Edge Wireless Controller (LED=1, touchpads=1)

The light bar. PadSetLightBar validated its arguments and returned OK without touching the pad, so a title signalling state through it (police lights, health, player colour) had no effect. Verified in Grand Theft Auto V, where the light bar now flashes red and blue at a wanted level.

Adaptive triggers. PadSetTriggerEffect likewise returned OK and did nothing. SDL_GameControllerSendEffect cannot carry these — SDL's PS5 driver owns its output report and rejects ours with SendEffect failed, device disconnected — so the trigger block is written directly to the pad over HID. USB uses report 0x02 with the payload at offset 1; Bluetooth uses 0x31 at offset 2 with a CRC32 over an 0xA2 header byte plus the report. Only the trigger-effect enable bits are set, leaving the rumble and LED state SDL manages untouched; an earlier version that wrote the whole report degraded vibration.

The parameter layout was established by logging what a title actually sends: a trigger mask, a uint32 mode per trigger at offsets 4 and 8, then a four-byte parameter block per trigger at 12 and 16. Modes map to DualSense effect types — 1 feedback to 0x01 rigid, 2 weapon to 0x02 pulse, 3 vibration to 0x06. Positions (0-9) and strengths (0-8) are scaled to the 0-255 the hardware expects; passing them through unscaled put resistance at 3.5% of the trigger pull and felt permanently engaged.

Identical effects are not re-sent, since titles reissue the same request every frame and the pad holds the last one.

Validation

  • Built on Windows with clang-cl/Ninja and exercised in game from the same changes in my working tree; the PR branch itself was not built in isolation because that checkout lacks the vendored submodules.
  • GTA5 on a DualSense Edge over Bluetooth: light bar flashes red/blue at a wanted level, R2 gives throttle resistance while driving, touchpad click and swipes register, and vibration is unaffected.
  • Titles that never call these functions are unaffected; the hints only change which SDL driver claims a PS5 pad.

AI assistance

AI assistance was used for this change.

**@⁠CheesyPoofs346** on GitHub · 2026-09-01 03:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437) `CheesyPoofs346:feat/dualsense-support` → `main` · +178 −18 · 4 files · 2 commits · merged 2026-09-01 20:53 UTC ## Summary - Enable SDL's PS5 HIDAPI driver, without which a DualSense exposes neither its light bar nor its touchpad. - Drive the light bar from `PadSetLightBar` instead of accepting and discarding the call. - Implement `PadSetTriggerEffect` by translating a title's request into a DualSense trigger block. ## Problem **The HIDAPI driver.** SDL opens a DualSense through the generic gamepad path unless told otherwise. Logging what SDL reported for a connected pad: ``` SDL pad opened: DualSense Edge Wireless Controller (LED=0, touchpads=0) ``` `SDL_GameControllerHasLED` and `SDL_GameControllerGetNumTouchpads` both return nothing, so `SDL_GameControllerSetLED` cannot work and no `SDL_CONTROLLERTOUCHPAD*` events are ever delivered — the touchpad handling already in tree has nothing to receive. Setting the PS5 hints before `SDL_InitSubSystem` gives: ``` SDL pad opened: DualSense Edge Wireless Controller (LED=1, touchpads=1) ``` **The light bar.** `PadSetLightBar` validated its arguments and returned `OK` without touching the pad, so a title signalling state through it (police lights, health, player colour) had no effect. Verified in Grand Theft Auto V, where the light bar now flashes red and blue at a wanted level. **Adaptive triggers.** `PadSetTriggerEffect` likewise returned `OK` and did nothing. `SDL_GameControllerSendEffect` cannot carry these — SDL's PS5 driver owns its output report and rejects ours with `SendEffect failed, device disconnected` — so the trigger block is written directly to the pad over HID. USB uses report `0x02` with the payload at offset 1; Bluetooth uses `0x31` at offset 2 with a CRC32 over an `0xA2` header byte plus the report. Only the trigger-effect enable bits are set, leaving the rumble and LED state SDL manages untouched; an earlier version that wrote the whole report degraded vibration. The parameter layout was established by logging what a title actually sends: a trigger mask, a `uint32` mode per trigger at offsets 4 and 8, then a four-byte parameter block per trigger at 12 and 16. Modes map to DualSense effect types — 1 feedback to `0x01` rigid, 2 weapon to `0x02` pulse, 3 vibration to `0x06`. Positions (0-9) and strengths (0-8) are scaled to the 0-255 the hardware expects; passing them through unscaled put resistance at 3.5% of the trigger pull and felt permanently engaged. Identical effects are not re-sent, since titles reissue the same request every frame and the pad holds the last one. ## Validation - Built on Windows with clang-cl/Ninja and exercised in game from the same changes in my working tree; the PR branch itself was not built in isolation because that checkout lacks the vendored submodules. - GTA5 on a DualSense Edge over Bluetooth: light bar flashes red/blue at a wanted level, R2 gives throttle resistance while driving, touchpad click and swipes register, and vibration is unaffected. - Titles that never call these functions are unaffected; the hints only change which SDL driver claims a PS5 pad. ## AI assistance AI assistance was used for this change.
Three additions. SDL was opening a DualSense through the generic gamepad path, so SDL_GameControllerHasLED and SDL_GameControllerGetNumTouchpads both reported nothing and no touchpad events ever arrived - enabling the PS5 HIDAPI driver before SDL_InitSubSystem is what makes the light bar and the existing touchpad support reachable. PadSetLightBar validated its arguments and returned OK without touching the pad; it now drives the LED. PadSetTriggerEffect did the same; it now translates the mode and parameters into a DualSense trigger block and sends it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:51 +00:00
github manually merged commit c2961cbd76 into gh-pr/437/base 2026-11-26 09:20:53 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-09-01 03:08 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 681c2f30cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-09-01 03:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#pullrequestreview-5073637067) · **reviewed** ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `681c2f30cc` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-09-01 03:08 UTC · original
On src/libs/controller.cpp line 346 (outdated):

@@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) {
 	}
 }
 
+void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) {
+	Common::LockGuard lock(m_mutex);
+	if (m_active_id < 0) {
+		return;
+	}
+	auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id));
+	if (pad == nullptr) {
+		return;
+	}
+	// A pad without an LED reports failure; there is nothing to recover from.
+	(void)SDL_GameControllerSetLED(pad, r, g, b);
+}
+
+// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad
+// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a
+// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at
+// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone.
+void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) {
+	Common::LockGuard lock(m_mutex);
+	if (left == nullptr || right == nullptr) {
+		return;
+	}
+	if (!m_hid_tried) {
+		m_hid_tried = true;
+		for (const auto product: {0x0ce6, 0x0df2}) {
+			m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr);

P2 Badge Retry HID acquisition after controller changes

If a title calls PadSetTriggerEffect before a DualSense is connected, SDL_hid_open fails but m_hid_tried remains true, so every later call returns without retrying even after the controller is hot-plugged. The same retained state leaves a stale handle after disconnect/reconnect; reset and close the HID handle whenever the active controller changes, and allow acquisition to be retried.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-09-01 03:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900431437) On `src/libs/controller.cpp` line 346 (outdated): ```diff @@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) { } } +void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) { + Common::LockGuard lock(m_mutex); + if (m_active_id < 0) { + return; + } + auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id)); + if (pad == nullptr) { + return; + } + // A pad without an LED reports failure; there is nothing to recover from. + (void)SDL_GameControllerSetLED(pad, r, g, b); +} + +// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad +// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a +// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at +// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone. +void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) { + Common::LockGuard lock(m_mutex); + if (left == nullptr || right == nullptr) { + return; + } + if (!m_hid_tried) { + m_hid_tried = true; + for (const auto product: {0x0ce6, 0x0df2}) { + m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr); ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Retry HID acquisition after controller changes** If a title calls `PadSetTriggerEffect` before a DualSense is connected, `SDL_hid_open` fails but `m_hid_tried` remains true, so every later call returns without retrying even after the controller is hot-plugged. The same retained state leaves a stale handle after disconnect/reconnect; reset and close the HID handle whenever the active controller changes, and allow acquisition to be retried. Useful? React with 👍 / 👎.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-09-01 03:08 UTC · original
On src/libs/libPad.cpp line 140 (outdated):

@@ -56,6 +112,34 @@ static int KYTY_SYSV_ABI PadSetTriggerEffect(int handle, const void* param) {
 		return -2137915391; /* 0x80920001 */
 	}
 
+	// Log what the title actually asks for: the effect mode and parameter bytes per trigger are
+	// what a DualSense HID output report has to carry, and nothing is known about them yet.
+	static std::atomic<uint32_t> trig_log {0};
+	if (trig_log.fetch_add(1, std::memory_order_relaxed) < 40) {
+		const auto* raw = static_cast<const uint8_t*>(param);
+		char        hex[3 * 32 + 1] = {};
+		for (int k = 0; k < 32; k++) {
+			::snprintf(hex + k * 3, 4, "%02x ", raw[k]);
+		}
+	}
+	// mask, then a mode per trigger, then a data block per trigger.
+	{
+		const auto*   raw      = static_cast<const uint8_t*>(param);
+		const uint8_t mask     = raw[0];
+		uint32_t      modes[2] = {};
+		std::memcpy(&modes[0], raw + 4, sizeof(uint32_t));
+		std::memcpy(&modes[1], raw + 8, sizeof(uint32_t));
+		uint8_t left[11]  = {};
+		uint8_t right[11] = {};
+		if ((mask & 0x1u) != 0) {
+			trigger_effect_to_hid(modes[0], raw + 12, left);
+		}
+		if ((mask & 0x2u) != 0) {
+			trigger_effect_to_hid(modes[1], raw + 16, right);
+		}
+		Controller::ControllerTriggerEffect(left, right);

P2 Badge Preserve the trigger excluded by the update mask

When the mask selects only one trigger, the other local effect remains zero-initialized, but ControllerTriggerEffect still emits a report enabling updates for both triggers. Consequently, a left-only update clears an existing right-trigger effect (and vice versa) instead of leaving the unmasked trigger unchanged; retain the previous effect or propagate the mask into report construction.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-09-01 03:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900431440) On `src/libs/libPad.cpp` line 140 (outdated): ```diff @@ -56,6 +112,34 @@ static int KYTY_SYSV_ABI PadSetTriggerEffect(int handle, const void* param) { return -2137915391; /* 0x80920001 */ } + // Log what the title actually asks for: the effect mode and parameter bytes per trigger are + // what a DualSense HID output report has to carry, and nothing is known about them yet. + static std::atomic<uint32_t> trig_log {0}; + if (trig_log.fetch_add(1, std::memory_order_relaxed) < 40) { + const auto* raw = static_cast<const uint8_t*>(param); + char hex[3 * 32 + 1] = {}; + for (int k = 0; k < 32; k++) { + ::snprintf(hex + k * 3, 4, "%02x ", raw[k]); + } + } + // mask, then a mode per trigger, then a data block per trigger. + { + const auto* raw = static_cast<const uint8_t*>(param); + const uint8_t mask = raw[0]; + uint32_t modes[2] = {}; + std::memcpy(&modes[0], raw + 4, sizeof(uint32_t)); + std::memcpy(&modes[1], raw + 8, sizeof(uint32_t)); + uint8_t left[11] = {}; + uint8_t right[11] = {}; + if ((mask & 0x1u) != 0) { + trigger_effect_to_hid(modes[0], raw + 12, left); + } + if ((mask & 0x2u) != 0) { + trigger_effect_to_hid(modes[1], raw + 16, right); + } + Controller::ControllerTriggerEffect(left, right); ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve the trigger excluded by the update mask** When the mask selects only one trigger, the other local effect remains zero-initialized, but `ControllerTriggerEffect` still emits a report enabling updates for both triggers. Consequently, a left-only update clears an existing right-trigger effect (and vice versa) instead of leaving the unmasked trigger unchanged; retain the previous effect or propagate the mask into report construction. Useful? React with 👍 / 👎.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-09-01 03:08 UTC · original
On src/libs/controller.cpp line 346 (outdated):

@@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) {
 	}
 }
 
+void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) {
+	Common::LockGuard lock(m_mutex);
+	if (m_active_id < 0) {
+		return;
+	}
+	auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id));
+	if (pad == nullptr) {
+		return;
+	}
+	// A pad without an LED reports failure; there is nothing to recover from.
+	(void)SDL_GameControllerSetLED(pad, r, g, b);
+}
+
+// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad
+// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a
+// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at
+// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone.
+void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) {
+	Common::LockGuard lock(m_mutex);
+	if (left == nullptr || right == nullptr) {
+		return;
+	}
+	if (!m_hid_tried) {
+		m_hid_tried = true;
+		for (const auto product: {0x0ce6, 0x0df2}) {
+			m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr);

P2 Badge Bind raw HID output to the active controller

When multiple Sony controllers are attached, this VID/PID-only open is unrelated to m_active_id; it can therefore send adaptive-trigger effects to a different physical pad than the one supplying player-one input. This is deterministic when an active Edge is present alongside a standard DualSense because product 0x0ce6 is always tried first. Resolve the active SDL controller's HID path or serial and open that exact device.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-09-01 03:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900431443) On `src/libs/controller.cpp` line 346 (outdated): ```diff @@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) { } } +void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) { + Common::LockGuard lock(m_mutex); + if (m_active_id < 0) { + return; + } + auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id)); + if (pad == nullptr) { + return; + } + // A pad without an LED reports failure; there is nothing to recover from. + (void)SDL_GameControllerSetLED(pad, r, g, b); +} + +// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad +// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a +// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at +// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone. +void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) { + Common::LockGuard lock(m_mutex); + if (left == nullptr || right == nullptr) { + return; + } + if (!m_hid_tried) { + m_hid_tried = true; + for (const auto product: {0x0ce6, 0x0df2}) { + m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr); ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Bind raw HID output to the active controller** When multiple Sony controllers are attached, this VID/PID-only open is unrelated to `m_active_id`; it can therefore send adaptive-trigger effects to a different physical pad than the one supplying player-one input. This is deterministic when an active Edge is present alongside a standard DualSense because product `0x0ce6` is always tried first. Resolve the active SDL controller's HID path or serial and open that exact device. Useful? React with 👍 / 👎.
Author
Owner

@⁠Copilot on GitHub · 2026-09-01 03:09 UTC · original
On src/libs/libPad.cpp line 124 (outdated):

@@ -56,6 +112,34 @@ static int KYTY_SYSV_ABI PadSetTriggerEffect(int handle, const void* param) {
 		return -2137915391; /* 0x80920001 */
 	}
 
+	// Log what the title actually asks for: the effect mode and parameter bytes per trigger are
+	// what a DualSense HID output report has to carry, and nothing is known about them yet.
+	static std::atomic<uint32_t> trig_log {0};
+	if (trig_log.fetch_add(1, std::memory_order_relaxed) < 40) {
+		const auto* raw = static_cast<const uint8_t*>(param);
+		char        hex[3 * 32 + 1] = {};
+		for (int k = 0; k < 32; k++) {
+			::snprintf(hex + k * 3, 4, "%02x ", raw[k]);
+		}
+	}

The trigger-effect logging block builds a hex string but never emits it, so the code has no effect and adds unnecessary work/complexity. Either remove the block or actually log the collected bytes (rate-limited as intended).

**@⁠Copilot** on GitHub · 2026-09-01 03:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900438176) On `src/libs/libPad.cpp` line 124 (outdated): ```diff @@ -56,6 +112,34 @@ static int KYTY_SYSV_ABI PadSetTriggerEffect(int handle, const void* param) { return -2137915391; /* 0x80920001 */ } + // Log what the title actually asks for: the effect mode and parameter bytes per trigger are + // what a DualSense HID output report has to carry, and nothing is known about them yet. + static std::atomic<uint32_t> trig_log {0}; + if (trig_log.fetch_add(1, std::memory_order_relaxed) < 40) { + const auto* raw = static_cast<const uint8_t*>(param); + char hex[3 * 32 + 1] = {}; + for (int k = 0; k < 32; k++) { + ::snprintf(hex + k * 3, 4, "%02x ", raw[k]); + } + } ``` The trigger-effect logging block builds a hex string but never emits it, so the code has no effect and adds unnecessary work/complexity. Either remove the block or actually log the collected bytes (rate-limited as intended).
Author
Owner

@⁠Copilot on GitHub · 2026-09-01 03:09 UTC · original
On src/libs/controller.cpp line 381 (outdated):

@@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) {
 	}
 }
 
+void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) {
+	Common::LockGuard lock(m_mutex);
+	if (m_active_id < 0) {
+		return;
+	}
+	auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id));
+	if (pad == nullptr) {
+		return;
+	}
+	// A pad without an LED reports failure; there is nothing to recover from.
+	(void)SDL_GameControllerSetLED(pad, r, g, b);
+}
+
+// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad
+// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a
+// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at
+// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone.
+void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) {
+	Common::LockGuard lock(m_mutex);
+	if (left == nullptr || right == nullptr) {
+		return;
+	}
+	if (!m_hid_tried) {
+		m_hid_tried = true;
+		for (const auto product: {0x0ce6, 0x0df2}) {
+			m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr);
+			if (m_hid != nullptr) {
+				uint8_t   probe[78] = {};
+				const int read      = SDL_hid_read_timeout(m_hid, probe, sizeof(probe), 50);
+				m_hid_bluetooth     = read > 64;
+				break;
+			}
+		}
+	}
+	if (m_hid == nullptr) {
+		return;
+	}
+	uint8_t combined[22] = {};
+	std::memcpy(combined, right, 11);
+	std::memcpy(combined + 11, left, 11);
+	if (m_trigger_sent && std::memcmp(combined, m_last_trigger, sizeof(combined)) == 0) {
+		return; // titles resend every frame; the pad holds the last effect
+	}
+	std::memcpy(m_last_trigger, combined, sizeof(combined));
+	m_trigger_sent = true;
+	uint8_t report[79] = {};
+	int     size       = 0;
+	int     offset     = 0;
+	if (m_hid_bluetooth) {
+		report[0] = 0x31;
+		report[1] = 0x02;
+		size      = 78;
+		offset    = 2;
+	} else {
+		report[0] = 0x02;
+		size      = 48;
+		offset    = 1;
+	}
+	report[offset + 0] = 0x0c;
+	std::memcpy(report + offset + 10, right, 11);
+	std::memcpy(report + offset + 21, left, 11);

The output-report apply bits are always set to 0x0c (both triggers), which ignores the title-provided trigger mask and can unintentionally clear or overwrite the other trigger when only one side is requested. This likely needs the mask (or per-trigger apply flags) to be plumbed through to SetTriggerEffect so only requested triggers are applied, while still allowing an explicit "off" to clear a trigger.

**@⁠Copilot** on GitHub · 2026-09-01 03:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900438216) On `src/libs/controller.cpp` line 381 (outdated): ```diff @@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) { } } +void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) { + Common::LockGuard lock(m_mutex); + if (m_active_id < 0) { + return; + } + auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id)); + if (pad == nullptr) { + return; + } + // A pad without an LED reports failure; there is nothing to recover from. + (void)SDL_GameControllerSetLED(pad, r, g, b); +} + +// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad +// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a +// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at +// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone. +void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) { + Common::LockGuard lock(m_mutex); + if (left == nullptr || right == nullptr) { + return; + } + if (!m_hid_tried) { + m_hid_tried = true; + for (const auto product: {0x0ce6, 0x0df2}) { + m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr); + if (m_hid != nullptr) { + uint8_t probe[78] = {}; + const int read = SDL_hid_read_timeout(m_hid, probe, sizeof(probe), 50); + m_hid_bluetooth = read > 64; + break; + } + } + } + if (m_hid == nullptr) { + return; + } + uint8_t combined[22] = {}; + std::memcpy(combined, right, 11); + std::memcpy(combined + 11, left, 11); + if (m_trigger_sent && std::memcmp(combined, m_last_trigger, sizeof(combined)) == 0) { + return; // titles resend every frame; the pad holds the last effect + } + std::memcpy(m_last_trigger, combined, sizeof(combined)); + m_trigger_sent = true; + uint8_t report[79] = {}; + int size = 0; + int offset = 0; + if (m_hid_bluetooth) { + report[0] = 0x31; + report[1] = 0x02; + size = 78; + offset = 2; + } else { + report[0] = 0x02; + size = 48; + offset = 1; + } + report[offset + 0] = 0x0c; + std::memcpy(report + offset + 10, right, 11); + std::memcpy(report + offset + 21, left, 11); ``` The output-report apply bits are always set to `0x0c` (both triggers), which ignores the title-provided trigger mask and can unintentionally clear or overwrite the other trigger when only one side is requested. This likely needs the mask (or per-trigger apply flags) to be plumbed through to `SetTriggerEffect` so only requested triggers are applied, while still allowing an explicit "off" to clear a trigger.
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-09-01 03:09 UTC · original · reviewed

Pull request overview

This PR enhances DualSense support in the controller subsystem by ensuring SDL uses the PS5 HIDAPI driver (enabling LED/touchpad capability reporting), wiring PadSetLightBar to actually drive the controller LED, and implementing adaptive trigger effects by translating title requests into DualSense HID trigger blocks sent directly over HID.

Changes:

  • Enable SDL PS5 HIDAPI hints on Windows so DualSense features (LED/touchpad) are exposed.
  • Implement light bar output by forwarding PadSetLightBar to SDL_GameControllerSetLED.
  • Implement adaptive trigger effects by translating title trigger requests into DualSense HID trigger effect blocks and sending them via HID.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/libs/libPad.cpp Adds translation from title trigger-effect parameters into DualSense HID trigger blocks and forwards them to the controller layer.
src/libs/controller.h Exposes a new ControllerTriggerEffect entry point for trigger-effect output.
src/libs/controller.cpp Implements light bar control via SDL, and adaptive trigger output via direct HID writes.
src/graphics/presentation/window/window.cpp Sets SDL hints to force PS5 HIDAPI driver usage on Windows prior to SDL subsystem init.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-09-01 03:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#pullrequestreview-5073644482) · **reviewed** ## Pull request overview This PR enhances DualSense support in the controller subsystem by ensuring SDL uses the PS5 HIDAPI driver (enabling LED/touchpad capability reporting), wiring `PadSetLightBar` to actually drive the controller LED, and implementing adaptive trigger effects by translating title requests into DualSense HID trigger blocks sent directly over HID. **Changes:** - Enable SDL PS5 HIDAPI hints on Windows so DualSense features (LED/touchpad) are exposed. - Implement light bar output by forwarding `PadSetLightBar` to `SDL_GameControllerSetLED`. - Implement adaptive trigger effects by translating title trigger requests into DualSense HID trigger effect blocks and sending them via HID. ### Reviewed changes Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments. | File | Description | | ---- | ----------- | | src/libs/libPad.cpp | Adds translation from title trigger-effect parameters into DualSense HID trigger blocks and forwards them to the controller layer. | | src/libs/controller.h | Exposes a new `ControllerTriggerEffect` entry point for trigger-effect output. | | src/libs/controller.cpp | Implements light bar control via SDL, and adaptive trigger output via direct HID writes. | | src/graphics/presentation/window/window.cpp | Sets SDL hints to force PS5 HIDAPI driver usage on Windows prior to SDL subsystem init. | --- 💡 <a href="/KytyPS5/KytyPS5/new/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a `code-review` agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review?tool=webui#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
Author
Owner

@⁠Copilot on GitHub · 2026-09-01 03:09 UTC · original
On src/libs/controller.cpp line 388 (outdated):

@@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) {
 	}
 }
 
+void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) {
+	Common::LockGuard lock(m_mutex);
+	if (m_active_id < 0) {
+		return;
+	}
+	auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id));
+	if (pad == nullptr) {
+		return;
+	}
+	// A pad without an LED reports failure; there is nothing to recover from.
+	(void)SDL_GameControllerSetLED(pad, r, g, b);
+}
+
+// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad
+// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a
+// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at
+// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone.
+void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) {
+	Common::LockGuard lock(m_mutex);
+	if (left == nullptr || right == nullptr) {
+		return;
+	}
+	if (!m_hid_tried) {
+		m_hid_tried = true;
+		for (const auto product: {0x0ce6, 0x0df2}) {
+			m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr);
+			if (m_hid != nullptr) {
+				uint8_t   probe[78] = {};
+				const int read      = SDL_hid_read_timeout(m_hid, probe, sizeof(probe), 50);
+				m_hid_bluetooth     = read > 64;
+				break;
+			}
+		}
+	}
+	if (m_hid == nullptr) {
+		return;
+	}
+	uint8_t combined[22] = {};
+	std::memcpy(combined, right, 11);
+	std::memcpy(combined + 11, left, 11);
+	if (m_trigger_sent && std::memcmp(combined, m_last_trigger, sizeof(combined)) == 0) {
+		return; // titles resend every frame; the pad holds the last effect
+	}
+	std::memcpy(m_last_trigger, combined, sizeof(combined));
+	m_trigger_sent = true;
+	uint8_t report[79] = {};
+	int     size       = 0;
+	int     offset     = 0;
+	if (m_hid_bluetooth) {
+		report[0] = 0x31;
+		report[1] = 0x02;
+		size      = 78;
+		offset    = 2;
+	} else {
+		report[0] = 0x02;
+		size      = 48;
+		offset    = 1;
+	}
+	report[offset + 0] = 0x0c;
+	std::memcpy(report + offset + 10, right, 11);
+	std::memcpy(report + offset + 21, left, 11);
+	if (m_hid_bluetooth) {
+		const uint8_t header = 0xa2;
+		uint32_t      crc    = SDL_crc32(0, &header, 1);
+		crc                  = SDL_crc32(crc, report, static_cast<size_t>(size) - sizeof(crc));
+		std::memcpy(report + size - sizeof(crc), &crc, sizeof(crc));
+	}
+	(void)SDL_hid_write(m_hid, report, static_cast<size_t>(size));

SDL_hid_write errors are ignored, and m_hid_tried prevents reopening; if the controller disconnects/reconnects, trigger effects may silently stop working for the rest of the session. Capture the return value and on failure close/reset the HID handle so a later call can retry opening.

**@⁠Copilot** on GitHub · 2026-09-01 03:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900438245) On `src/libs/controller.cpp` line 388 (outdated): ```diff @@ -304,6 +318,76 @@ void GameController::SetVibration(uint8_t large_motor, uint8_t small_motor) { } } +void GameController::SetLightBar(uint8_t r, uint8_t g, uint8_t b) { + Common::LockGuard lock(m_mutex); + if (m_active_id < 0) { + return; + } + auto* pad = SDL_GameControllerFromInstanceID(static_cast<SDL_JoystickID>(m_active_id)); + if (pad == nullptr) { + return; + } + // A pad without an LED reports failure; there is nothing to recover from. + (void)SDL_GameControllerSetLED(pad, r, g, b); +} + +// SDL owns its own PS5 output report and rejects ours, so trigger effects go straight to the pad +// over HID. USB is report 0x02 with the payload at offset 1; Bluetooth is 0x31 at offset 2 with a +// CRC32 over an 0xA2 header byte plus the report. Right trigger sits at payload offset 10, left at +// 21, and bits 2 and 3 of the first byte say which to apply - leaving rumble and LED state alone. +void GameController::SetTriggerEffect(const uint8_t* left, const uint8_t* right) { + Common::LockGuard lock(m_mutex); + if (left == nullptr || right == nullptr) { + return; + } + if (!m_hid_tried) { + m_hid_tried = true; + for (const auto product: {0x0ce6, 0x0df2}) { + m_hid = SDL_hid_open(0x054c, static_cast<unsigned short>(product), nullptr); + if (m_hid != nullptr) { + uint8_t probe[78] = {}; + const int read = SDL_hid_read_timeout(m_hid, probe, sizeof(probe), 50); + m_hid_bluetooth = read > 64; + break; + } + } + } + if (m_hid == nullptr) { + return; + } + uint8_t combined[22] = {}; + std::memcpy(combined, right, 11); + std::memcpy(combined + 11, left, 11); + if (m_trigger_sent && std::memcmp(combined, m_last_trigger, sizeof(combined)) == 0) { + return; // titles resend every frame; the pad holds the last effect + } + std::memcpy(m_last_trigger, combined, sizeof(combined)); + m_trigger_sent = true; + uint8_t report[79] = {}; + int size = 0; + int offset = 0; + if (m_hid_bluetooth) { + report[0] = 0x31; + report[1] = 0x02; + size = 78; + offset = 2; + } else { + report[0] = 0x02; + size = 48; + offset = 1; + } + report[offset + 0] = 0x0c; + std::memcpy(report + offset + 10, right, 11); + std::memcpy(report + offset + 21, left, 11); + if (m_hid_bluetooth) { + const uint8_t header = 0xa2; + uint32_t crc = SDL_crc32(0, &header, 1); + crc = SDL_crc32(crc, report, static_cast<size_t>(size) - sizeof(crc)); + std::memcpy(report + size - sizeof(crc), &crc, sizeof(crc)); + } + (void)SDL_hid_write(m_hid, report, static_cast<size_t>(size)); ``` `SDL_hid_write` errors are ignored, and `m_hid_tried` prevents reopening; if the controller disconnects/reconnects, trigger effects may silently stop working for the rest of the session. Capture the return value and on failure close/reset the HID handle so a later call can retry opening.
Author
Owner

@⁠Copilot on GitHub · 2026-09-01 03:09 UTC · original
On src/libs/controller.cpp line 84 (outdated):

@@ -73,6 +80,8 @@ class GameController {
 	void ResetInputState();
 	void GetConnectionInfo(bool* flag, int* count);
 	void SetVibration(uint8_t large_motor, uint8_t small_motor);
+	void SetLightBar(uint8_t r, uint8_t g, uint8_t b);
+	void SetTriggerEffect(const uint8_t* left, const uint8_t* right);

m_hid is opened with SDL_hid_open but never closed, so the process can leak the HID handle across controller shutdown and potentially keep the device busy. Add RAII cleanup (e.g., a destructor) to close the HID device when GameController is destroyed.

**@⁠Copilot** on GitHub · 2026-09-01 03:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/437#discussion_r3900438261) On `src/libs/controller.cpp` line 84 (outdated): ```diff @@ -73,6 +80,8 @@ class GameController { void ResetInputState(); void GetConnectionInfo(bool* flag, int* count); void SetVibration(uint8_t large_motor, uint8_t small_motor); + void SetLightBar(uint8_t r, uint8_t g, uint8_t b); + void SetTriggerEffect(const uint8_t* left, const uint8_t* right); ``` `m_hid` is opened with `SDL_hid_open` but never closed, so the process can leak the HID handle across controller shutdown and potentially keep the device busy. Add RAII cleanup (e.g., a destructor) to close the HID device when `GameController` is destroyed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.