Class DualShock4OutputWriter
Drives vibration AND the LED on a DualShock 4 in a SINGLE HID output report.
Unity's high-level SetMotorSpeeds and SetLightBarColor each send a separate
report that zeroes the other's bytes (the package even flags this with
////FIXME: SetLightBarColor and SetMotorSpeeds to not mutually respect their settings), so
on a DS4 the two effects clobber each other and the auto-reset of one clips the other. The DS4
hardware itself packs vibration and color into one report — only the wrapper splits them, and the
combining struct (DualShockHIDOutputReport) is internal. This writer mirrors that
report in our own Serenity.Feedback.Infrastructure.Services.DualShock4CombinedOutputReport and sends both together via the
public InputDevice.ExecuteCommand, exactly like native titles do. DualSense already
combines internally, so it does not go through here.
Per-device state is the single source of truth: setting motors preserves the current color
and vice-versa, which is what makes the two channels coexist and stops each reset from blanking
the other. Methods return false for non-DS4 pads (and on non-desktop platforms) so callers
fall back to the standard path.
Transport: USB uses Unity's ExecuteCommand (the 32-byte 0x05 report); Bluetooth uses the
reframed 0x11/CRC32 report sent through a raw HID handle (Serenity.Feedback.Infrastructure.Hid.GamepadHidrawTransport) — on
Linux for both buses, and on Windows for Bluetooth only (Unity's built-in DS4 output is inert over
Bluetooth). The bus is detected once and cached. macOS drives USB only.
Implements
Inherited Members
Namespace: Serenity.Feedback.Infrastructure.Services
Assembly: Serenity.UnityFeedback.Infrastructure.dll
Syntax
public class DualShock4OutputWriter : IGamepadOutputBackend
Constructors
DualShock4OutputWriter()
Declaration
public DualShock4OutputWriter()
Methods
TrySetLed(Gamepad, Color)
If pad is a DualShock 4, updates its LED color (preserving the current
motor speeds) and sends the combined report. Returns true when handled.
Declaration
public bool TrySetLed(Gamepad pad, Color color)
Parameters
| Type | Name | Description |
|---|---|---|
| Gamepad | pad | |
| Color | color |
Returns
| Type | Description |
|---|---|
| bool |
TrySetVibration(Gamepad, float, float)
If pad is a DualShock 4, updates its motor speeds (preserving the current
LED color) and sends the combined report. Returns true when handled.
Declaration
public bool TrySetVibration(Gamepad pad, float low, float high)
Parameters
| Type | Name | Description |
|---|---|---|
| Gamepad | pad | |
| float | low | |
| float | high |
Returns
| Type | Description |
|---|---|
| bool |