1 /* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20 */ 21 22 #ifndef SDL_syssensor_c_h_ 23 #define SDL_syssensor_c_h_ 24 25 #include "SDL_config.h" 26 27 /* This is the system specific header for the SDL sensor API */ 28 29 #include "SDL_sensor.h" 30 #include "SDL_sensor_c.h" 31 32 /* The SDL sensor structure */ 33 struct _SDL_Sensor 34 { 35 SDL_SensorID instance_id; /* Device instance, monotonically increasing from 0 */ 36 char *name; /* Sensor name - system dependent */ 37 SDL_SensorType type; /* Type of the sensor */ 38 int non_portable_type; /* Platform dependent type of the sensor */ 39 40 float data[16]; /* The current state of the sensor */ 41 42 struct _SDL_SensorDriver *driver; 43 44 struct sensor_hwdata *hwdata; /* Driver dependent information */ 45 46 int ref_count; /* Reference count for multiple opens */ 47 48 struct _SDL_Sensor *next; /* pointer to next sensor we have allocated */ 49 }; 50 51 typedef struct _SDL_SensorDriver 52 { 53 /* Function to scan the system for sensors. 54 * sensor 0 should be the system default sensor. 55 * This function should return 0, or -1 on an unrecoverable fatal error. 56 */ 57 int (*Init)(void); 58 59 /* Function to return the number of sensors available right now */ 60 int (*GetCount)(void); 61 62 /* Function to check to see if the available sensors have changed */ 63 void (*Detect)(void); 64 65 /* Function to get the device-dependent name of a sensor */ 66 const char *(*GetDeviceName)(int device_index); 67 68 /* Function to get the type of a sensor */ 69 SDL_SensorType (*GetDeviceType)(int device_index); 70 71 /* Function to get the platform dependent type of a sensor */ 72 int (*GetDeviceNonPortableType)(int device_index); 73 74 /* Function to get the current instance id of the sensor located at device_index */ 75 SDL_SensorID (*GetDeviceInstanceID)(int device_index); 76 77 /* Function to open a sensor for use. 78 The sensor to open is specified by the device index. 79 It returns 0, or -1 if there is an error. 80 */ 81 int (*Open)(SDL_Sensor * sensor, int device_index); 82 83 /* Function to update the state of a sensor - called as a device poll. 84 * This function shouldn't update the sensor structure directly, 85 * but instead should call SDL_PrivateSensorUpdate() to deliver events 86 * and update sensor device state. 87 */ 88 void (*Update)(SDL_Sensor * sensor); 89 90 /* Function to close a sensor after use */ 91 void (*Close)(SDL_Sensor * sensor); 92 93 /* Function to perform any system-specific sensor related cleanup */ 94 void (*Quit)(void); 95 96 } SDL_SensorDriver; 97 98 /* The available sensor drivers */ 99 extern SDL_SensorDriver SDL_ANDROID_SensorDriver; 100 extern SDL_SensorDriver SDL_COREMOTION_SensorDriver; 101 extern SDL_SensorDriver SDL_WINDOWS_SensorDriver; 102 extern SDL_SensorDriver SDL_DUMMY_SensorDriver; 103 104 #endif /* SDL_syssensor_h_ */ 105 106 /* vi: set ts=4 sw=4 expandtab: */ 107