SDL_sysjoystick.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2022 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. #include "../SDL_internal.h"
  19. #ifndef SDL_sysjoystick_h_
  20. #define SDL_sysjoystick_h_
  21. /* This is the system specific header for the SDL joystick API */
  22. #include "SDL_joystick.h"
  23. #include "SDL_joystick_c.h"
  24. /* Set up for C function definitions, even when using C++ */
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* The SDL joystick structure */
  29. typedef struct _SDL_JoystickAxisInfo
  30. {
  31. Sint16 initial_value; /* Initial axis state */
  32. Sint16 value; /* Current axis state */
  33. Sint16 zero; /* Zero point on the axis (-32768 for triggers) */
  34. SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
  35. SDL_bool has_second_value; /* Whether we've seen a second value on the axis yet */
  36. SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
  37. SDL_bool sending_initial_value; /* Whether we are sending the initial axis value */
  38. } SDL_JoystickAxisInfo;
  39. typedef struct _SDL_JoystickTouchpadFingerInfo
  40. {
  41. Uint8 state;
  42. float x;
  43. float y;
  44. float pressure;
  45. } SDL_JoystickTouchpadFingerInfo;
  46. typedef struct _SDL_JoystickTouchpadInfo
  47. {
  48. int nfingers;
  49. SDL_JoystickTouchpadFingerInfo *fingers;
  50. } SDL_JoystickTouchpadInfo;
  51. typedef struct _SDL_JoystickSensorInfo
  52. {
  53. SDL_SensorType type;
  54. SDL_bool enabled;
  55. float rate;
  56. float data[3]; /* If this needs to expand, update SDL_ControllerSensorEvent */
  57. } SDL_JoystickSensorInfo;
  58. struct _SDL_Joystick
  59. {
  60. SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
  61. char *name; /* Joystick name - system dependent */
  62. char *path; /* Joystick path - system dependent */
  63. char *serial; /* Joystick serial */
  64. SDL_JoystickGUID guid; /* Joystick guid */
  65. Uint16 firmware_version; /* Firmware version, if available */
  66. int naxes; /* Number of axis controls on the joystick */
  67. SDL_JoystickAxisInfo *axes;
  68. int nhats; /* Number of hats on the joystick */
  69. Uint8 *hats; /* Current hat states */
  70. int nballs; /* Number of trackballs on the joystick */
  71. struct balldelta {
  72. int dx;
  73. int dy;
  74. } *balls; /* Current ball motion deltas */
  75. int nbuttons; /* Number of buttons on the joystick */
  76. Uint8 *buttons; /* Current button states */
  77. int ntouchpads; /* Number of touchpads on the joystick */
  78. SDL_JoystickTouchpadInfo *touchpads; /* Current touchpad states */
  79. int nsensors; /* Number of sensors on the joystick */
  80. int nsensors_enabled;
  81. SDL_JoystickSensorInfo *sensors;
  82. Uint16 low_frequency_rumble;
  83. Uint16 high_frequency_rumble;
  84. Uint32 rumble_expiration;
  85. Uint16 left_trigger_rumble;
  86. Uint16 right_trigger_rumble;
  87. Uint32 trigger_rumble_expiration;
  88. Uint8 led_red;
  89. Uint8 led_green;
  90. Uint8 led_blue;
  91. Uint32 led_expiration;
  92. SDL_bool attached;
  93. SDL_bool is_game_controller;
  94. SDL_bool delayed_guide_button; /* SDL_TRUE if this device has the guide button event delayed */
  95. SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
  96. struct _SDL_JoystickDriver *driver;
  97. struct joystick_hwdata *hwdata; /* Driver dependent information */
  98. int ref_count; /* Reference count for multiple opens */
  99. struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
  100. };
  101. /* Device bus definitions */
  102. #define SDL_HARDWARE_BUS_UNKNOWN 0x00
  103. #define SDL_HARDWARE_BUS_USB 0x03
  104. #define SDL_HARDWARE_BUS_BLUETOOTH 0x05
  105. #define SDL_HARDWARE_BUS_VIRTUAL 0xFF
  106. /* Joystick capability flags for GetCapabilities() */
  107. #define SDL_JOYCAP_LED 0x01
  108. #define SDL_JOYCAP_RUMBLE 0x02
  109. #define SDL_JOYCAP_RUMBLE_TRIGGERS 0x04
  110. /* Macro to combine a USB vendor ID and product ID into a single Uint32 value */
  111. #define MAKE_VIDPID(VID, PID) (((Uint32)(VID))<<16|(PID))
  112. typedef struct _SDL_JoystickDriver
  113. {
  114. /* Function to scan the system for joysticks.
  115. * Joystick 0 should be the system default joystick.
  116. * This function should return 0, or -1 on an unrecoverable error.
  117. */
  118. int (*Init)(void);
  119. /* Function to return the number of joystick devices plugged in right now */
  120. int (*GetCount)(void);
  121. /* Function to cause any queued joystick insertions to be processed */
  122. void (*Detect)(void);
  123. /* Function to get the device-dependent name of a joystick */
  124. const char *(*GetDeviceName)(int device_index);
  125. /* Function to get the device-dependent path of a joystick */
  126. const char *(*GetDevicePath)(int device_index);
  127. /* Function to get the player index of a joystick */
  128. int (*GetDevicePlayerIndex)(int device_index);
  129. /* Function to set the player index of a joystick */
  130. void (*SetDevicePlayerIndex)(int device_index, int player_index);
  131. /* Function to return the stable GUID for a plugged in device */
  132. SDL_JoystickGUID (*GetDeviceGUID)(int device_index);
  133. /* Function to get the current instance id of the joystick located at device_index */
  134. SDL_JoystickID (*GetDeviceInstanceID)(int device_index);
  135. /* Function to open a joystick for use.
  136. The joystick to open is specified by the device index.
  137. This should fill the nbuttons and naxes fields of the joystick structure.
  138. It returns 0, or -1 if there is an error.
  139. */
  140. int (*Open)(SDL_Joystick *joystick, int device_index);
  141. /* Rumble functionality */
  142. int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
  143. int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
  144. /* Capability detection */
  145. Uint32 (*GetCapabilities)(SDL_Joystick *joystick);
  146. /* LED functionality */
  147. int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  148. /* General effects */
  149. int (*SendEffect)(SDL_Joystick *joystick, const void *data, int size);
  150. /* Sensor functionality */
  151. int (*SetSensorsEnabled)(SDL_Joystick *joystick, SDL_bool enabled);
  152. /* Function to update the state of a joystick - called as a device poll.
  153. * This function shouldn't update the joystick structure directly,
  154. * but instead should call SDL_PrivateJoystick*() to deliver events
  155. * and update joystick device state.
  156. */
  157. void (*Update)(SDL_Joystick *joystick);
  158. /* Function to close a joystick after use */
  159. void (*Close)(SDL_Joystick *joystick);
  160. /* Function to perform any system-specific joystick related cleanup */
  161. void (*Quit)(void);
  162. /* Function to get the autodetected controller mapping; returns false if there isn't any. */
  163. SDL_bool (*GetGamepadMapping)(int device_index, SDL_GamepadMapping * out);
  164. } SDL_JoystickDriver;
  165. /* Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF */
  166. #define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF
  167. #define SDL_LED_MIN_REPEAT_MS 5000
  168. /* The available joystick drivers */
  169. extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
  170. extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
  171. extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
  172. extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
  173. extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
  174. extern SDL_JoystickDriver SDL_HAIKU_JoystickDriver;
  175. extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver;
  176. extern SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver;
  177. extern SDL_JoystickDriver SDL_IOS_JoystickDriver;
  178. extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
  179. extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
  180. extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
  181. extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
  182. extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
  183. extern SDL_JoystickDriver SDL_OS2_JoystickDriver;
  184. extern SDL_JoystickDriver SDL_PS2_JoystickDriver;
  185. extern SDL_JoystickDriver SDL_PSP_JoystickDriver;
  186. extern SDL_JoystickDriver SDL_VITA_JoystickDriver;
  187. /* Ends C function definitions when using C++ */
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /* SDL_sysjoystick_h_ */
  192. /* vi: set ts=4 sw=4 expandtab: */