SDL_syssensor.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 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_syssensor_c_h_
  20. #define SDL_syssensor_c_h_
  21. // This is the system specific header for the SDL sensor API
  22. #include "SDL_sensor_c.h"
  23. #define _guarded SDL_GUARDED_BY(SDL_sensor_lock)
  24. // The SDL sensor structure
  25. struct SDL_Sensor
  26. {
  27. SDL_SensorID instance_id _guarded; // Device instance, monotonically increasing from 0
  28. char *name _guarded; // Sensor name - system dependent
  29. SDL_SensorType type _guarded; // Type of the sensor
  30. int non_portable_type _guarded; // Platform dependent type of the sensor
  31. float data[16] _guarded; // The current state of the sensor
  32. struct SDL_SensorDriver *driver _guarded;
  33. struct sensor_hwdata *hwdata _guarded; // Driver dependent information
  34. SDL_PropertiesID props _guarded;
  35. int ref_count _guarded; // Reference count for multiple opens
  36. struct SDL_Sensor *next _guarded; // pointer to next sensor we have allocated
  37. };
  38. #undef _guarded
  39. typedef struct SDL_SensorDriver
  40. {
  41. /* Function to scan the system for sensors.
  42. * sensor 0 should be the system default sensor.
  43. * This function should return 0, or -1 on an unrecoverable fatal error.
  44. */
  45. bool (*Init)(void);
  46. // Function to return the number of sensors available right now
  47. int (*GetCount)(void);
  48. // Function to check to see if the available sensors have changed
  49. void (*Detect)(void);
  50. // Function to get the device-dependent name of a sensor
  51. const char *(*GetDeviceName)(int device_index);
  52. // Function to get the type of a sensor
  53. SDL_SensorType (*GetDeviceType)(int device_index);
  54. // Function to get the platform dependent type of a sensor
  55. int (*GetDeviceNonPortableType)(int device_index);
  56. // Function to get the current instance id of the sensor located at device_index
  57. SDL_SensorID (*GetDeviceInstanceID)(int device_index);
  58. /* Function to open a sensor for use.
  59. The sensor to open is specified by the device index.
  60. It returns 0, or -1 if there is an error.
  61. */
  62. bool (*Open)(SDL_Sensor *sensor, int device_index);
  63. /* Function to update the state of a sensor - called as a device poll.
  64. * This function shouldn't update the sensor structure directly,
  65. * but instead should call SDL_SendSensorUpdate() to deliver events
  66. * and update sensor device state.
  67. */
  68. void (*Update)(SDL_Sensor *sensor);
  69. // Function to close a sensor after use
  70. void (*Close)(SDL_Sensor *sensor);
  71. // Function to perform any system-specific sensor related cleanup
  72. void (*Quit)(void);
  73. } SDL_SensorDriver;
  74. // The available sensor drivers
  75. extern SDL_SensorDriver SDL_ANDROID_SensorDriver;
  76. extern SDL_SensorDriver SDL_COREMOTION_SensorDriver;
  77. extern SDL_SensorDriver SDL_WINDOWS_SensorDriver;
  78. extern SDL_SensorDriver SDL_DUMMY_SensorDriver;
  79. extern SDL_SensorDriver SDL_VITA_SensorDriver;
  80. extern SDL_SensorDriver SDL_N3DS_SensorDriver;
  81. #endif // SDL_syssensor_h_