isteamcontroller.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //====== Copyright 1996-2013, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to valve controller
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMCONTROLLER_H
  7. #define ISTEAMCONTROLLER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. #define STEAM_CONTROLLER_MAX_COUNT 16
  13. #define STEAM_CONTROLLER_MAX_ANALOG_ACTIONS 16
  14. #define STEAM_CONTROLLER_MAX_DIGITAL_ACTIONS 128
  15. #define STEAM_CONTROLLER_MAX_ORIGINS 8
  16. // When sending an option to a specific controller handle, you can send to all controllers via this command
  17. #define STEAM_CONTROLLER_HANDLE_ALL_CONTROLLERS UINT64_MAX
  18. #define STEAM_CONTROLLER_MIN_ANALOG_ACTION_DATA -1.0f
  19. #define STEAM_CONTROLLER_MAX_ANALOG_ACTION_DATA 1.0f
  20. enum ESteamControllerPad
  21. {
  22. k_ESteamControllerPad_Left,
  23. k_ESteamControllerPad_Right
  24. };
  25. enum EControllerSource
  26. {
  27. k_EControllerSource_None,
  28. k_EControllerSource_LeftTrackpad,
  29. k_EControllerSource_RightTrackpad,
  30. k_EControllerSource_Joystick,
  31. k_EControllerSource_ABXY,
  32. k_EControllerSource_Switch,
  33. k_EControllerSource_LeftTrigger,
  34. k_EControllerSource_RightTrigger,
  35. k_EControllerSource_Gyro,
  36. k_EControllerSource_Count
  37. };
  38. enum EControllerSourceMode
  39. {
  40. k_EControllerSourceMode_None,
  41. k_EControllerSourceMode_Dpad,
  42. k_EControllerSourceMode_Buttons,
  43. k_EControllerSourceMode_FourButtons,
  44. k_EControllerSourceMode_AbsoluteMouse,
  45. k_EControllerSourceMode_RelativeMouse,
  46. k_EControllerSourceMode_JoystickMove,
  47. k_EControllerSourceMode_JoystickCamera,
  48. k_EControllerSourceMode_ScrollWheel,
  49. k_EControllerSourceMode_Trigger,
  50. k_EControllerSourceMode_TouchMenu,
  51. k_EControllerSourceMode_MouseJoystick,
  52. k_EControllerSourceMode_MouseRegion,
  53. k_EControllerSourceMode_RadialMenu,
  54. k_EControllerSourceMode_Switches
  55. };
  56. enum EControllerActionOrigin
  57. {
  58. k_EControllerActionOrigin_None,
  59. k_EControllerActionOrigin_A,
  60. k_EControllerActionOrigin_B,
  61. k_EControllerActionOrigin_X,
  62. k_EControllerActionOrigin_Y,
  63. k_EControllerActionOrigin_LeftBumper,
  64. k_EControllerActionOrigin_RightBumper,
  65. k_EControllerActionOrigin_LeftGrip,
  66. k_EControllerActionOrigin_RightGrip,
  67. k_EControllerActionOrigin_Start,
  68. k_EControllerActionOrigin_Back,
  69. k_EControllerActionOrigin_LeftPad_Touch,
  70. k_EControllerActionOrigin_LeftPad_Swipe,
  71. k_EControllerActionOrigin_LeftPad_Click,
  72. k_EControllerActionOrigin_LeftPad_DPadNorth,
  73. k_EControllerActionOrigin_LeftPad_DPadSouth,
  74. k_EControllerActionOrigin_LeftPad_DPadWest,
  75. k_EControllerActionOrigin_LeftPad_DPadEast,
  76. k_EControllerActionOrigin_RightPad_Touch,
  77. k_EControllerActionOrigin_RightPad_Swipe,
  78. k_EControllerActionOrigin_RightPad_Click,
  79. k_EControllerActionOrigin_RightPad_DPadNorth,
  80. k_EControllerActionOrigin_RightPad_DPadSouth,
  81. k_EControllerActionOrigin_RightPad_DPadWest,
  82. k_EControllerActionOrigin_RightPad_DPadEast,
  83. k_EControllerActionOrigin_LeftTrigger_Pull,
  84. k_EControllerActionOrigin_LeftTrigger_Click,
  85. k_EControllerActionOrigin_RightTrigger_Pull,
  86. k_EControllerActionOrigin_RightTrigger_Click,
  87. k_EControllerActionOrigin_LeftStick_Move,
  88. k_EControllerActionOrigin_LeftStick_Click,
  89. k_EControllerActionOrigin_LeftStick_DPadNorth,
  90. k_EControllerActionOrigin_LeftStick_DPadSouth,
  91. k_EControllerActionOrigin_LeftStick_DPadWest,
  92. k_EControllerActionOrigin_LeftStick_DPadEast,
  93. k_EControllerActionOrigin_Gyro_Move,
  94. k_EControllerActionOrigin_Gyro_Pitch,
  95. k_EControllerActionOrigin_Gyro_Yaw,
  96. k_EControllerActionOrigin_Gyro_Roll,
  97. k_EControllerActionOrigin_Count
  98. };
  99. // ControllerHandle_t is used to refer to a specific controller.
  100. // This handle will consistently identify a controller, even if it is disconnected and re-connected
  101. typedef uint64 ControllerHandle_t;
  102. // These handles are used to refer to a specific in-game action or action set
  103. // All action handles should be queried during initialization for performance reasons
  104. typedef uint64 ControllerActionSetHandle_t;
  105. typedef uint64 ControllerDigitalActionHandle_t;
  106. typedef uint64 ControllerAnalogActionHandle_t;
  107. #pragma pack( push, 1 )
  108. struct ControllerAnalogActionData_t
  109. {
  110. // Type of data coming from this action, this will match what got specified in the action set
  111. EControllerSourceMode eMode;
  112. // The current state of this action; will be delta updates for mouse actions
  113. float x, y;
  114. // Whether or not this action is currently available to be bound in the active action set
  115. bool bActive;
  116. };
  117. struct ControllerDigitalActionData_t
  118. {
  119. // The current state of this action; will be true if currently pressed
  120. bool bState;
  121. // Whether or not this action is currently available to be bound in the active action set
  122. bool bActive;
  123. };
  124. struct ControllerMotionData_t
  125. {
  126. // Sensor-fused absolute rotation; will drift in heading
  127. float rotQuatX;
  128. float rotQuatY;
  129. float rotQuatZ;
  130. float rotQuatW;
  131. // Positional acceleration
  132. float posAccelX;
  133. float posAccelY;
  134. float posAccelZ;
  135. // Angular velocity
  136. float rotVelX;
  137. float rotVelY;
  138. float rotVelZ;
  139. };
  140. #pragma pack( pop )
  141. //-----------------------------------------------------------------------------
  142. // Purpose: Native Steam controller support API
  143. //-----------------------------------------------------------------------------
  144. class ISteamController
  145. {
  146. public:
  147. // Init and Shutdown must be called when starting/ending use of this interface
  148. virtual bool Init() = 0;
  149. virtual bool Shutdown() = 0;
  150. // Synchronize API state with the latest Steam Controller inputs available. This
  151. // is performed automatically by SteamAPI_RunCallbacks, but for the absolute lowest
  152. // possible latency, you call this directly before reading controller state.
  153. virtual void RunFrame() = 0;
  154. // Enumerate currently connected controllers
  155. // handlesOut should point to a STEAM_CONTROLLER_MAX_COUNT sized array of ControllerHandle_t handles
  156. // Returns the number of handles written to handlesOut
  157. virtual int GetConnectedControllers( ControllerHandle_t *handlesOut ) = 0;
  158. // Invokes the Steam overlay and brings up the binding screen
  159. // Returns false is overlay is disabled / unavailable, or the user is not in Big Picture mode
  160. virtual bool ShowBindingPanel( ControllerHandle_t controllerHandle ) = 0;
  161. // ACTION SETS
  162. // Lookup the handle for an Action Set. Best to do this once on startup, and store the handles for all future API calls.
  163. virtual ControllerActionSetHandle_t GetActionSetHandle( const char *pszActionSetName ) = 0;
  164. // Reconfigure the controller to use the specified action set (ie 'Menu', 'Walk' or 'Drive')
  165. // This is cheap, and can be safely called repeatedly. It's often easier to repeatedly call it in
  166. // your state loops, instead of trying to place it in all of your state transitions.
  167. virtual void ActivateActionSet( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle ) = 0;
  168. virtual ControllerActionSetHandle_t GetCurrentActionSet( ControllerHandle_t controllerHandle ) = 0;
  169. // ACTIONS
  170. // Lookup the handle for a digital action. Best to do this once on startup, and store the handles for all future API calls.
  171. virtual ControllerDigitalActionHandle_t GetDigitalActionHandle( const char *pszActionName ) = 0;
  172. // Returns the current state of the supplied digital game action
  173. virtual ControllerDigitalActionData_t GetDigitalActionData( ControllerHandle_t controllerHandle, ControllerDigitalActionHandle_t digitalActionHandle ) = 0;
  174. // Get the origin(s) for a digital action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.
  175. // originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles
  176. virtual int GetDigitalActionOrigins( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerDigitalActionHandle_t digitalActionHandle, EControllerActionOrigin *originsOut ) = 0;
  177. // Lookup the handle for an analog action. Best to do this once on startup, and store the handles for all future API calls.
  178. virtual ControllerAnalogActionHandle_t GetAnalogActionHandle( const char *pszActionName ) = 0;
  179. // Returns the current state of these supplied analog game action
  180. virtual ControllerAnalogActionData_t GetAnalogActionData( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t analogActionHandle ) = 0;
  181. // Get the origin(s) for an analog action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.
  182. // originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles
  183. virtual int GetAnalogActionOrigins( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerAnalogActionHandle_t analogActionHandle, EControllerActionOrigin *originsOut ) = 0;
  184. virtual void StopAnalogActionMomentum( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t eAction ) = 0;
  185. // Trigger a haptic pulse on a controller
  186. virtual void TriggerHapticPulse( ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, unsigned short usDurationMicroSec ) = 0;
  187. // Trigger a pulse with a duty cycle of usDurationMicroSec / usOffMicroSec, unRepeat times.
  188. // nFlags is currently unused and reserved for future use.
  189. virtual void TriggerRepeatedHapticPulse( ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, unsigned short usDurationMicroSec, unsigned short usOffMicroSec, unsigned short unRepeat, unsigned int nFlags ) = 0;
  190. // Returns the associated gamepad index for the specified controller, if emulating a gamepad
  191. virtual int GetGamepadIndexForController( ControllerHandle_t ulControllerHandle ) = 0;
  192. // Returns the associated controller handle for the specified emulated gamepad
  193. virtual ControllerHandle_t GetControllerForGamepadIndex( int nIndex ) = 0;
  194. // Returns raw motion data from the specified controller
  195. virtual ControllerMotionData_t GetMotionData( ControllerHandle_t controllerHandle ) = 0;
  196. // Attempt to display origins of given action in the controller HUD, for the currently active action set
  197. // Returns false is overlay is disabled / unavailable, or the user is not in Big Picture mode
  198. virtual bool ShowDigitalActionOrigins( ControllerHandle_t controllerHandle, ControllerDigitalActionHandle_t digitalActionHandle, float flScale, float flXPosition, float flYPosition ) = 0;
  199. virtual bool ShowAnalogActionOrigins( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t analogActionHandle, float flScale, float flXPosition, float flYPosition ) = 0;
  200. };
  201. #define STEAMCONTROLLER_INTERFACE_VERSION "SteamController004"
  202. #endif // ISTEAMCONTROLLER_H