SDL_syshaptic.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  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_syshaptic_h_
  20. #define SDL_syshaptic_h_
  21. // Set up for C function definitions, even when using C++
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. struct haptic_effect
  26. {
  27. SDL_HapticEffect effect; // The current event
  28. struct haptic_hweffect *hweffect; // The hardware behind the event
  29. };
  30. /*
  31. * The real SDL_Haptic struct.
  32. */
  33. struct SDL_Haptic
  34. {
  35. SDL_HapticID instance_id; // Device instance, monotonically increasing from 0
  36. char *name; // Device name - system dependent
  37. struct haptic_effect *effects; // Allocated effects
  38. int neffects; // Maximum amount of effects
  39. int nplaying; // Maximum amount of effects to play at the same time
  40. Uint32 supported; // Supported effects and features
  41. int naxes; // Number of axes on the device.
  42. struct haptic_hwdata *hwdata; // Driver dependent
  43. int ref_count; // Count for multiple opens
  44. int rumble_id; // ID of rumble effect for simple rumble API.
  45. SDL_HapticEffect rumble_effect; // Rumble effect.
  46. struct SDL_Haptic *next; // pointer to next haptic we have allocated
  47. };
  48. /*
  49. * Scans the system for haptic devices.
  50. *
  51. * Returns number of devices on success, -1 on error.
  52. */
  53. extern bool SDL_SYS_HapticInit(void);
  54. // Function to return the number of haptic devices plugged in right now
  55. extern int SDL_SYS_NumHaptics(void);
  56. /*
  57. * Gets the instance ID of the haptic device
  58. */
  59. extern SDL_HapticID SDL_SYS_HapticInstanceID(int index);
  60. /*
  61. * Gets the device dependent name of the haptic device
  62. */
  63. extern const char *SDL_SYS_HapticName(int index);
  64. /*
  65. * Opens the haptic device for usage. The haptic device should have
  66. * the index value set previously.
  67. */
  68. extern bool SDL_SYS_HapticOpen(SDL_Haptic *haptic);
  69. /*
  70. * Returns the index of the haptic core pointer or -1 if none is found.
  71. */
  72. extern int SDL_SYS_HapticMouse(void);
  73. /*
  74. * Checks to see if the joystick has haptic capabilities.
  75. */
  76. extern bool SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick);
  77. /*
  78. * Opens the haptic device for usage using the same device as
  79. * the joystick.
  80. */
  81. extern bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic,
  82. SDL_Joystick *joystick);
  83. /*
  84. * Checks to see if haptic device and joystick device are the same.
  85. *
  86. * Returns true if they are the same, false if they aren't.
  87. */
  88. extern bool SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic,
  89. SDL_Joystick *joystick);
  90. /*
  91. * Closes a haptic device after usage.
  92. */
  93. extern void SDL_SYS_HapticClose(SDL_Haptic *haptic);
  94. /*
  95. * Performs a cleanup on the haptic subsystem.
  96. */
  97. extern void SDL_SYS_HapticQuit(void);
  98. /*
  99. * Creates a new haptic effect on the haptic device using base
  100. * as a template for the effect.
  101. */
  102. extern bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic,
  103. struct haptic_effect *effect,
  104. const SDL_HapticEffect *base);
  105. /*
  106. * Updates the haptic effect on the haptic device using data
  107. * as a template.
  108. */
  109. extern bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic,
  110. struct haptic_effect *effect,
  111. const SDL_HapticEffect *data);
  112. /*
  113. * Runs the effect on the haptic device.
  114. */
  115. extern bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic,
  116. struct haptic_effect *effect,
  117. Uint32 iterations);
  118. /*
  119. * Stops the effect on the haptic device.
  120. */
  121. extern bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic,
  122. struct haptic_effect *effect);
  123. /*
  124. * Cleanups up the effect on the haptic device.
  125. */
  126. extern void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic,
  127. struct haptic_effect *effect);
  128. /*
  129. * Queries the device for the status of effect.
  130. *
  131. * Returns 0 if device is stopped, >0 if device is playing and
  132. * -1 on error.
  133. */
  134. extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic,
  135. struct haptic_effect *effect);
  136. /*
  137. * Sets the global gain of the haptic device.
  138. */
  139. extern bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain);
  140. /*
  141. * Sets the autocenter feature of the haptic device.
  142. */
  143. extern bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter);
  144. /*
  145. * Pauses the haptic device.
  146. */
  147. extern bool SDL_SYS_HapticPause(SDL_Haptic *haptic);
  148. /*
  149. * Unpauses the haptic device.
  150. */
  151. extern bool SDL_SYS_HapticResume(SDL_Haptic *haptic);
  152. /*
  153. * Stops all the currently playing haptic effects on the device.
  154. */
  155. extern bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic);
  156. // Ends C function definitions when using C++
  157. #ifdef __cplusplus
  158. }
  159. #endif
  160. #endif // SDL_syshaptic_h_