Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

DualShockGamepadHID.cs 63KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WSA || PACKAGE_DOCS_GENERATION
  2. using System;
  3. using System.Runtime.CompilerServices;
  4. using System.Runtime.InteropServices;
  5. using UnityEngine.InputSystem.Controls;
  6. using UnityEngine.InputSystem.Layouts;
  7. using UnityEngine.InputSystem.LowLevel;
  8. using UnityEngine.InputSystem.DualShock.LowLevel;
  9. using UnityEngine.InputSystem.Utilities;
  10. ////TODO: figure out sensor formats and add support for acceleration, angularVelocity, and orientation (also add to base layout then)
  11. namespace UnityEngine.InputSystem.DualShock.LowLevel
  12. {
  13. /// <summary>
  14. /// This is abstract input report for PS5 DualSense controller, similar to what is on the wire, but not exactly binary matching any state events.
  15. /// See ConvertInputReport for the exact conversion.
  16. /// </summary>
  17. [StructLayout(LayoutKind.Explicit, Size = 9 /* !!! Beware !!! If you plan to increase this, think about how you gonna fit 10 byte state events because we can only shrink events in IEventPreProcessor */)]
  18. internal struct DualSenseHIDInputReport : IInputStateTypeInfo
  19. {
  20. public static FourCC Format = new FourCC('D', 'S', 'V', 'S'); // DualSense Virtual State
  21. public FourCC format => Format;
  22. [InputControl(name = "leftStick", layout = "Stick", format = "VC2B")]
  23. [InputControl(name = "leftStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  24. [InputControl(name = "leftStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  25. [InputControl(name = "leftStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
  26. [InputControl(name = "leftStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  27. [InputControl(name = "leftStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  28. [InputControl(name = "leftStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
  29. [FieldOffset(0)] public byte leftStickX;
  30. [FieldOffset(1)] public byte leftStickY;
  31. [InputControl(name = "rightStick", layout = "Stick", format = "VC2B")]
  32. [InputControl(name = "rightStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  33. [InputControl(name = "rightStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  34. [InputControl(name = "rightStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
  35. [InputControl(name = "rightStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  36. [InputControl(name = "rightStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  37. [InputControl(name = "rightStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
  38. [FieldOffset(2)] public byte rightStickX;
  39. [FieldOffset(3)] public byte rightStickY;
  40. [InputControl(name = "leftTrigger", format = "BYTE")]
  41. [FieldOffset(4)] public byte leftTrigger;
  42. [InputControl(name = "rightTrigger", format = "BYTE")]
  43. [FieldOffset(5)] public byte rightTrigger;
  44. [InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
  45. [InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
  46. [InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
  47. [InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3,maxValue=5", bit = 0, sizeInBits = 4)]
  48. [InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5, maxValue=7", bit = 0, sizeInBits = 4)]
  49. [InputControl(name = "buttonWest", displayName = "Square", bit = 4)]
  50. [InputControl(name = "buttonSouth", displayName = "Cross", bit = 5)]
  51. [InputControl(name = "buttonEast", displayName = "Circle", bit = 6)]
  52. [InputControl(name = "buttonNorth", displayName = "Triangle", bit = 7)]
  53. [FieldOffset(6)] public byte buttons0;
  54. [InputControl(name = "leftShoulder", bit = 0)]
  55. [InputControl(name = "rightShoulder", bit = 1)]
  56. [InputControl(name = "leftTriggerButton", layout = "Button", bit = 2)]
  57. [InputControl(name = "rightTriggerButton", layout = "Button", bit = 3)]
  58. [InputControl(name = "select", displayName = "Share", bit = 4)]
  59. [InputControl(name = "start", displayName = "Options", bit = 5)]
  60. [InputControl(name = "leftStickPress", bit = 6)]
  61. [InputControl(name = "rightStickPress", bit = 7)]
  62. [FieldOffset(7)] public byte buttons1;
  63. [InputControl(name = "systemButton", layout = "Button", displayName = "System", bit = 0)]
  64. [InputControl(name = "touchpadButton", layout = "Button", displayName = "Touchpad Press", bit = 1)]
  65. [InputControl(name = "micButton", layout = "Button", displayName = "Mic Mute", bit = 2)]
  66. [FieldOffset(8)] public byte buttons2;
  67. }
  68. [StructLayout(LayoutKind.Explicit, Size = 47)]
  69. internal struct DualSenseHIDOutputReportPayload
  70. {
  71. [FieldOffset(0)] public byte enableFlags1;
  72. [FieldOffset(1)] public byte enableFlags2;
  73. [FieldOffset(2)] public byte highFrequencyMotorSpeed;
  74. [FieldOffset(3)] public byte lowFrequencyMotorSpeed;
  75. [FieldOffset(44)] public byte redColor;
  76. [FieldOffset(45)] public byte greenColor;
  77. [FieldOffset(46)] public byte blueColor;
  78. }
  79. [StructLayout(LayoutKind.Explicit, Size = kSize)]
  80. internal struct DualSenseHIDUSBOutputReport : IInputDeviceCommandInfo
  81. {
  82. public static FourCC Type => new FourCC('H', 'I', 'D', 'O');
  83. public FourCC typeStatic => Type;
  84. internal const int kSize = InputDeviceCommand.BaseCommandSize + 48;
  85. [FieldOffset(0)] public InputDeviceCommand baseCommand;
  86. [FieldOffset(InputDeviceCommand.BaseCommandSize + 0)] public byte reportId;
  87. [FieldOffset(InputDeviceCommand.BaseCommandSize + 1)] public DualSenseHIDOutputReportPayload payload;
  88. public static DualSenseHIDUSBOutputReport Create(DualSenseHIDOutputReportPayload payload, int outputReportSize)
  89. {
  90. return new DualSenseHIDUSBOutputReport
  91. {
  92. baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + outputReportSize),
  93. reportId = 2,
  94. payload = payload
  95. };
  96. }
  97. }
  98. [StructLayout(LayoutKind.Explicit, Size = kSize)]
  99. internal struct DualSenseHIDBluetoothOutputReport : IInputDeviceCommandInfo
  100. {
  101. public static FourCC Type => new FourCC('H', 'I', 'D', 'O');
  102. public FourCC typeStatic => Type;
  103. internal const int kSize = InputDeviceCommand.BaseCommandSize + 78;
  104. [FieldOffset(0)] public InputDeviceCommand baseCommand;
  105. [FieldOffset(InputDeviceCommand.BaseCommandSize + 0)] public byte reportId;
  106. [FieldOffset(InputDeviceCommand.BaseCommandSize + 1)] public byte tag1;
  107. [FieldOffset(InputDeviceCommand.BaseCommandSize + 2)] public byte tag2;
  108. [FieldOffset(InputDeviceCommand.BaseCommandSize + 3)] public DualSenseHIDOutputReportPayload payload;
  109. [FieldOffset(InputDeviceCommand.BaseCommandSize + 74)] public uint crc32;
  110. [FieldOffset(InputDeviceCommand.BaseCommandSize + 0)] public unsafe fixed byte rawData[74];
  111. public static DualSenseHIDBluetoothOutputReport Create(DualSenseHIDOutputReportPayload payload, byte outputSequenceId, int outputReportSize)
  112. {
  113. var report = new DualSenseHIDBluetoothOutputReport
  114. {
  115. baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + outputReportSize),
  116. reportId = 0x31,
  117. tag1 = (byte)((outputSequenceId & 0xf) << 4),
  118. tag2 = 0x10,
  119. payload = payload
  120. };
  121. ////FIXME: Calculate crc32 correctly
  122. return report;
  123. }
  124. }
  125. /// <summary>
  126. /// Structure of HID input reports for PS4 DualShock 4 controllers.
  127. /// </summary>
  128. [StructLayout(LayoutKind.Explicit, Size = 9 /* !!! Beware !!! If you plan to increase this, think about how you gonna fit 10 byte state events because we can only shrink events in IEventPreProcessor */)]
  129. internal struct DualShock4HIDInputReport : IInputStateTypeInfo
  130. {
  131. public static FourCC Format = new FourCC('D', '4', 'V', 'S'); // DualShock4 Virtual State
  132. public FourCC format => Format;
  133. [InputControl(name = "leftStick", layout = "Stick", format = "VC2B")]
  134. [InputControl(name = "leftStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  135. [InputControl(name = "leftStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  136. [InputControl(name = "leftStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
  137. [InputControl(name = "leftStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  138. [InputControl(name = "leftStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  139. [InputControl(name = "leftStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
  140. [FieldOffset(0)] public byte leftStickX;
  141. [FieldOffset(1)] public byte leftStickY;
  142. [InputControl(name = "rightStick", layout = "Stick", format = "VC2B")]
  143. [InputControl(name = "rightStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  144. [InputControl(name = "rightStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  145. [InputControl(name = "rightStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
  146. [InputControl(name = "rightStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  147. [InputControl(name = "rightStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  148. [InputControl(name = "rightStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
  149. [FieldOffset(2)] public byte rightStickX;
  150. [FieldOffset(3)] public byte rightStickY;
  151. [InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
  152. [InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
  153. [InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
  154. [InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3,maxValue=5", bit = 0, sizeInBits = 4)]
  155. [InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5, maxValue=7", bit = 0, sizeInBits = 4)]
  156. [InputControl(name = "buttonWest", displayName = "Square", bit = 4)]
  157. [InputControl(name = "buttonSouth", displayName = "Cross", bit = 5)]
  158. [InputControl(name = "buttonEast", displayName = "Circle", bit = 6)]
  159. [InputControl(name = "buttonNorth", displayName = "Triangle", bit = 7)]
  160. [FieldOffset(4)] public byte buttons1;
  161. [InputControl(name = "leftShoulder", bit = 0)]
  162. [InputControl(name = "rightShoulder", bit = 1)]
  163. [InputControl(name = "leftTriggerButton", layout = "Button", bit = 2, synthetic = true)]
  164. [InputControl(name = "rightTriggerButton", layout = "Button", bit = 3, synthetic = true)]
  165. [InputControl(name = "select", displayName = "Share", bit = 4)]
  166. [InputControl(name = "start", displayName = "Options", bit = 5)]
  167. [InputControl(name = "leftStickPress", bit = 6)]
  168. [InputControl(name = "rightStickPress", bit = 7)]
  169. [FieldOffset(5)] public byte buttons2;
  170. [InputControl(name = "systemButton", layout = "Button", displayName = "System", bit = 0)]
  171. [InputControl(name = "touchpadButton", layout = "Button", displayName = "Touchpad Press", bit = 1)]
  172. [FieldOffset(6)] public byte buttons3;
  173. [InputControl(name = "leftTrigger", format = "BYTE")]
  174. [FieldOffset(7)] public byte leftTrigger;
  175. [InputControl(name = "rightTrigger", format = "BYTE")]
  176. [FieldOffset(8)] public byte rightTrigger;
  177. }
  178. /// <summary>
  179. /// Structure of HID input reports for PS3 DualShock 3 controllers.
  180. /// </summary>
  181. [StructLayout(LayoutKind.Explicit, Size = 32)]
  182. internal unsafe struct DualShock3HIDInputReport : IInputStateTypeInfo
  183. {
  184. [FieldOffset(0)] private ushort padding1;
  185. [InputControl(name = "select", displayName = "Share", bit = 0)]
  186. [InputControl(name = "leftStickPress", bit = 1)]
  187. [InputControl(name = "rightStickPress", bit = 2)]
  188. [InputControl(name = "start", displayName = "Options", bit = 3)]
  189. [InputControl(name = "dpad", format = "BIT", layout = "Dpad", bit = 4, sizeInBits = 4)]
  190. [InputControl(name = "dpad/up", bit = 4)]
  191. [InputControl(name = "dpad/right", bit = 5)]
  192. [InputControl(name = "dpad/down", bit = 6)]
  193. [InputControl(name = "dpad/left", bit = 7)]
  194. [FieldOffset(2)] public byte buttons1;
  195. [InputControl(name = "leftTriggerButton", layout = "Button", bit = 0, synthetic = true)]
  196. [InputControl(name = "rightTriggerButton", layout = "Button", bit = 1, synthetic = true)]
  197. [InputControl(name = "leftShoulder", bit = 2)]
  198. [InputControl(name = "rightShoulder", bit = 3)]
  199. [InputControl(name = "buttonNorth", displayName = "Triangle", bit = 4)]
  200. [InputControl(name = "buttonEast", displayName = "Circle", bit = 5)]
  201. [InputControl(name = "buttonSouth", displayName = "Cross", bit = 6)]
  202. [InputControl(name = "buttonWest", displayName = "Square", bit = 7)]
  203. [FieldOffset(3)] public byte buttons2;
  204. [InputControl(name = "systemButton", layout = "Button", displayName = "System", bit = 0)]
  205. [InputControl(name = "touchpadButton", layout = "Button", displayName = "Touchpad Press", bit = 1)] // always 0, does not exist on DualShock 3
  206. [FieldOffset(4)] public byte buttons3;
  207. [FieldOffset(5)] private byte padding2;
  208. [InputControl(name = "leftStick", layout = "Stick", format = "VC2B")]
  209. [InputControl(name = "leftStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  210. [InputControl(name = "leftStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  211. [InputControl(name = "leftStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
  212. [InputControl(name = "leftStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  213. [InputControl(name = "leftStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  214. [InputControl(name = "leftStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
  215. [FieldOffset(6)] public byte leftStickX;
  216. [FieldOffset(7)] public byte leftStickY;
  217. [InputControl(name = "rightStick", layout = "Stick", format = "VC2B")]
  218. [InputControl(name = "rightStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  219. [InputControl(name = "rightStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  220. [InputControl(name = "rightStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
  221. [InputControl(name = "rightStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
  222. [InputControl(name = "rightStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
  223. [InputControl(name = "rightStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
  224. [FieldOffset(8)] public byte rightStickX;
  225. [FieldOffset(9)] public byte rightStickY;
  226. [FieldOffset(10)] private fixed byte padding3[8];
  227. [InputControl(name = "leftTrigger", format = "BYTE")]
  228. [FieldOffset(18)] public byte leftTrigger;
  229. [InputControl(name = "rightTrigger", format = "BYTE")]
  230. [FieldOffset(19)] public byte rightTrigger;
  231. public FourCC format
  232. {
  233. get { return new FourCC('H', 'I', 'D'); }
  234. }
  235. }
  236. /// <summary>
  237. /// PS4 output report sent as command to HID backend.
  238. /// </summary>
  239. [StructLayout(LayoutKind.Explicit, Size = kSize)]
  240. internal unsafe struct DualShockHIDOutputReport : IInputDeviceCommandInfo
  241. {
  242. public static FourCC Type => new FourCC('H', 'I', 'D', 'O');
  243. internal const int kSize = InputDeviceCommand.kBaseCommandSize + 32;
  244. internal const int kReportId = 5;
  245. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags", Justification = "No better term for underlying data.")]
  246. [Flags]
  247. public enum Flags
  248. {
  249. Rumble = 0x1,
  250. Color = 0x2
  251. }
  252. [FieldOffset(0)] public InputDeviceCommand baseCommand;
  253. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 0)] public byte reportId;
  254. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "flags", Justification = "No better term for underlying data.")]
  255. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 1)] public byte flags;
  256. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 2)] public fixed byte unknown1[2];
  257. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 4)] public byte highFrequencyMotorSpeed;
  258. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 5)] public byte lowFrequencyMotorSpeed;
  259. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 6)] public byte redColor;
  260. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 7)] public byte greenColor;
  261. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 8)] public byte blueColor;
  262. [FieldOffset(InputDeviceCommand.kBaseCommandSize + 9)] public fixed byte unknown2[23];
  263. public FourCC typeStatic => Type;
  264. public void SetMotorSpeeds(float lowFreq, float highFreq)
  265. {
  266. flags |= (byte)Flags.Rumble;
  267. lowFrequencyMotorSpeed = (byte)Mathf.Clamp(lowFreq * 255, 0, 255);
  268. highFrequencyMotorSpeed = (byte)Mathf.Clamp(highFreq * 255, 0, 255);
  269. }
  270. public void SetColor(Color color)
  271. {
  272. flags |= (byte)Flags.Color;
  273. redColor = (byte)Mathf.Clamp(color.r * 255, 0, 255);
  274. greenColor = (byte)Mathf.Clamp(color.g * 255, 0, 255);
  275. blueColor = (byte)Mathf.Clamp(color.b * 255, 0, 255);
  276. }
  277. public static DualShockHIDOutputReport Create(int outputReportSize)
  278. {
  279. return new DualShockHIDOutputReport
  280. {
  281. baseCommand = new InputDeviceCommand(Type, InputDeviceCommand.kBaseCommandSize + outputReportSize),
  282. reportId = kReportId,
  283. };
  284. }
  285. }
  286. }
  287. namespace UnityEngine.InputSystem.DualShock
  288. {
  289. /// <summary>
  290. /// PS5 DualSense controller that is interfaced to a HID backend.
  291. /// </summary>
  292. [InputControlLayout(stateType = typeof(DualSenseHIDInputReport), displayName = "DualSense HID")]
  293. public class DualSenseGamepadHID : DualShockGamepad, IEventMerger, IEventPreProcessor, IInputStateCallbackReceiver
  294. {
  295. // Gamepad might send 3 types of input reports:
  296. // - Minimal report, first byte is 0x01, observed size is 78, also can be 10
  297. // - Full USB report, first byte is 0x01, observed size is 64
  298. // - Full Bluetooth report, first byte is 0x31, observed size 78
  299. // While USB and Bluetooth reports only differ in header,
  300. // Minimal report also differs in order of fields (buttons -> triggers vs triggers -> buttons).
  301. public ButtonControl leftTriggerButton { get; protected set; }
  302. public ButtonControl rightTriggerButton { get; protected set; }
  303. public ButtonControl playStationButton { get; protected set; }
  304. private float? m_LowFrequencyMotorSpeed;
  305. private float? m_HighFrequenceyMotorSpeed;
  306. private Color? m_LightBarColor;
  307. private byte outputSequenceId;
  308. protected override void FinishSetup()
  309. {
  310. leftTriggerButton = GetChildControl<ButtonControl>("leftTriggerButton");
  311. rightTriggerButton = GetChildControl<ButtonControl>("rightTriggerButton");
  312. playStationButton = GetChildControl<ButtonControl>("systemButton");
  313. base.FinishSetup();
  314. }
  315. public override void PauseHaptics()
  316. {
  317. if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue)
  318. return;
  319. SetMotorSpeedsAndLightBarColor(0.0f, 0.0f, m_LightBarColor);
  320. }
  321. public override void ResetHaptics()
  322. {
  323. if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue)
  324. return;
  325. m_HighFrequenceyMotorSpeed = null;
  326. m_LowFrequencyMotorSpeed = null;
  327. SetMotorSpeedsAndLightBarColor(m_LowFrequencyMotorSpeed, m_HighFrequenceyMotorSpeed, m_LightBarColor);
  328. }
  329. public override void ResumeHaptics()
  330. {
  331. if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue)
  332. return;
  333. SetMotorSpeedsAndLightBarColor(m_LowFrequencyMotorSpeed, m_HighFrequenceyMotorSpeed, m_LightBarColor);
  334. }
  335. public override void SetLightBarColor(Color color)
  336. {
  337. m_LightBarColor = color;
  338. SetMotorSpeedsAndLightBarColor(m_LowFrequencyMotorSpeed, m_HighFrequenceyMotorSpeed, m_LightBarColor);
  339. }
  340. public override void SetMotorSpeeds(float lowFrequency, float highFrequency)
  341. {
  342. m_LowFrequencyMotorSpeed = lowFrequency;
  343. m_HighFrequenceyMotorSpeed = highFrequency;
  344. SetMotorSpeedsAndLightBarColor(m_LowFrequencyMotorSpeed, m_HighFrequenceyMotorSpeed, m_LightBarColor);
  345. }
  346. /// <summary>
  347. /// Set motor speeds of both motors and the light bar color simultaneously.
  348. /// </summary>
  349. /// <param name="lowFrequency"><see cref="Haptics.IDualMotorRumble.SetMotorSpeeds"/></param>
  350. /// <param name="highFrequency"><see cref="Haptics.IDualMotorRumble.SetMotorSpeeds"/></param>
  351. /// <param name="color"><see cref="IDualShockHaptics.SetLightBarColor"/></param>
  352. /// <returns>True if the command succeeded. Will return false if another command is currently being processed.</returns>
  353. /// <remarks>
  354. /// Use this method to set both the motor speeds and the light bar color in the same call. This method exists
  355. /// because it is currently not possible to process an input/output control (IOCTL) command while another one
  356. /// is in flight. For example, calling <see cref="SetMotorSpeeds"/> immediately after calling
  357. /// <see cref="SetLightBarColor"/> might result in only the light bar color changing. The <see cref="SetMotorSpeeds"/>
  358. /// call could fail. It is however possible to combine multiple IOCTL instructions into a single command, which
  359. /// is what this method does.
  360. ///
  361. /// See <see cref="Haptics.IDualMotorRumble.SetMotorSpeeds"/> and <see cref="IDualShockHaptics.SetLightBarColor"/>
  362. /// for the respective documentation regarding setting rumble and light bar color.</remarks>
  363. public bool SetMotorSpeedsAndLightBarColor(float? lowFrequency, float? highFrequency, Color? color)
  364. {
  365. var lf = lowFrequency.HasValue ? lowFrequency.Value : 0;
  366. var hf = highFrequency.HasValue ? highFrequency.Value : 0;
  367. var c = color.HasValue ? color.Value : Color.black;
  368. // DualSense differs a bit from DualShock 4 because all effects need to be set at a same time,
  369. // otherwise setting just a color would disable motor rumble.
  370. var payload = new DualSenseHIDOutputReportPayload
  371. {
  372. enableFlags1 = 0x1 | // Enable motor rumble.
  373. 0x2, // Disable haptics.
  374. enableFlags2 = 0x4, // Enable LEDs color.
  375. lowFrequencyMotorSpeed = (byte)NumberHelpers.NormalizedFloatToUInt(lf, byte.MinValue, byte.MaxValue),
  376. highFrequencyMotorSpeed = (byte)NumberHelpers.NormalizedFloatToUInt(hf, byte.MinValue, byte.MaxValue),
  377. redColor = (byte)NumberHelpers.NormalizedFloatToUInt(c.r, byte.MinValue, byte.MaxValue),
  378. greenColor = (byte)NumberHelpers.NormalizedFloatToUInt(c.g, byte.MinValue, byte.MaxValue),
  379. blueColor = (byte)NumberHelpers.NormalizedFloatToUInt(c.b, byte.MinValue, byte.MaxValue)
  380. };
  381. ////FIXME: Bluetooth reports are not working
  382. //var command = DualSenseHIDBluetoothOutputReport.Create(payload, ++outputSequenceId);
  383. var command = DualSenseHIDUSBOutputReport.Create(payload, hidDescriptor.outputReportSize);
  384. return ExecuteCommand(ref command) >= 0;
  385. }
  386. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  387. private static unsafe bool MergeForward(DualSenseHIDUSBInputReport* currentState, DualSenseHIDUSBInputReport* nextState)
  388. {
  389. return currentState->buttons0 == nextState->buttons0 && currentState->buttons1 == nextState->buttons1 &&
  390. currentState->buttons2 == nextState->buttons2;
  391. }
  392. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  393. private static unsafe bool MergeForward(DualSenseHIDBluetoothInputReport* currentState, DualSenseHIDBluetoothInputReport* nextState)
  394. {
  395. return currentState->buttons0 == nextState->buttons0 && currentState->buttons1 == nextState->buttons1 &&
  396. currentState->buttons2 == nextState->buttons2;
  397. }
  398. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  399. private static unsafe bool MergeForward(DualSenseHIDMinimalInputReport* currentState, DualSenseHIDMinimalInputReport* nextState)
  400. {
  401. return currentState->buttons0 == nextState->buttons0 && currentState->buttons1 == nextState->buttons1 &&
  402. currentState->buttons2 == nextState->buttons2;
  403. }
  404. unsafe bool IEventMerger.MergeForward(InputEventPtr currentEventPtr, InputEventPtr nextEventPtr)
  405. {
  406. if (currentEventPtr.type != StateEvent.Type || nextEventPtr.type != StateEvent.Type)
  407. return false;
  408. var currentEvent = StateEvent.FromUnchecked(currentEventPtr);
  409. var nextEvent = StateEvent.FromUnchecked(nextEventPtr);
  410. if (currentEvent->stateFormat != DualSenseHIDGenericInputReport.Format || nextEvent->stateFormat != DualSenseHIDGenericInputReport.Format)
  411. return false;
  412. if (currentEvent->stateSizeInBytes != nextEvent->stateSizeInBytes)
  413. return false;
  414. var currentGenericReport = (DualSenseHIDGenericInputReport*)currentEvent->state;
  415. var nextGenericReport = (DualSenseHIDGenericInputReport*)nextEvent->state;
  416. if (currentGenericReport->reportId != nextGenericReport->reportId)
  417. return false;
  418. if (currentGenericReport->reportId == DualSenseHIDUSBInputReport.ExpectedReportId)
  419. {
  420. if (currentEvent->stateSizeInBytes == DualSenseHIDMinimalInputReport.ExpectedSize1 ||
  421. currentEvent->stateSizeInBytes == DualSenseHIDMinimalInputReport.ExpectedSize2)
  422. {
  423. var currentState = (DualSenseHIDMinimalInputReport*)currentEvent->state;
  424. var nextState = (DualSenseHIDMinimalInputReport*)nextEvent->state;
  425. return MergeForward(currentState, nextState);
  426. }
  427. else
  428. {
  429. var currentState = (DualSenseHIDUSBInputReport*)currentEvent->state;
  430. var nextState = (DualSenseHIDUSBInputReport*)nextEvent->state;
  431. return MergeForward(currentState, nextState);
  432. }
  433. }
  434. else if (currentGenericReport->reportId == DualSenseHIDBluetoothInputReport.ExpectedReportId)
  435. {
  436. var currentState = (DualSenseHIDBluetoothInputReport*)currentEvent->state;
  437. var nextState = (DualSenseHIDBluetoothInputReport*)nextEvent->state;
  438. return MergeForward(currentState, nextState);
  439. }
  440. else
  441. return false;
  442. }
  443. unsafe bool IEventPreProcessor.PreProcessEvent(InputEventPtr eventPtr)
  444. {
  445. if (eventPtr.type != StateEvent.Type)
  446. return eventPtr.type != DeltaStateEvent.Type; // only skip delta state events
  447. var stateEvent = StateEvent.FromUnchecked(eventPtr);
  448. if (stateEvent->stateFormat == DualSenseHIDInputReport.Format)
  449. return true; // if someone queued DSVS directly, just use as-is
  450. var size = stateEvent->stateSizeInBytes;
  451. if (stateEvent->stateFormat != DualSenseHIDGenericInputReport.Format || size < sizeof(DualSenseHIDInputReport))
  452. return false; // skip unrecognized state events otherwise they will corrupt control states
  453. var genericReport = (DualSenseHIDGenericInputReport*)stateEvent->state;
  454. if (genericReport->reportId == DualSenseHIDUSBInputReport.ExpectedReportId)
  455. {
  456. if (stateEvent->stateSizeInBytes == DualSenseHIDMinimalInputReport.ExpectedSize1 ||
  457. stateEvent->stateSizeInBytes == DualSenseHIDMinimalInputReport.ExpectedSize2)
  458. {
  459. // minimal report
  460. var data = ((DualSenseHIDMinimalInputReport*)stateEvent->state)->ToHIDInputReport();
  461. *((DualSenseHIDInputReport*)stateEvent->state) = data;
  462. }
  463. else
  464. {
  465. var data = ((DualSenseHIDUSBInputReport*)stateEvent->state)->ToHIDInputReport();
  466. *((DualSenseHIDInputReport*)stateEvent->state) = data;
  467. }
  468. stateEvent->stateFormat = DualSenseHIDInputReport.Format;
  469. return true;
  470. }
  471. else if (genericReport->reportId == DualSenseHIDBluetoothInputReport.ExpectedReportId)
  472. {
  473. var data = ((DualSenseHIDBluetoothInputReport*)stateEvent->state)->ToHIDInputReport();
  474. *((DualSenseHIDInputReport*)stateEvent->state) = data;
  475. stateEvent->stateFormat = DualSenseHIDInputReport.Format;
  476. return true;
  477. }
  478. else
  479. return false; // skip unrecognized reportId
  480. }
  481. public void OnNextUpdate()
  482. {
  483. }
  484. // filter out three lower bits as jitter noise
  485. internal const byte JitterMaskLow = 0b01111000;
  486. internal const byte JitterMaskHigh = 0b10000111;
  487. public unsafe void OnStateEvent(InputEventPtr eventPtr)
  488. {
  489. if (eventPtr.type == StateEvent.Type && eventPtr.stateFormat == DualSenseHIDInputReport.Format)
  490. {
  491. var currentState = (DualSenseHIDInputReport*)((byte*)currentStatePtr + m_StateBlock.byteOffset);
  492. var newState = (DualSenseHIDInputReport*)StateEvent.FromUnchecked(eventPtr)->state;
  493. var actuated =
  494. // we need to make device current if axes are outside of deadzone specifying hardware jitter of sticks around zero point
  495. newState->leftStickX<JitterMaskLow
  496. || newState->leftStickX> JitterMaskHigh
  497. || newState->leftStickY<JitterMaskLow
  498. || newState->leftStickY> JitterMaskHigh
  499. || newState->rightStickX<JitterMaskLow
  500. || newState->rightStickX> JitterMaskHigh
  501. || newState->rightStickY<JitterMaskLow
  502. || newState->rightStickY> JitterMaskHigh
  503. // we need to make device current if triggers or buttons state change
  504. || newState->leftTrigger != currentState->leftTrigger
  505. || newState->rightTrigger != currentState->rightTrigger
  506. || newState->buttons0 != currentState->buttons0
  507. || newState->buttons1 != currentState->buttons1
  508. || newState->buttons2 != currentState->buttons2;
  509. if (!actuated)
  510. InputSystem.s_Manager.DontMakeCurrentlyUpdatingDeviceCurrent();
  511. }
  512. InputState.Change(this, eventPtr);
  513. }
  514. public bool GetStateOffsetForEvent(InputControl control, InputEventPtr eventPtr, ref uint offset)
  515. {
  516. return false;
  517. }
  518. [StructLayout(LayoutKind.Explicit)]
  519. internal struct DualSenseHIDGenericInputReport
  520. {
  521. public static FourCC Format => new FourCC('H', 'I', 'D');
  522. [FieldOffset(0)] public byte reportId;
  523. }
  524. [StructLayout(LayoutKind.Explicit)]
  525. internal struct DualSenseHIDUSBInputReport
  526. {
  527. public const int ExpectedReportId = 0x01;
  528. [FieldOffset(0)] public byte reportId;
  529. [FieldOffset(1)] public byte leftStickX;
  530. [FieldOffset(2)] public byte leftStickY;
  531. [FieldOffset(3)] public byte rightStickX;
  532. [FieldOffset(4)] public byte rightStickY;
  533. [FieldOffset(5)] public byte leftTrigger;
  534. [FieldOffset(6)] public byte rightTrigger;
  535. [FieldOffset(8)] public byte buttons0;
  536. [FieldOffset(9)] public byte buttons1;
  537. [FieldOffset(10)] public byte buttons2;
  538. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  539. public DualSenseHIDInputReport ToHIDInputReport()
  540. {
  541. return new DualSenseHIDInputReport
  542. {
  543. leftStickX = leftStickX,
  544. leftStickY = leftStickY,
  545. rightStickX = rightStickX,
  546. rightStickY = rightStickY,
  547. leftTrigger = leftTrigger,
  548. rightTrigger = rightTrigger,
  549. buttons0 = buttons0,
  550. buttons1 = buttons1,
  551. buttons2 = (byte)(buttons2 & 0x07)
  552. };
  553. }
  554. }
  555. [StructLayout(LayoutKind.Explicit)]
  556. internal struct DualSenseHIDBluetoothInputReport
  557. {
  558. public const int ExpectedReportId = 0x31;
  559. [FieldOffset(0)] public byte reportId;
  560. [FieldOffset(2)] public byte leftStickX;
  561. [FieldOffset(3)] public byte leftStickY;
  562. [FieldOffset(4)] public byte rightStickX;
  563. [FieldOffset(5)] public byte rightStickY;
  564. [FieldOffset(6)] public byte leftTrigger;
  565. [FieldOffset(7)] public byte rightTrigger;
  566. [FieldOffset(9)] public byte buttons0;
  567. [FieldOffset(10)] public byte buttons1;
  568. [FieldOffset(11)] public byte buttons2;
  569. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  570. public DualSenseHIDInputReport ToHIDInputReport()
  571. {
  572. return new DualSenseHIDInputReport
  573. {
  574. leftStickX = leftStickX,
  575. leftStickY = leftStickY,
  576. rightStickX = rightStickX,
  577. rightStickY = rightStickY,
  578. leftTrigger = leftTrigger,
  579. rightTrigger = rightTrigger,
  580. buttons0 = buttons0,
  581. buttons1 = buttons1,
  582. buttons2 = (byte)(buttons2 & 0x07)
  583. };
  584. }
  585. }
  586. [StructLayout(LayoutKind.Explicit)]
  587. internal struct DualSenseHIDMinimalInputReport
  588. {
  589. public static int ExpectedSize1 = 10;
  590. public static int ExpectedSize2 = 78;
  591. [FieldOffset(0)] public byte reportId;
  592. [FieldOffset(1)] public byte leftStickX;
  593. [FieldOffset(2)] public byte leftStickY;
  594. [FieldOffset(3)] public byte rightStickX;
  595. [FieldOffset(4)] public byte rightStickY;
  596. [FieldOffset(5)] public byte buttons0;
  597. [FieldOffset(6)] public byte buttons1;
  598. [FieldOffset(7)] public byte buttons2;
  599. [FieldOffset(8)] public byte leftTrigger;
  600. [FieldOffset(9)] public byte rightTrigger;
  601. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  602. public DualSenseHIDInputReport ToHIDInputReport()
  603. {
  604. return new DualSenseHIDInputReport
  605. {
  606. leftStickX = leftStickX,
  607. leftStickY = leftStickY,
  608. rightStickX = rightStickX,
  609. rightStickY = rightStickY,
  610. leftTrigger = leftTrigger,
  611. rightTrigger = rightTrigger,
  612. buttons0 = buttons0,
  613. buttons1 = buttons1,
  614. buttons2 = (byte)(buttons2 & 0x03) // higher bits seem to contain random data, and mic button is not supported
  615. };
  616. }
  617. }
  618. }
  619. /// <summary>
  620. /// PS4 DualShock controller that is interfaced to a HID backend.
  621. /// </summary>
  622. [InputControlLayout(stateType = typeof(DualShock4HIDInputReport), hideInUI = true, isNoisy = true)]
  623. public class DualShock4GamepadHID : DualShockGamepad, IEventPreProcessor, IInputStateCallbackReceiver
  624. {
  625. public ButtonControl leftTriggerButton { get; protected set; }
  626. public ButtonControl rightTriggerButton { get; protected set; }
  627. public ButtonControl playStationButton { get; protected set; }
  628. protected override void FinishSetup()
  629. {
  630. leftTriggerButton = GetChildControl<ButtonControl>("leftTriggerButton");
  631. rightTriggerButton = GetChildControl<ButtonControl>("rightTriggerButton");
  632. playStationButton = GetChildControl<ButtonControl>("systemButton");
  633. base.FinishSetup();
  634. }
  635. public override void PauseHaptics()
  636. {
  637. if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue && !m_LightBarColor.HasValue)
  638. return;
  639. var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
  640. command.SetMotorSpeeds(0f, 0f);
  641. ////REVIEW: when pausing&resuming haptics, you probably don't want the lightbar color to change
  642. if (m_LightBarColor.HasValue)
  643. command.SetColor(Color.black);
  644. ExecuteCommand(ref command);
  645. }
  646. public override void ResetHaptics()
  647. {
  648. if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue && !m_LightBarColor.HasValue)
  649. return;
  650. var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
  651. command.SetMotorSpeeds(0f, 0f);
  652. if (m_LightBarColor.HasValue)
  653. command.SetColor(Color.black);
  654. ExecuteCommand(ref command);
  655. m_HighFrequenceyMotorSpeed = null;
  656. m_LowFrequencyMotorSpeed = null;
  657. m_LightBarColor = null;
  658. }
  659. public override void ResumeHaptics()
  660. {
  661. if (!m_LowFrequencyMotorSpeed.HasValue && !m_HighFrequenceyMotorSpeed.HasValue && !m_LightBarColor.HasValue)
  662. return;
  663. var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
  664. if (m_LowFrequencyMotorSpeed.HasValue || m_HighFrequenceyMotorSpeed.HasValue)
  665. command.SetMotorSpeeds(m_LowFrequencyMotorSpeed.Value, m_HighFrequenceyMotorSpeed.Value);
  666. if (m_LightBarColor.HasValue)
  667. command.SetColor(m_LightBarColor.Value);
  668. ExecuteCommand(ref command);
  669. }
  670. ////FIXME: SetLightBarColor and SetMotorSpeeds to not mutually respect their settings
  671. public override void SetLightBarColor(Color color)
  672. {
  673. var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
  674. command.SetColor(color);
  675. ExecuteCommand(ref command);
  676. m_LightBarColor = color;
  677. }
  678. public override void SetMotorSpeeds(float lowFrequency, float highFrequency)
  679. {
  680. var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
  681. command.SetMotorSpeeds(lowFrequency, highFrequency);
  682. ExecuteCommand(ref command);
  683. m_LowFrequencyMotorSpeed = lowFrequency;
  684. m_HighFrequenceyMotorSpeed = highFrequency;
  685. }
  686. /// <summary>
  687. /// Set motor speeds of both motors and the light bar color simultaneously.
  688. /// </summary>
  689. /// <param name="lowFrequency"><see cref="Haptics.IDualMotorRumble.SetMotorSpeeds"/></param>
  690. /// <param name="highFrequency"><see cref="Haptics.IDualMotorRumble.SetMotorSpeeds"/></param>
  691. /// <param name="color"><see cref="IDualShockHaptics.SetLightBarColor"/></param>
  692. /// <returns>True if the command succeeded. Will return false if another command is currently being processed.</returns>
  693. /// <remarks>
  694. /// Use this method to set both the motor speeds and the light bar color in the same call. This method exists
  695. /// because it is currently not possible to process an input/output control (IOCTL) command while another one
  696. /// is in flight. For example, calling <see cref="SetMotorSpeeds"/> immediately after calling
  697. /// <see cref="SetLightBarColor"/> might result in only the light bar color changing. The <see cref="SetMotorSpeeds"/>
  698. /// call could fail. It is however possible to combine multiple IOCTL instructions into a single command, which
  699. /// is what this method does.
  700. ///
  701. /// See <see cref="Haptics.IDualMotorRumble.SetMotorSpeeds"/> and <see cref="IDualShockHaptics.SetLightBarColor"/>
  702. /// for the respective documentation regarding setting rumble and light bar color.</remarks>
  703. public bool SetMotorSpeedsAndLightBarColor(float lowFrequency, float highFrequency, Color color)
  704. {
  705. var command = DualShockHIDOutputReport.Create(hidDescriptor.outputReportSize);
  706. command.SetMotorSpeeds(lowFrequency, highFrequency);
  707. command.SetColor(color);
  708. var result = ExecuteCommand(ref command);
  709. m_LowFrequencyMotorSpeed = lowFrequency;
  710. m_HighFrequenceyMotorSpeed = highFrequency;
  711. m_LightBarColor = color;
  712. return result >= 0;
  713. }
  714. private float? m_LowFrequencyMotorSpeed;
  715. private float? m_HighFrequenceyMotorSpeed;
  716. private Color? m_LightBarColor;
  717. unsafe bool IEventPreProcessor.PreProcessEvent(InputEventPtr eventPtr)
  718. {
  719. if (eventPtr.type != StateEvent.Type)
  720. return eventPtr.type != DeltaStateEvent.Type; // only skip delta state events
  721. var stateEvent = StateEvent.FromUnchecked(eventPtr);
  722. if (stateEvent->stateFormat == DualShock4HIDInputReport.Format)
  723. return true; // if someone queued D4VS directly, just use as-is
  724. var size = stateEvent->stateSizeInBytes;
  725. if (stateEvent->stateFormat != DualShock4HIDGenericInputReport.Format || size < sizeof(DualShock4HIDGenericInputReport))
  726. return false; // skip unrecognized state events otherwise they will corrupt control states
  727. var binaryData = (byte*)stateEvent->state;
  728. switch (binaryData[0])
  729. {
  730. // normal USB or non-enhanced report
  731. case 1:
  732. {
  733. if (size < sizeof(DualShock4HIDGenericInputReport) + 1)
  734. return false;
  735. var data = ((DualShock4HIDGenericInputReport*)(binaryData + 1))->ToHIDInputReport();
  736. *((DualShock4HIDInputReport*)stateEvent->state) = data;
  737. stateEvent->stateFormat = DualShock4HIDInputReport.Format;
  738. return true;
  739. }
  740. // bluetooth or enhanced report
  741. case 17:
  742. case 18:
  743. case 19:
  744. case 20:
  745. case 21:
  746. case 22:
  747. case 23:
  748. case 24:
  749. case 25:
  750. if ((binaryData[1] & 0x80) != 0)
  751. {
  752. if (size < sizeof(DualShock4HIDGenericInputReport) + 3)
  753. return false;
  754. var data = ((DualShock4HIDGenericInputReport*)(binaryData + 3))->ToHIDInputReport();
  755. *((DualShock4HIDInputReport*)stateEvent->state) = data;
  756. stateEvent->stateFormat = DualShock4HIDInputReport.Format;
  757. return true;
  758. }
  759. else
  760. return false;
  761. default:
  762. return false; // skip unrecognized reportId
  763. }
  764. }
  765. public void OnNextUpdate()
  766. {
  767. }
  768. // filter out three lower bits as jitter noise
  769. internal const byte JitterMaskLow = 0b01111000;
  770. internal const byte JitterMaskHigh = 0b10000111;
  771. public unsafe void OnStateEvent(InputEventPtr eventPtr)
  772. {
  773. if (eventPtr.type == StateEvent.Type && eventPtr.stateFormat == DualShock4HIDInputReport.Format)
  774. {
  775. var currentState = (DualShock4HIDInputReport*)((byte*)currentStatePtr + m_StateBlock.byteOffset);
  776. var newState = (DualShock4HIDInputReport*)StateEvent.FromUnchecked(eventPtr)->state;
  777. var actuatedOrChanged =
  778. // we need to make device current if axes are outside of deadzone specifying hardware jitter of sticks around zero point
  779. newState->leftStickX<JitterMaskLow
  780. || newState->leftStickX> JitterMaskHigh
  781. || newState->leftStickY<JitterMaskLow
  782. || newState->leftStickY> JitterMaskHigh
  783. || newState->rightStickX<JitterMaskLow
  784. || newState->rightStickX> JitterMaskHigh
  785. || newState->rightStickY<JitterMaskLow
  786. || newState->rightStickY> JitterMaskHigh
  787. // we need to make device current if triggers or buttons state change
  788. || newState->leftTrigger != currentState->leftTrigger
  789. || newState->rightTrigger != currentState->rightTrigger
  790. || newState->buttons1 != currentState->buttons1
  791. || newState->buttons2 != currentState->buttons2
  792. || newState->buttons3 != currentState->buttons3;
  793. if (!actuatedOrChanged)
  794. InputSystem.s_Manager.DontMakeCurrentlyUpdatingDeviceCurrent();
  795. }
  796. InputState.Change(this, eventPtr);
  797. }
  798. public bool GetStateOffsetForEvent(InputControl control, InputEventPtr eventPtr, ref uint offset)
  799. {
  800. return false;
  801. }
  802. [StructLayout(LayoutKind.Explicit)]
  803. internal struct DualShock4HIDGenericInputReport
  804. {
  805. public static FourCC Format => new FourCC('H', 'I', 'D');
  806. [FieldOffset(0)] public byte leftStickX;
  807. [FieldOffset(1)] public byte leftStickY;
  808. [FieldOffset(2)] public byte rightStickX;
  809. [FieldOffset(3)] public byte rightStickY;
  810. [FieldOffset(4)] public byte buttons0;
  811. [FieldOffset(5)] public byte buttons1;
  812. [FieldOffset(6)] public byte buttons2;
  813. [FieldOffset(7)] public byte leftTrigger;
  814. [FieldOffset(8)] public byte rightTrigger;
  815. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  816. public DualShock4HIDInputReport ToHIDInputReport()
  817. {
  818. return new DualShock4HIDInputReport
  819. {
  820. leftStickX = leftStickX,
  821. leftStickY = leftStickY,
  822. rightStickX = rightStickX,
  823. rightStickY = rightStickY,
  824. leftTrigger = leftTrigger,
  825. rightTrigger = rightTrigger,
  826. buttons1 = buttons0,
  827. buttons2 = buttons1,
  828. buttons3 = buttons2
  829. };
  830. }
  831. }
  832. }
  833. [InputControlLayout(stateType = typeof(DualShock3HIDInputReport), hideInUI = true, displayName = "PS3 Controller")]
  834. public class DualShock3GamepadHID : DualShockGamepad
  835. {
  836. public ButtonControl leftTriggerButton { get; protected set; }
  837. public ButtonControl rightTriggerButton { get; protected set; }
  838. public ButtonControl playStationButton { get; protected set; }
  839. protected override void FinishSetup()
  840. {
  841. leftTriggerButton = GetChildControl<ButtonControl>("leftTriggerButton");
  842. rightTriggerButton = GetChildControl<ButtonControl>("rightTriggerButton");
  843. playStationButton = GetChildControl<ButtonControl>("systemButton");
  844. base.FinishSetup();
  845. }
  846. // TODO: see if we can implement rumble support on DualShock 3
  847. }
  848. }
  849. // PS4 HID structures:
  850. //
  851. // struct PS4InputReport1
  852. // {
  853. // byte reportId; // #0
  854. // byte leftStickX; // #1
  855. // byte leftStickY; // #2
  856. // byte rightStickX; // #3
  857. // byte rightStickY; // #4
  858. // byte dpad : 4; // #5 bit #0 (0=up, 2=right, 4=down, 6=left)
  859. // byte squareButton : 1; // #5 bit #4
  860. // byte crossButton : 1; // #5 bit #5
  861. // byte circleButton : 1; // #5 bit #6
  862. // byte triangleButton : 1; // #5 bit #7
  863. // byte leftShoulder : 1; // #6 bit #0
  864. // byte rightShoulder : 1; // #6 bit #1
  865. // byte leftTriggerButton : 2;// #6 bit #2
  866. // byte rightTriggerButton : 2;// #6 bit #3
  867. // byte shareButton : 1; // #6 bit #4
  868. // byte optionsButton : 1; // #6 bit #5
  869. // byte leftStickPress : 1; // #6 bit #6
  870. // byte rightStickPress : 1; // #6 bit #7
  871. // byte psButton : 1; // #7 bit #0
  872. // byte touchpadPress : 1; // #7 bit #1
  873. // byte padding : 6;
  874. // byte leftTrigger; // #8
  875. // byte rightTrigger; // #9
  876. // }
  877. //
  878. // struct PS4OutputReport5
  879. // {
  880. // byte reportId; // #0
  881. // byte flags; // #1
  882. // byte unknown1[2];
  883. // byte highFrequencyMotor; // #4
  884. // byte lowFrequencyMotor; // #5
  885. // byte redColor; // #6
  886. // byte greenColor; // #7
  887. // byte blueColor; // #8
  888. // byte unknown2[23];
  889. // }
  890. //
  891. // Raw HID report descriptor:
  892. //
  893. // Usage Page (Generic Desktop) 05 01
  894. // Usage (Game Pad) 09 05
  895. // Collection (Application) A1 01
  896. // Report ID (1) 85 01
  897. // Usage (X) 09 30
  898. // Usage (Y) 09 31
  899. // Usage (Z) 09 32
  900. // Usage (Rz) 09 35
  901. // Logical Minimum (0) 15 00
  902. // Logical Maximum (255) 26 FF 00
  903. // Report Size (8) 75 08
  904. // Report Count (4) 95 04
  905. // Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
  906. // Usage (Hat Switch) 09 39
  907. // Logical Minimum (0) 15 00
  908. // Logical Maximum (7) 25 07
  909. // Physical Minimum (0) 35 00
  910. // Physical Maximum (315) 46 3B 01
  911. // Unit (Eng Rot: Degree) 65 14
  912. // Report Size (4) 75 04
  913. // Report Count (1) 95 01
  914. // Input (Data,Var,Abs,NWrp,Lin,Pref,Null,Bit) 81 42
  915. // Unit (None) 65 00
  916. // Usage Page (Button) 05 09
  917. // Usage Minimum (Button 1) 19 01
  918. // Usage Maximum (Button 14) 29 0E
  919. // Logical Minimum (0) 15 00
  920. // Logical Maximum (1) 25 01
  921. // Report Size (1) 75 01
  922. // Report Count (14) 95 0E
  923. // Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
  924. // Usage Page (Vendor-Defined 1) 06 00 FF
  925. // Usage (Vendor-Defined 32) 09 20
  926. // Report Size (6) 75 06
  927. // Report Count (1) 95 01
  928. // Logical Minimum (0) 15 00
  929. // Logical Maximum (127) 25 7F
  930. // Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
  931. // Usage Page (Generic Desktop) 05 01
  932. // Usage (Rx) 09 33
  933. // Usage (Ry) 09 34
  934. // Logical Minimum (0) 15 00
  935. // Logical Maximum (255) 26 FF 00
  936. // Report Size (8) 75 08
  937. // Report Count (2) 95 02
  938. // Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
  939. // Usage Page (Vendor-Defined 1) 06 00 FF
  940. // Usage (Vendor-Defined 33) 09 21
  941. // Report Count (54) 95 36
  942. // Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 02
  943. // Report ID (5) 85 05
  944. // Usage (Vendor-Defined 34) 09 22
  945. // Report Count (31) 95 1F
  946. // Output (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) 91 02
  947. // Report ID (4) 85 04
  948. // Usage (Vendor-Defined 35) 09 23
  949. // Report Count (36) 95 24
  950. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  951. // Report ID (2) 85 02
  952. // Usage (Vendor-Defined 36) 09 24
  953. // Report Count (36) 95 24
  954. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  955. // Report ID (8) 85 08
  956. // Usage (Vendor-Defined 37) 09 25
  957. // Report Count (3) 95 03
  958. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  959. // Report ID (16) 85 10
  960. // Usage (Vendor-Defined 38) 09 26
  961. // Report Count (4) 95 04
  962. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  963. // Report ID (17) 85 11
  964. // Usage (Vendor-Defined 39) 09 27
  965. // Report Count (2) 95 02
  966. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  967. // Report ID (18) 85 12
  968. // Usage Page (Vendor-Defined 3) 06 02 FF
  969. // Usage (Vendor-Defined 33) 09 21
  970. // Report Count (15) 95 0F
  971. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  972. // Report ID (19) 85 13
  973. // Usage (Vendor-Defined 34) 09 22
  974. // Report Count (22) 95 16
  975. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  976. // Report ID (20) 85 14
  977. // Usage Page (Vendor-Defined 6) 06 05 FF
  978. // Usage (Vendor-Defined 32) 09 20
  979. // Report Count (16) 95 10
  980. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  981. // Report ID (21) 85 15
  982. // Usage (Vendor-Defined 33) 09 21
  983. // Report Count (44) 95 2C
  984. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  985. // Usage Page (Vendor-Defined 129) 06 80 FF
  986. // Report ID (128) 85 80
  987. // Usage (Vendor-Defined 32) 09 20
  988. // Report Count (6) 95 06
  989. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  990. // Report ID (129) 85 81
  991. // Usage (Vendor-Defined 33) 09 21
  992. // Report Count (6) 95 06
  993. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  994. // Report ID (130) 85 82
  995. // Usage (Vendor-Defined 34) 09 22
  996. // Report Count (5) 95 05
  997. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  998. // Report ID (131) 85 83
  999. // Usage (Vendor-Defined 35) 09 23
  1000. // Report Count (1) 95 01
  1001. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1002. // Report ID (132) 85 84
  1003. // Usage (Vendor-Defined 36) 09 24
  1004. // Report Count (4) 95 04
  1005. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1006. // Report ID (133) 85 85
  1007. // Usage (Vendor-Defined 37) 09 25
  1008. // Report Count (6) 95 06
  1009. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1010. // Report ID (134) 85 86
  1011. // Usage (Vendor-Defined 38) 09 26
  1012. // Report Count (6) 95 06
  1013. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1014. // Report ID (135) 85 87
  1015. // Usage (Vendor-Defined 39) 09 27
  1016. // Report Count (35) 95 23
  1017. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1018. // Report ID (136) 85 88
  1019. // Usage (Vendor-Defined 40) 09 28
  1020. // Report Count (34) 95 22
  1021. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1022. // Report ID (137) 85 89
  1023. // Usage (Vendor-Defined 41) 09 29
  1024. // Report Count (2) 95 02
  1025. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1026. // Report ID (144) 85 90
  1027. // Usage (Vendor-Defined 48) 09 30
  1028. // Report Count (5) 95 05
  1029. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1030. // Report ID (145) 85 91
  1031. // Usage (Vendor-Defined 49) 09 31
  1032. // Report Count (3) 95 03
  1033. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1034. // Report ID (146) 85 92
  1035. // Usage (Vendor-Defined 50) 09 32
  1036. // Report Count (3) 95 03
  1037. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1038. // Report ID (147) 85 93
  1039. // Usage (Vendor-Defined 51) 09 33
  1040. // Report Count (12) 95 0C
  1041. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1042. // Report ID (160) 85 A0
  1043. // Usage (Vendor-Defined 64) 09 40
  1044. // Report Count (6) 95 06
  1045. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1046. // Report ID (161) 85 A1
  1047. // Usage (Vendor-Defined 65) 09 41
  1048. // Report Count (1) 95 01
  1049. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1050. // Report ID (162) 85 A2
  1051. // Usage (Vendor-Defined 66) 09 42
  1052. // Report Count (1) 95 01
  1053. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1054. // Report ID (163) 85 A3
  1055. // Usage (Vendor-Defined 67) 09 43
  1056. // Report Count (48) 95 30
  1057. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1058. // Report ID (164) 85 A4
  1059. // Usage (Vendor-Defined 68) 09 44
  1060. // Report Count (13) 95 0D
  1061. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1062. // Report ID (165) 85 A5
  1063. // Usage (Vendor-Defined 69) 09 45
  1064. // Report Count (21) 95 15
  1065. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1066. // Report ID (166) 85 A6
  1067. // Usage (Vendor-Defined 70) 09 46
  1068. // Report Count (21) 95 15
  1069. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1070. // Report ID (240) 85 F0
  1071. // Usage (Vendor-Defined 71) 09 47
  1072. // Report Count (63) 95 3F
  1073. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1074. // Report ID (241) 85 F1
  1075. // Usage (Vendor-Defined 72) 09 48
  1076. // Report Count (63) 95 3F
  1077. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1078. // Report ID (242) 85 F2
  1079. // Usage (Vendor-Defined 73) 09 49
  1080. // Report Count (15) 95 0F
  1081. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1082. // Report ID (167) 85 A7
  1083. // Usage (Vendor-Defined 74) 09 4A
  1084. // Report Count (1) 95 01
  1085. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1086. // Report ID (168) 85 A8
  1087. // Usage (Vendor-Defined 75) 09 4B
  1088. // Report Count (1) 95 01
  1089. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1090. // Report ID (169) 85 A9
  1091. // Usage (Vendor-Defined 76) 09 4C
  1092. // Report Count (8) 95 08
  1093. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1094. // Report ID (170) 85 AA
  1095. // Usage (Vendor-Defined 78) 09 4E
  1096. // Report Count (1) 95 01
  1097. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1098. // Report ID (171) 85 AB
  1099. // Usage (Vendor-Defined 79) 09 4F
  1100. // Report Count (57) 95 39
  1101. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1102. // Report ID (172) 85 AC
  1103. // Usage (Vendor-Defined 80) 09 50
  1104. // Report Count (57) 95 39
  1105. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1106. // Report ID (173) 85 AD
  1107. // Usage (Vendor-Defined 81) 09 51
  1108. // Report Count (11) 95 0B
  1109. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1110. // Report ID (174) 85 AE
  1111. // Usage (Vendor-Defined 82) 09 52
  1112. // Report Count (1) 95 01
  1113. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1114. // Report ID (175) 85 AF
  1115. // Usage (Vendor-Defined 83) 09 53
  1116. // Report Count (2) 95 02
  1117. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1118. // Report ID (176) 85 B0
  1119. // Usage (Vendor-Defined 84) 09 54
  1120. // Report Count (63) 95 3F
  1121. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1122. // Report ID (177) 85 B1
  1123. // Usage (Vendor-Defined 85) 09 55
  1124. // Report Count (2) 95 02
  1125. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1126. // Report ID (178) 85 B2
  1127. // Usage (Vendor-Defined 86) 09 56
  1128. // Report Count (2) 95 02
  1129. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1130. // Report ID (224) 85 E0
  1131. // Usage (Vendor-Defined 87) 09 57
  1132. // Report Count (2) 95 02
  1133. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1134. // Report ID (179) 85 B3
  1135. // Usage (Vendor-Defined 85) 09 55
  1136. // Report Count (63) 95 3F
  1137. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1138. // Report ID (180) 85 B4
  1139. // Usage (Vendor-Defined 85) 09 55
  1140. // Report Count (63) 95 3F
  1141. // Feature (Data,Var,Abs,NWrp,Lin,Pref,NNul,NVol,Bit) B1 02
  1142. // End Collection C0
  1143. #endif // UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WSA