SDL_sensor.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2018 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_sensor.h
  20. *
  21. * Include file for SDL sensor event handling
  22. *
  23. */
  24. #ifndef _SDL_sensor_h
  25. #define _SDL_sensor_h
  26. #include "SDL_stdinc.h"
  27. #include "SDL_error.h"
  28. #include "begin_code.h"
  29. /* Set up for C function definitions, even when using C++ */
  30. #ifdef __cplusplus
  31. /* *INDENT-OFF* */
  32. extern "C" {
  33. /* *INDENT-ON* */
  34. #endif
  35. /**
  36. * \file SDL_sensor.h
  37. *
  38. * In order to use these functions, SDL_Init() must have been called
  39. * with the ::SDL_INIT_SENSOR flag. This causes SDL to scan the system
  40. * for sensors, and load appropriate drivers.
  41. */
  42. struct _SDL_Sensor;
  43. typedef struct _SDL_Sensor SDL_Sensor;
  44. /**
  45. * This is a unique ID for a sensor for the time it is connected to the system,
  46. * and is never reused for the lifetime of the application.
  47. *
  48. * The ID value starts at 0 and increments from there. The value -1 is an invalid ID.
  49. */
  50. typedef Sint32 SDL_SensorID;
  51. /* The different sensor types */
  52. typedef enum
  53. {
  54. SDL_SENSOR_INVALID = -1, /**< Returned for an invalid sensor */
  55. SDL_SENSOR_UNKNOWN, /**< Unknown sensor type */
  56. SDL_SENSOR_ACCEL, /**< Accelerometer */
  57. SDL_SENSOR_GYRO, /**< Gyroscope */
  58. } SDL_SensorType;
  59. /**
  60. * Accelerometer sensor
  61. *
  62. * The accelerometer returns the current acceleration in SI meters per
  63. * second squared. This includes gravity, so a device at rest will have
  64. * an acceleration of SDL_STANDARD_GRAVITY straight down.
  65. *
  66. * values[0]: Acceleration on the x axis
  67. * values[1]: Acceleration on the y axis
  68. * values[2]: Acceleration on the z axis
  69. *
  70. * For phones held in portrait mode, the axes are defined as follows:
  71. * -X ... +X : left ... right
  72. * -Y ... +Y : bottom ... top
  73. * -Z ... +Z : farther ... closer
  74. *
  75. * The axis data is not changed when the phone is rotated.
  76. *
  77. * \sa SDL_GetDisplayOrientation()
  78. */
  79. #define SDL_STANDARD_GRAVITY 9.80665f
  80. /**
  81. * Gyroscope sensor
  82. *
  83. * The gyroscope returns the current rate of rotation in radians per second.
  84. * The rotation is positive in the counter-clockwise direction. That is,
  85. * an observer looking from a positive location on one of the axes would
  86. * see positive rotation on that axis when it appeared to be rotating
  87. * counter-clockwise.
  88. *
  89. * values[0]: Angular speed around the x axis
  90. * values[1]: Angular speed around the y axis
  91. * values[2]: Angular speed around the z axis
  92. *
  93. * For phones held in portrait mode, the axes are defined as follows:
  94. * -X ... +X : left ... right
  95. * -Y ... +Y : bottom ... top
  96. * -Z ... +Z : farther ... closer
  97. *
  98. * The axis data is not changed when the phone is rotated.
  99. *
  100. * \sa SDL_GetDisplayOrientation()
  101. */
  102. /* Function prototypes */
  103. /**
  104. * \brief Count the number of sensors attached to the system right now
  105. */
  106. extern DECLSPEC int SDLCALL SDL_NumSensors(void);
  107. /**
  108. * \brief Get the implementation dependent name of a sensor.
  109. *
  110. * This can be called before any sensors are opened.
  111. *
  112. * \return The sensor name, or NULL if device_index is out of range.
  113. */
  114. extern DECLSPEC const char *SDLCALL SDL_SensorGetDeviceName(int device_index);
  115. /**
  116. * \brief Get the type of a sensor.
  117. *
  118. * This can be called before any sensors are opened.
  119. *
  120. * \return The sensor type, or SDL_SENSOR_INVALID if device_index is out of range.
  121. */
  122. extern DECLSPEC SDL_SensorType SDLCALL SDL_SensorGetDeviceType(int device_index);
  123. /**
  124. * \brief Get the platform dependent type of a sensor.
  125. *
  126. * This can be called before any sensors are opened.
  127. *
  128. * \return The sensor platform dependent type, or -1 if device_index is out of range.
  129. */
  130. extern DECLSPEC int SDLCALL SDL_SensorGetDeviceNonPortableType(int device_index);
  131. /**
  132. * \brief Get the instance ID of a sensor.
  133. *
  134. * This can be called before any sensors are opened.
  135. *
  136. * \return The sensor instance ID, or -1 if device_index is out of range.
  137. */
  138. extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetDeviceInstanceID(int device_index);
  139. /**
  140. * \brief Open a sensor for use.
  141. *
  142. * The index passed as an argument refers to the N'th sensor on the system.
  143. *
  144. * \return A sensor identifier, or NULL if an error occurred.
  145. */
  146. extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorOpen(int device_index);
  147. /**
  148. * Return the SDL_Sensor associated with an instance id.
  149. */
  150. extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorFromInstanceID(SDL_SensorID instance_id);
  151. /**
  152. * \brief Get the implementation dependent name of a sensor.
  153. *
  154. * \return The sensor name, or NULL if the sensor is NULL.
  155. */
  156. extern DECLSPEC const char *SDLCALL SDL_SensorGetName(SDL_Sensor *sensor);
  157. /**
  158. * \brief Get the type of a sensor.
  159. *
  160. * This can be called before any sensors are opened.
  161. *
  162. * \return The sensor type, or SDL_SENSOR_INVALID if the sensor is NULL.
  163. */
  164. extern DECLSPEC SDL_SensorType SDLCALL SDL_SensorGetType(SDL_Sensor *sensor);
  165. /**
  166. * \brief Get the platform dependent type of a sensor.
  167. *
  168. * This can be called before any sensors are opened.
  169. *
  170. * \return The sensor platform dependent type, or -1 if the sensor is NULL.
  171. */
  172. extern DECLSPEC int SDLCALL SDL_SensorGetNonPortableType(SDL_Sensor *sensor);
  173. /**
  174. * \brief Get the instance ID of a sensor.
  175. *
  176. * This can be called before any sensors are opened.
  177. *
  178. * \return The sensor instance ID, or -1 if the sensor is NULL.
  179. */
  180. extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetInstanceID(SDL_Sensor *sensor);
  181. /**
  182. * Get the current state of an opened sensor.
  183. *
  184. * The number of values and interpretation of the data is sensor dependent.
  185. *
  186. * \param sensor The sensor to query
  187. * \param data A pointer filled with the current sensor state
  188. * \param num_values The number of values to write to data
  189. *
  190. * \return 0 or -1 if an error occurred.
  191. */
  192. extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values);
  193. /**
  194. * Close a sensor previously opened with SDL_SensorOpen()
  195. */
  196. extern DECLSPEC void SDLCALL SDL_SensorClose(SDL_Sensor * sensor);
  197. /**
  198. * Update the current state of the open sensors.
  199. *
  200. * This is called automatically by the event loop if sensor events are enabled.
  201. *
  202. * This needs to be called from the thread that initialized the sensor subsystem.
  203. */
  204. extern DECLSPEC void SDLCALL SDL_SensorUpdate(void);
  205. /* Ends C function definitions when using C++ */
  206. #ifdef __cplusplus
  207. /* *INDENT-OFF* */
  208. }
  209. /* *INDENT-ON* */
  210. #endif
  211. #include "close_code.h"
  212. #endif /* _SDL_sensor_h */
  213. /* vi: set ts=4 sw=4 expandtab: */