Skip to content

Commit 30225fa

Browse files
authored
FIX: Update DualSense HID support so OutputReports function properly (ISXB-787) (#1900)
* DualSense Edge has a larger OutputReportSize and regular DS controller * Use actual OutputReport side from the HID descriptor instead of hard-coded value
1 parent 596c508 commit 30225fa

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ however, it has to be formatted properly to pass verification tests.
1515
- Physical keyboards used on Android/ChromeOS could have keys "stuck" reporting as pressed after a long press and release [ISXB-475](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-475).
1616
- NullReferenceException thrown when right-clicking an empty Action Map list in Input Actions Editor windows [ISXB-833](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-833).
1717
- Fixed an issue where `System.ObjectDisposedException` would be thrown when deleting the last ActionMap item in the Input Actions Asset editor.
18+
- Fixed DualSense Edge's vibration and light bar not working on Windows
1819

1920
### Changed
2021
- For Unity 6.0 and above, when an `EventSystem` GameObject is created in the Editor it will have the

Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepad.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ public class DualShockGamepad : Gamepad, IDualShockHaptics
8686
/// <summary>
8787
/// The last used/added DualShock controller.
8888
/// </summary>
89+
/// <value>Equivalent to <see cref="Gamepad.leftTrigger"/>.</value>
8990
public new static DualShockGamepad current { get; private set; }
9091

92+
/// <summary>
93+
/// If the controller is connected over HID, returns <see cref="HID.HID.HIDDeviceDescriptor"/> data parsed from <see cref="InputDeviceDescription.capabilities"/>.
94+
/// </summary>
95+
internal HID.HID.HIDDeviceDescriptor hidDescriptor { get; private set; }
96+
9197
/// <inheritdoc />
9298
public override void MakeCurrent()
9399
{
@@ -118,6 +124,9 @@ protected override void FinishSetup()
118124
R2 = rightTrigger;
119125
L3 = leftStickButton;
120126
R3 = rightStickButton;
127+
128+
if (m_Description.capabilities != null && m_Description.interfaceName == "HID")
129+
hidDescriptor = HID.HID.HIDDeviceDescriptor.FromJson(m_Description.capabilities);
121130
}
122131

123132
/// <inheritdoc />

Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockGamepadHID.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ internal struct DualSenseHIDUSBOutputReport : IInputDeviceCommandInfo
9999
[FieldOffset(InputDeviceCommand.BaseCommandSize + 0)] public byte reportId;
100100
[FieldOffset(InputDeviceCommand.BaseCommandSize + 1)] public DualSenseHIDOutputReportPayload payload;
101101

102-
public static DualSenseHIDUSBOutputReport Create(DualSenseHIDOutputReportPayload payload)
102+
public static DualSenseHIDUSBOutputReport Create(DualSenseHIDOutputReportPayload payload, int outputReportSize)
103103
{
104104
return new DualSenseHIDUSBOutputReport
105105
{
106-
baseCommand = new InputDeviceCommand(Type, kSize),
106+
baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + outputReportSize),
107107
reportId = 2,
108108
payload = payload
109109
};
@@ -127,11 +127,11 @@ internal struct DualSenseHIDBluetoothOutputReport : IInputDeviceCommandInfo
127127

128128
[FieldOffset(InputDeviceCommand.BaseCommandSize + 0)] public unsafe fixed byte rawData[74];
129129

130-
public static DualSenseHIDBluetoothOutputReport Create(DualSenseHIDOutputReportPayload payload, byte outputSequenceId)
130+
public static DualSenseHIDBluetoothOutputReport Create(DualSenseHIDOutputReportPayload payload, byte outputSequenceId, int outputReportSize)
131131
{
132132
var report = new DualSenseHIDBluetoothOutputReport
133133
{
134-
baseCommand = new InputDeviceCommand(Type, kSize),
134+
baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + outputReportSize),
135135
reportId = 0x31,
136136
tag1 = (byte)((outputSequenceId & 0xf) << 4),
137137
tag2 = 0x10,
@@ -317,11 +317,11 @@ public void SetColor(Color color)
317317
blueColor = (byte)Mathf.Clamp(color.b * 255, 0, 255);
318318
}
319319

320-
public static DualShockHIDOutputReport Create()
320+
public static DualShockHIDOutputReport Create(int outputReportSize)
321321
{
322322
return new DualShockHIDOutputReport
323323
{
324-
baseCommand = new InputDeviceCommand(Type, kSize),
324+
baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + outputReportSize),
325325
reportId = kReportId,
326326
};
327327
}
@@ -439,7 +439,7 @@ public bool SetMotorSpeedsAndLightBarColor(float? lowFrequency, float? highFrequ
439439

440440
////FIXME: Bluetooth reports are not working
441441
//var command = DualSenseHIDBluetoothOutputReport.Create(payload, ++outputSequenceId);
442-
var command = DualSenseHIDUSBOutputReport.Create(payload);
442+
var command = DualSenseHIDUSBOutputReport.Create(payload, hidDescriptor.outputReportSize);
443443
return ExecuteCommand(ref command) >= 0;
444444
}
445445

@@ -732,7 +732,7 @@ public override void PauseHaptics()
732732
if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue && !m_LightBarColor.HasValue)
733733
return;
734734

735-
var command = DualShockHIDOutputReport.Create();
735+
var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
736736
command.SetMotorSpeeds(0f, 0f);
737737
////REVIEW: when pausing&resuming haptics, you probably don't want the lightbar color to change
738738
if (m_LightBarColor.HasValue)
@@ -746,7 +746,7 @@ public override void ResetHaptics()
746746
if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue && !m_LightBarColor.HasValue)
747747
return;
748748

749-
var command = DualShockHIDOutputReport.Create();
749+
var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
750750
command.SetMotorSpeeds(0f, 0f);
751751
if (m_LightBarColor.HasValue)
752752
command.SetColor(Color.black);
@@ -763,7 +763,7 @@ public override void ResumeHaptics()
763763
if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue && !m_LightBarColor.HasValue)
764764
return;
765765

766-
var command = DualShockHIDOutputReport.Create();
766+
var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
767767

768768
if (m_LowFrequencyMotorSpeed.HasValue || m_HighFrequenceyMotorSpeed.HasValue)
769769
command.SetMotorSpeeds(m_LowFrequencyMotorSpeed.Value, m_HighFrequenceyMotorSpeed.Value);
@@ -777,7 +777,7 @@ public override void ResumeHaptics()
777777

778778
public override void SetLightBarColor(Color color)
779779
{
780-
var command = DualShockHIDOutputReport.Create();
780+
var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
781781
command.SetColor(color);
782782

783783
ExecuteCommand(ref command);
@@ -787,7 +787,7 @@ public override void SetLightBarColor(Color color)
787787

788788
public override void SetMotorSpeeds(float lowFrequency, float highFrequency)
789789
{
790-
var command = DualShockHIDOutputReport.Create();
790+
var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
791791
command.SetMotorSpeeds(lowFrequency, highFrequency);
792792

793793
ExecuteCommand(ref command);
@@ -815,7 +815,7 @@ public override void SetMotorSpeeds(float lowFrequency, float highFrequency)
815815
/// for the respective documentation regarding setting rumble and light bar color.</remarks>
816816
public bool SetMotorSpeedsAndLightBarColor(float lowFrequency, float highFrequency, Color color)
817817
{
818-
var command = DualShockHIDOutputReport.Create();
818+
var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
819819
command.SetMotorSpeeds(lowFrequency, highFrequency);
820820
command.SetColor(color);
821821

0 commit comments

Comments
 (0)