🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

322 lines
10 KiB

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. * \brief 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 sensors defined by SDL
  52. *
  53. * Additional sensors may be available, using platform dependent semantics.
  54. *
  55. * Hare are the additional Android sensors:
  56. * https://developer.android.com/reference/android/hardware/SensorEvent.html#values
  57. */
  58. typedef enum
  59. {
  60. SDL_SENSOR_INVALID = -1, /**< Returned for an invalid sensor */
  61. SDL_SENSOR_UNKNOWN, /**< Unknown sensor type */
  62. SDL_SENSOR_ACCEL, /**< Accelerometer */
  63. SDL_SENSOR_GYRO, /**< Gyroscope */
  64. SDL_SENSOR_ACCEL_L, /**< Accelerometer for left Joy-Con controller and Wii nunchuk */
  65. SDL_SENSOR_GYRO_L, /**< Gyroscope for left Joy-Con controller */
  66. SDL_SENSOR_ACCEL_R, /**< Accelerometer for right Joy-Con controller */
  67. SDL_SENSOR_GYRO_R /**< Gyroscope for right Joy-Con controller */
  68. } SDL_SensorType;
  69. /**
  70. * Accelerometer sensor
  71. *
  72. * The accelerometer returns the current acceleration in SI meters per
  73. * second squared. This measurement includes the force of gravity, so
  74. * a device at rest will have an value of SDL_STANDARD_GRAVITY away
  75. * from the center of the earth.
  76. *
  77. * values[0]: Acceleration on the x axis
  78. * values[1]: Acceleration on the y axis
  79. * values[2]: Acceleration on the z axis
  80. *
  81. * For phones held in portrait mode and game controllers held in front of you,
  82. * the axes are defined as follows:
  83. * -X ... +X : left ... right
  84. * -Y ... +Y : bottom ... top
  85. * -Z ... +Z : farther ... closer
  86. *
  87. * The axis data is not changed when the phone is rotated.
  88. *
  89. * \sa SDL_GetDisplayOrientation()
  90. */
  91. #define SDL_STANDARD_GRAVITY 9.80665f
  92. /**
  93. * Gyroscope sensor
  94. *
  95. * The gyroscope returns the current rate of rotation in radians per second.
  96. * The rotation is positive in the counter-clockwise direction. That is,
  97. * an observer looking from a positive location on one of the axes would
  98. * see positive rotation on that axis when it appeared to be rotating
  99. * counter-clockwise.
  100. *
  101. * values[0]: Angular speed around the x axis (pitch)
  102. * values[1]: Angular speed around the y axis (yaw)
  103. * values[2]: Angular speed around the z axis (roll)
  104. *
  105. * For phones held in portrait mode and game controllers held in front of you,
  106. * the axes are defined as follows:
  107. * -X ... +X : left ... right
  108. * -Y ... +Y : bottom ... top
  109. * -Z ... +Z : farther ... closer
  110. *
  111. * The axis data is not changed when the phone or controller is rotated.
  112. *
  113. * \sa SDL_GetDisplayOrientation()
  114. */
  115. /* Function prototypes */
  116. /**
  117. * Locking for multi-threaded access to the sensor API
  118. *
  119. * If you are using the sensor API or handling events from multiple threads
  120. * you should use these locking functions to protect access to the sensors.
  121. *
  122. * In particular, you are guaranteed that the sensor list won't change, so the
  123. * API functions that take a sensor index will be valid, and sensor events
  124. * will not be delivered.
  125. *
  126. * \since This function is available since SDL 2.0.14.
  127. */
  128. extern DECLSPEC void SDLCALL SDL_LockSensors(void);
  129. extern DECLSPEC void SDLCALL SDL_UnlockSensors(void);
  130. /**
  131. * Count the number of sensors attached to the system right now.
  132. *
  133. * \returns the number of sensors detected.
  134. *
  135. * \since This function is available since SDL 2.0.9.
  136. */
  137. extern DECLSPEC int SDLCALL SDL_NumSensors(void);
  138. /**
  139. * Get the implementation dependent name of a sensor.
  140. *
  141. * \param device_index The sensor to obtain name from
  142. * \returns the sensor name, or NULL if `device_index` is out of range.
  143. *
  144. * \since This function is available since SDL 2.0.9.
  145. */
  146. extern DECLSPEC const char *SDLCALL SDL_SensorGetDeviceName(int device_index);
  147. /**
  148. * Get the type of a sensor.
  149. *
  150. * \param device_index The sensor to get the type from
  151. * \returns the SDL_SensorType, or `SDL_SENSOR_INVALID` if `device_index` is
  152. * out of range.
  153. *
  154. * \since This function is available since SDL 2.0.9.
  155. */
  156. extern DECLSPEC SDL_SensorType SDLCALL SDL_SensorGetDeviceType(int device_index);
  157. /**
  158. * Get the platform dependent type of a sensor.
  159. *
  160. * \param device_index The sensor to check
  161. * \returns the sensor platform dependent type, or -1 if `device_index` is out
  162. * of range.
  163. *
  164. * \since This function is available since SDL 2.0.9.
  165. */
  166. extern DECLSPEC int SDLCALL SDL_SensorGetDeviceNonPortableType(int device_index);
  167. /**
  168. * Get the instance ID of a sensor.
  169. *
  170. * \param device_index The sensor to get instance id from
  171. * \returns the sensor instance ID, or -1 if `device_index` is out of range.
  172. *
  173. * \since This function is available since SDL 2.0.9.
  174. */
  175. extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetDeviceInstanceID(int device_index);
  176. /**
  177. * Open a sensor for use.
  178. *
  179. * \param device_index The sensor to open
  180. * \returns an SDL_Sensor sensor object, or NULL if an error occurred.
  181. *
  182. * \since This function is available since SDL 2.0.9.
  183. */
  184. extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorOpen(int device_index);
  185. /**
  186. * Return the SDL_Sensor associated with an instance id.
  187. *
  188. * \param instance_id The sensor from instance id
  189. * \returns an SDL_Sensor object.
  190. *
  191. * \since This function is available since SDL 2.0.9.
  192. */
  193. extern DECLSPEC SDL_Sensor *SDLCALL SDL_SensorFromInstanceID(SDL_SensorID instance_id);
  194. /**
  195. * Get the implementation dependent name of a sensor
  196. *
  197. * \param sensor The SDL_Sensor object
  198. * \returns the sensor name, or NULL if `sensor` is NULL.
  199. *
  200. * \since This function is available since SDL 2.0.9.
  201. */
  202. extern DECLSPEC const char *SDLCALL SDL_SensorGetName(SDL_Sensor *sensor);
  203. /**
  204. * Get the type of a sensor.
  205. *
  206. * \param sensor The SDL_Sensor object to inspect
  207. * \returns the SDL_SensorType type, or `SDL_SENSOR_INVALID` if `sensor` is
  208. * NULL.
  209. *
  210. * \since This function is available since SDL 2.0.9.
  211. */
  212. extern DECLSPEC SDL_SensorType SDLCALL SDL_SensorGetType(SDL_Sensor *sensor);
  213. /**
  214. * Get the platform dependent type of a sensor.
  215. *
  216. * \param sensor The SDL_Sensor object to inspect
  217. * \returns the sensor platform dependent type, or -1 if `sensor` is NULL.
  218. *
  219. * \since This function is available since SDL 2.0.9.
  220. */
  221. extern DECLSPEC int SDLCALL SDL_SensorGetNonPortableType(SDL_Sensor *sensor);
  222. /**
  223. * Get the instance ID of a sensor.
  224. *
  225. * \param sensor The SDL_Sensor object to inspect
  226. * \returns the sensor instance ID, or -1 if `sensor` is NULL.
  227. *
  228. * \since This function is available since SDL 2.0.9.
  229. */
  230. extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetInstanceID(SDL_Sensor *sensor);
  231. /**
  232. * Get the current state of an opened sensor.
  233. *
  234. * The number of values and interpretation of the data is sensor dependent.
  235. *
  236. * \param sensor The SDL_Sensor object to query
  237. * \param data A pointer filled with the current sensor state
  238. * \param num_values The number of values to write to data
  239. * \returns 0 or -1 if an error occurred.
  240. *
  241. * \since This function is available since SDL 2.0.9.
  242. */
  243. extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor *sensor, float *data, int num_values);
  244. /**
  245. * Get the current state of an opened sensor with the timestamp of the last
  246. * update.
  247. *
  248. * The number of values and interpretation of the data is sensor dependent.
  249. *
  250. * \param sensor The SDL_Sensor object to query
  251. * \param timestamp A pointer filled with the timestamp in microseconds of the
  252. * current sensor reading if available, or 0 if not
  253. * \param data A pointer filled with the current sensor state
  254. * \param num_values The number of values to write to data
  255. * \returns 0 or -1 if an error occurred.
  256. *
  257. * \since This function is available since SDL 2.26.0.
  258. */
  259. extern DECLSPEC int SDLCALL SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values);
  260. /**
  261. * Close a sensor previously opened with SDL_SensorOpen().
  262. *
  263. * \param sensor The SDL_Sensor object to close
  264. *
  265. * \since This function is available since SDL 2.0.9.
  266. */
  267. extern DECLSPEC void SDLCALL SDL_SensorClose(SDL_Sensor *sensor);
  268. /**
  269. * Update the current state of the open sensors.
  270. *
  271. * This is called automatically by the event loop if sensor events are
  272. * enabled.
  273. *
  274. * This needs to be called from the thread that initialized the sensor
  275. * subsystem.
  276. *
  277. * \since This function is available since SDL 2.0.9.
  278. */
  279. extern DECLSPEC void SDLCALL SDL_SensorUpdate(void);
  280. /* Ends C function definitions when using C++ */
  281. #ifdef __cplusplus
  282. /* *INDENT-OFF* */
  283. }
  284. /* *INDENT-ON* */
  285. #endif
  286. #include "close_code.h"
  287. #endif /* SDL_sensor_h_ */
  288. /* vi: set ts=4 sw=4 expandtab: */