1
0

SDL_joystick.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_joystick.h
  20. *
  21. * Include file for SDL joystick event handling
  22. *
  23. * The term "device_index" identifies currently plugged in joystick devices between 0 and SDL_NumJoysticks(), with the exact joystick
  24. * behind a device_index changing as joysticks are plugged and unplugged.
  25. *
  26. * The term "instance_id" is the current instantiation of a joystick device in the system, if the joystick is removed and then re-inserted
  27. * then it will get a new instance_id, instance_id's are monotonically increasing identifiers of a joystick plugged in.
  28. *
  29. * The term JoystickGUID is a stable 128-bit identifier for a joystick device that does not change over time, it identifies class of
  30. * the device (a X360 wired controller for example). This identifier is platform dependent.
  31. *
  32. *
  33. */
  34. #ifndef _SDL_joystick_h
  35. #define _SDL_joystick_h
  36. #include "SDL_stdinc.h"
  37. #include "SDL_error.h"
  38. #include "begin_code.h"
  39. /* Set up for C function definitions, even when using C++ */
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /**
  44. * \file SDL_joystick.h
  45. *
  46. * In order to use these functions, SDL_Init() must have been called
  47. * with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
  48. * for joysticks, and load appropriate drivers.
  49. *
  50. * If you would like to receive joystick updates while the application
  51. * is in the background, you should set the following hint before calling
  52. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  53. */
  54. /* The joystick structure used to identify an SDL joystick */
  55. struct _SDL_Joystick;
  56. typedef struct _SDL_Joystick SDL_Joystick;
  57. /* A structure that encodes the stable unique id for a joystick device */
  58. typedef struct {
  59. Uint8 data[16];
  60. } SDL_JoystickGUID;
  61. typedef Sint32 SDL_JoystickID;
  62. typedef enum
  63. {
  64. SDL_JOYSTICK_POWER_UNKNOWN = -1,
  65. SDL_JOYSTICK_POWER_EMPTY,
  66. SDL_JOYSTICK_POWER_LOW,
  67. SDL_JOYSTICK_POWER_MEDIUM,
  68. SDL_JOYSTICK_POWER_FULL,
  69. SDL_JOYSTICK_POWER_WIRED,
  70. SDL_JOYSTICK_POWER_MAX
  71. } SDL_JoystickPowerLevel;
  72. /* Function prototypes */
  73. /**
  74. * Count the number of joysticks attached to the system right now
  75. */
  76. extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
  77. /**
  78. * Get the implementation dependent name of a joystick.
  79. * This can be called before any joysticks are opened.
  80. * If no name can be found, this function returns NULL.
  81. */
  82. extern DECLSPEC const char *SDLCALL SDL_JoystickNameForIndex(int device_index);
  83. /**
  84. * Open a joystick for use.
  85. * The index passed as an argument refers to the N'th joystick on the system.
  86. * This index is not the value which will identify this joystick in future
  87. * joystick events. The joystick's instance id (::SDL_JoystickID) will be used
  88. * there instead.
  89. *
  90. * \return A joystick identifier, or NULL if an error occurred.
  91. */
  92. extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
  93. /**
  94. * Return the SDL_Joystick associated with an instance id.
  95. */
  96. extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickFromInstanceID(SDL_JoystickID joyid);
  97. /**
  98. * Return the name for this currently opened joystick.
  99. * If no name can be found, this function returns NULL.
  100. */
  101. extern DECLSPEC const char *SDLCALL SDL_JoystickName(SDL_Joystick * joystick);
  102. /**
  103. * Return the GUID for the joystick at this index
  104. */
  105. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetDeviceGUID(int device_index);
  106. /**
  107. * Return the GUID for this opened joystick
  108. */
  109. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUID(SDL_Joystick * joystick);
  110. /**
  111. * Return a string representation for this guid. pszGUID must point to at least 33 bytes
  112. * (32 for the string plus a NULL terminator).
  113. */
  114. extern DECLSPEC void SDLCALL SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID);
  115. /**
  116. * convert a string into a joystick formatted guid
  117. */
  118. extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const char *pchGUID);
  119. /**
  120. * Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.
  121. */
  122. extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
  123. /**
  124. * Get the instance ID of an opened joystick or -1 if the joystick is invalid.
  125. */
  126. extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
  127. /**
  128. * Get the number of general axis controls on a joystick.
  129. */
  130. extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
  131. /**
  132. * Get the number of trackballs on a joystick.
  133. *
  134. * Joystick trackballs have only relative motion events associated
  135. * with them and their state cannot be polled.
  136. */
  137. extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
  138. /**
  139. * Get the number of POV hats on a joystick.
  140. */
  141. extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
  142. /**
  143. * Get the number of buttons on a joystick.
  144. */
  145. extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
  146. /**
  147. * Update the current state of the open joysticks.
  148. *
  149. * This is called automatically by the event loop if any joystick
  150. * events are enabled.
  151. */
  152. extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
  153. /**
  154. * Enable/disable joystick event polling.
  155. *
  156. * If joystick events are disabled, you must call SDL_JoystickUpdate()
  157. * yourself and check the state of the joystick when you want joystick
  158. * information.
  159. *
  160. * The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
  161. */
  162. extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
  163. /**
  164. * Get the current state of an axis control on a joystick.
  165. *
  166. * The state is a value ranging from -32768 to 32767.
  167. *
  168. * The axis indices start at index 0.
  169. */
  170. extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
  171. int axis);
  172. /**
  173. * \name Hat positions
  174. */
  175. /* @{ */
  176. #define SDL_HAT_CENTERED 0x00
  177. #define SDL_HAT_UP 0x01
  178. #define SDL_HAT_RIGHT 0x02
  179. #define SDL_HAT_DOWN 0x04
  180. #define SDL_HAT_LEFT 0x08
  181. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  182. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  183. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  184. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  185. /* @} */
  186. /**
  187. * Get the current state of a POV hat on a joystick.
  188. *
  189. * The hat indices start at index 0.
  190. *
  191. * \return The return value is one of the following positions:
  192. * - ::SDL_HAT_CENTERED
  193. * - ::SDL_HAT_UP
  194. * - ::SDL_HAT_RIGHT
  195. * - ::SDL_HAT_DOWN
  196. * - ::SDL_HAT_LEFT
  197. * - ::SDL_HAT_RIGHTUP
  198. * - ::SDL_HAT_RIGHTDOWN
  199. * - ::SDL_HAT_LEFTUP
  200. * - ::SDL_HAT_LEFTDOWN
  201. */
  202. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
  203. int hat);
  204. /**
  205. * Get the ball axis change since the last poll.
  206. *
  207. * \return 0, or -1 if you passed it invalid parameters.
  208. *
  209. * The ball indices start at index 0.
  210. */
  211. extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
  212. int ball, int *dx, int *dy);
  213. /**
  214. * Get the current state of a button on a joystick.
  215. *
  216. * The button indices start at index 0.
  217. */
  218. extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
  219. int button);
  220. /**
  221. * Close a joystick previously opened with SDL_JoystickOpen().
  222. */
  223. extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
  224. /**
  225. * Return the battery level of this joystick
  226. */
  227. extern DECLSPEC SDL_JoystickPowerLevel SDLCALL SDL_JoystickCurrentPowerLevel(SDL_Joystick * joystick);
  228. /* Ends C function definitions when using C++ */
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #include "close_code.h"
  233. #endif /* _SDL_joystick_h */
  234. /* vi: set ts=4 sw=4 expandtab: */