controller_structs.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //===================== Copyright (c) Valve Corporation. All Rights Reserved. ======================
  2. //
  3. // Purpose: Defines methods and structures used to communicate with Valve controllers.
  4. //
  5. //==================================================================================================
  6. #ifndef _CONTROLLER_STRUCTS_
  7. #define _CONTROLLER_STRUCTS_
  8. #pragma pack(1)
  9. // Roll this version forward anytime that you are breaking compatibility of existing
  10. // message types within ValveInReport_t or the header itself. Hopefully this should
  11. // be super rare and instead you shoudl just add new message payloads to the union,
  12. // or just add fields to the end of existing payload structs which is expected to be
  13. // safe in all code consuming these as they should just consume/copy upto the prior size
  14. // they were aware of when processing.
  15. #define k_ValveInReportMsgVersion 0x01
  16. typedef enum
  17. {
  18. ID_CONTROLLER_STATE = 1,
  19. ID_CONTROLLER_DEBUG = 2,
  20. ID_CONTROLLER_WIRELESS = 3,
  21. ID_CONTROLLER_STATUS = 4,
  22. ID_CONTROLLER_DEBUG2 = 5,
  23. ID_CONTROLLER_SECONDARY_STATE = 6,
  24. ID_CONTROLLER_BLE_STATE = 7,
  25. ID_CONTROLLER_MSG_COUNT
  26. } ValveInReportMessageIDs;
  27. typedef struct
  28. {
  29. unsigned short unReportVersion;
  30. unsigned char ucType;
  31. unsigned char ucLength;
  32. } ValveInReportHeader_t;
  33. // State payload
  34. typedef struct
  35. {
  36. // If packet num matches that on your prior call, then the controller state hasn't been changed since
  37. // your last call and there is no need to process it
  38. uint32 unPacketNum;
  39. // Button bitmask and trigger data.
  40. union
  41. {
  42. uint64 ulButtons;
  43. struct
  44. {
  45. unsigned char _pad0[3];
  46. unsigned char nLeft;
  47. unsigned char nRight;
  48. unsigned char _pad1[3];
  49. } Triggers;
  50. } ButtonTriggerData;
  51. // Left pad coordinates
  52. short sLeftPadX;
  53. short sLeftPadY;
  54. // Right pad coordinates
  55. short sRightPadX;
  56. short sRightPadY;
  57. // This is redundant, packed above, but still sent over wired
  58. unsigned short sTriggerL;
  59. unsigned short sTriggerR;
  60. // FIXME figure out a way to grab this stuff over wireless
  61. short sAccelX;
  62. short sAccelY;
  63. short sAccelZ;
  64. short sGyroX;
  65. short sGyroY;
  66. short sGyroZ;
  67. short sGyroQuatW;
  68. short sGyroQuatX;
  69. short sGyroQuatY;
  70. short sGyroQuatZ;
  71. } ValveControllerStatePacket_t;
  72. // BLE State payload this has to be re-formatted from the normal state because BLE controller shows up as
  73. //a HID device and we don't want to send all the optional parts of the message. Keep in sync with struct above.
  74. typedef struct
  75. {
  76. // If packet num matches that on your prior call, then the controller state hasn't been changed since
  77. // your last call and there is no need to process it
  78. uint32 unPacketNum;
  79. // Button bitmask and trigger data.
  80. union
  81. {
  82. uint64 ulButtons;
  83. struct
  84. {
  85. unsigned char _pad0[3];
  86. unsigned char nLeft;
  87. unsigned char nRight;
  88. unsigned char _pad1[3];
  89. } Triggers;
  90. } ButtonTriggerData;
  91. // Left pad coordinates
  92. short sLeftPadX;
  93. short sLeftPadY;
  94. // Right pad coordinates
  95. short sRightPadX;
  96. short sRightPadY;
  97. //This mimcs how the dongle reconstitutes HID packets, there will be 0-4 shorts depending on gyro mode
  98. unsigned char ucGyroDataType; //TODO could maybe find some unused bits in the button field for this info (is only 2bits)
  99. short sGyro[4];
  100. } ValveControllerBLEStatePacket_t;
  101. // Define a payload for reporting debug information
  102. typedef struct
  103. {
  104. // Left pad coordinates
  105. short sLeftPadX;
  106. short sLeftPadY;
  107. // Right pad coordinates
  108. short sRightPadX;
  109. short sRightPadY;
  110. // Left mouse deltas
  111. short sLeftPadMouseDX;
  112. short sLeftPadMouseDY;
  113. // Right mouse deltas
  114. short sRightPadMouseDX;
  115. short sRightPadMouseDY;
  116. // Left mouse filtered deltas
  117. short sLeftPadMouseFilteredDX;
  118. short sLeftPadMouseFilteredDY;
  119. // Right mouse filtered deltas
  120. short sRightPadMouseFilteredDX;
  121. short sRightPadMouseFilteredDY;
  122. // Pad Z values
  123. unsigned char ucLeftZ;
  124. unsigned char ucRightZ;
  125. // FingerPresent
  126. unsigned char ucLeftFingerPresent;
  127. unsigned char ucRightFingerPresent;
  128. // Timestamps
  129. unsigned char ucLeftTimestamp;
  130. unsigned char ucRightTimestamp;
  131. // Double tap state
  132. unsigned char ucLeftTapState;
  133. unsigned char ucRightTapState;
  134. unsigned int unDigitalIOStates0;
  135. unsigned int unDigitalIOStates1;
  136. } ValveControllerDebugPacket_t;
  137. typedef struct
  138. {
  139. unsigned char ucPadNum;
  140. unsigned char ucPad[3]; // need Data to be word aligned
  141. short Data[20];
  142. unsigned short unNoise;
  143. } ValveControllerTrackpadImage_t;
  144. typedef struct
  145. {
  146. unsigned char ucPadNum;
  147. unsigned char ucOffset;
  148. unsigned char ucPad[2]; // need Data to be word aligned
  149. short rgData[28];
  150. } ValveControllerRawTrackpadImage_t;
  151. // Payload for wireless metadata
  152. typedef struct
  153. {
  154. unsigned char ucEventType;
  155. } SteamControllerWirelessEvent_t;
  156. typedef struct
  157. {
  158. // Current packet number.
  159. unsigned int unPacketNum;
  160. // Event codes and state information.
  161. unsigned short sEventCode;
  162. unsigned short unStateFlags;
  163. // Current battery voltage (mV).
  164. unsigned short sBatteryVoltage;
  165. // Current battery level (0-100).
  166. unsigned char ucBatteryLevel;
  167. } SteamControllerStatusEvent_t;
  168. typedef struct
  169. {
  170. ValveInReportHeader_t header;
  171. union
  172. {
  173. ValveControllerStatePacket_t controllerState;
  174. ValveControllerBLEStatePacket_t controllerBLEState;
  175. ValveControllerDebugPacket_t debugState;
  176. ValveControllerTrackpadImage_t padImage;
  177. ValveControllerRawTrackpadImage_t rawPadImage;
  178. SteamControllerWirelessEvent_t wirelessEvent;
  179. SteamControllerStatusEvent_t statusEvent;
  180. } payload;
  181. } ValveInReport_t;
  182. // Enumeration for BLE packet protocol
  183. enum EBLEPacketReportNums
  184. {
  185. // Skipping past 2-3 because they are escape characters in Uart protocol
  186. k_EBLEReportState = 4,
  187. k_EBLEReportStatus = 5,
  188. };
  189. // Enumeration of data chunks in BLE state packets
  190. enum EBLEOptionDataChunksBitmask
  191. {
  192. // First byte uppper nibble
  193. k_EBLEButtonChunk1 = 0x10,
  194. k_EBLEButtonChunk2 = 0x20,
  195. k_EBLEButtonChunk3 = 0x40,
  196. k_EBLELeftJoystickChunk = 0x80,
  197. // Second full byte
  198. k_EBLELeftTrackpadChunk = 0x100,
  199. k_EBLERightTrackpadChunk = 0x200,
  200. k_EBLEIMUAccelChunk = 0x400,
  201. k_EBLEIMUGyroChunk = 0x800,
  202. k_EBLEIMUQuatChunk = 0x1000,
  203. };
  204. #pragma pack()
  205. #endif // _CONTROLLER_STRUCTS