21 #include "../SDL_internal.h" 31 #if !SDL_EVENTS_DISABLED 32 #include "../events/SDL_events_c.h" 36 #ifdef SDL_SENSOR_ANDROID 39 #ifdef SDL_SENSOR_COREMOTION 42 #if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED) 54 if (SDL_sensor_lock) {
62 if (SDL_sensor_lock) {
74 if (!SDL_sensor_lock) {
78 #if !SDL_EVENTS_DISABLED 86 if (SDL_sensor_drivers[i]->Init() >= 0) {
99 int i, total_sensors = 0;
102 total_sensors += SDL_sensor_drivers[
i]->
GetCount();
105 return total_sensors;
124 int i, num_sensors, total_sensors = 0;
126 if (device_index >= 0) {
128 num_sensors = SDL_sensor_drivers[
i]->
GetCount();
129 if (device_index < num_sensors) {
130 *driver = SDL_sensor_drivers[
i];
131 *driver_index = device_index;
134 device_index -= num_sensors;
135 total_sensors += num_sensors;
139 SDL_SetError(
"There are %d sensors available", total_sensors);
220 SDL_Sensor *sensorlist;
221 const char *sensorname =
NULL;
236 if (instance_id == sensorlist->instance_id) {
242 sensorlist = sensorlist->next;
246 sensor = (SDL_Sensor *)
SDL_calloc(
sizeof(*sensor), 1);
247 if (sensor ==
NULL) {
252 sensor->driver = driver;
253 sensor->instance_id = instance_id;
257 if (driver->
Open(sensor, device_index) < 0) {
292 for (sensor =
SDL_sensors; sensor; sensor = sensor->next) {
293 if (sensor->instance_id == instance_id) {
309 if (sensor ==
NULL) {
355 return sensor->non_portable_type;
368 return sensor->instance_id;
382 SDL_memcpy(data, sensor->data, num_values*
sizeof(*data));
392 SDL_Sensor *sensorlist;
393 SDL_Sensor *sensorlistprev;
402 if (--sensor->ref_count > 0) {
412 sensor->driver->Close(sensor);
413 sensor->hwdata =
NULL;
416 sensorlistprev =
NULL;
418 if (sensor == sensorlist) {
419 if (sensorlistprev) {
421 sensorlistprev->next = sensorlist->next;
427 sensorlistprev = sensorlist;
428 sensorlist = sensorlist->next;
457 SDL_sensor_drivers[
i]->
Quit();
462 #if !SDL_EVENTS_DISABLED 466 if (SDL_sensor_lock) {
468 SDL_sensor_lock =
NULL;
484 SDL_memcpy(sensor->data, data, num_values*
sizeof(*data));
488 #if !SDL_EVENTS_DISABLED 492 event.sensor.which = sensor->instance_id;
525 for (sensor =
SDL_sensors; sensor; sensor = sensor->next) {
526 sensor->driver->Update(sensor);
534 for (sensor =
SDL_sensors; sensor; sensor = sensor->next) {
535 if (sensor->ref_count <= 0) {
544 SDL_sensor_drivers[
i]->
Detect();
SDL_SensorID(* GetDeviceInstanceID)(int device_index)
static SDL_mutex * SDL_sensor_lock
int SDL_SensorGetData(SDL_Sensor *sensor, float *data, int num_values)
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
int(* GetDeviceNonPortableType)(int device_index)
#define SDL_QuitSubSystem
void SDL_SensorClose(SDL_Sensor *sensor)
int(* Open)(SDL_Sensor *sensor, int device_index)
SDL_SensorType SDL_SensorGetType(SDL_Sensor *sensor)
Get the type of a sensor.
SDL_SensorDriver SDL_ANDROID_SensorDriver
SDL_SensorType(* GetDeviceType)(int device_index)
#define SDL_InitSubSystem
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
const char *(* GetDeviceName)(int device_index)
int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values)
SDL_SensorDriver SDL_DUMMY_SensorDriver
void(* Update)(SDL_Sensor *sensor)
GLuint const GLchar * name
int SDL_SensorGetNonPortableType(SDL_Sensor *sensor)
Get the platform dependent type of a sensor.
static void SDL_LockSensors(void)
#define SDL_GetEventState(type)
static SDL_bool SDL_updating_sensor
int SDL_NumSensors(void)
Count the number of sensors attached to the system right now.
SDL_SensorID SDL_GetNextSensorInstanceID()
SDL_SensorType SDL_SensorGetDeviceNonPortableType(int device_index)
Get the platform dependent type of a sensor.
SDL_Sensor * SDL_SensorOpen(int device_index)
Open a sensor for use.
SDL_SensorID SDL_SensorGetDeviceInstanceID(int device_index)
Get the instance ID of a sensor.
void SDL_SensorUpdate(void)
SDL_SensorType SDL_SensorGetDeviceType(int device_index)
Get the type of a sensor.
static SDL_atomic_t SDL_next_sensor_instance_id
static SDL_Sensor * SDL_sensors
const char * SDL_SensorGetDeviceName(int device_index)
Get the implementation dependent name of a sensor.
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
SDL_SensorID SDL_SensorGetInstanceID(SDL_Sensor *sensor)
Get the instance ID of a sensor.
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
SDL_SensorDriver SDL_COREMOTION_SensorDriver
static SDL_SensorDriver * SDL_sensor_drivers[]
void SDL_SensorQuit(void)
static SDL_bool SDL_GetDriverAndSensorIndex(int device_index, SDL_SensorDriver **driver, int *driver_index)
GLuint GLuint GLsizei GLenum type
static void SDL_UnlockSensors(void)
#define SDL_arraysize(array)
static int SDL_PrivateSensorValid(SDL_Sensor *sensor)
const char * SDL_SensorGetName(SDL_Sensor *sensor)
Get the implementation dependent name of a sensor.
SDL_Sensor * SDL_SensorFromInstanceID(SDL_SensorID instance_id)