SDL_sensor_c.h File Reference
`#include "SDL_config.h"`
`#include "SDL_sensor.h"`
Include dependency graph for SDL_sensor_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

SDL_SensorID | SDL_GetNextSensorInstanceID (void)
int | SDL_SensorInit (void)
void | SDL_SensorQuit (void)
int | SDL_PrivateSensorUpdate (SDL_Sensor *sensor, float *data, int num_values)

## Function Documentation

## SDL_GetNextSensorInstanceID()

SDL_SensorID SDL_GetNextSensorInstanceID | ( | void |  | ) |

Definition at line 112 of file SDL_sensor.c.

{
return SDL_AtomicIncRef(&SDL_next_sensor_instance_id);
}

References SDL_AtomicIncRef, and SDL_next_sensor_instance_id.

## SDL_PrivateSensorUpdate()

int SDL_PrivateSensorUpdate | ( | SDL_Sensor * | sensor,
|  | float * | data,
|  | int | num_values
| ) |  |

Definition at line 476 of file SDL_sensor.c.

{
int posted;
/* Allow duplicate events, for things like steps and heartbeats */
/* Update internal sensor state */
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(sensor->data, data, num_values*sizeof(*data));
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_SENSORUPDATE;
event.sensor.which = sensor->instance_id;
num_values = SDL_min(num_values, SDL_arraysize(event.sensor.data));
SDL_memset(event.sensor.data, 0, sizeof(event.sensor.data));
SDL_memcpy(event.sensor.data, data, num_values*sizeof(*data));
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return posted;
}

References SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_JOYAXISMOTION, SDL_memcpy, SDL_memset, SDL_min, SDL_PushEvent, and SDL_SENSORUPDATE.

## SDL_SensorInit()

int SDL_SensorInit | ( | void |  | ) |

Definition at line 69 of file SDL_sensor.c.

{
int i, status;
/* Create the sensor list lock */
if (!SDL_sensor_lock) {
SDL_sensor_lock = SDL_CreateMutex();
}
#if !SDL_EVENTS_DISABLED
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
return -1;
}
#endif /* !SDL_EVENTS_DISABLED */
status = -1;
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
if (SDL_sensor_drivers[i]->Init() >= 0) {
status = 0;
}
}
return status;
}

References i, SDL_arraysize, SDL_CreateMutex, SDL_INIT_EVENTS, SDL_InitSubSystem, SDL_sensor_drivers, and SDL_sensor_lock.

Referenced by SDL_InitSubSystem().

## SDL_SensorQuit()

void SDL_SensorQuit | ( | void |  | ) |

Definition at line 440 of file SDL_sensor.c.

{
int i;
/* Make sure we're not getting called in the middle of updating sensors */
SDL_assert(!SDL_updating_sensor);
SDL_LockSensors();
/* Stop the event polling */
while (SDL_sensors) {
SDL_sensors->ref_count = 1;
SDL_SensorClose(SDL_sensors);
}
/* Quit the sensor setup */
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
SDL_sensor_drivers[i]->Quit();
}
SDL_UnlockSensors();
#if !SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
if (SDL_sensor_lock) {
SDL_DestroyMutex(SDL_sensor_lock);
SDL_sensor_lock = NULL;
}
}

References i, NULL, SDL_arraysize, SDL_assert, SDL_DestroyMutex, SDL_INIT_EVENTS, SDL_LockSensors(), SDL_QuitSubSystem, SDL_sensor_drivers, SDL_sensor_lock, SDL_SensorClose(), SDL_sensors, SDL_UnlockSensors(), and SDL_updating_sensor.

Referenced by SDL_QuitSubSystem().

SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:386
SDL_updating_sensor
static SDL_bool SDL_updating_sensor
Definition: SDL_sensor.c:47
NULL
#define NULL
Definition: begin_code.h:167
SDL_LockSensors
static void SDL_LockSensors(void)
Definition: SDL_sensor.c:52
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:83
SDL_AtomicIncRef
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
Definition: SDL_atomic.h:252
SDL_QuitSubSystem
#define SDL_QuitSubSystem
Definition: SDL_dynapi_overrides.h:56
SDL_CreateMutex
#define SDL_CreateMutex
Definition: SDL_dynapi_overrides.h:259
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:759
SDL_InitSubSystem
#define SDL_InitSubSystem
Definition: SDL_dynapi_overrides.h:55
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_memcpy
#define SDL_memcpy
Definition: SDL_dynapi_overrides.h:387
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:772
SDL_SENSORUPDATE
@ SDL_SENSORUPDATE
Definition: SDL_events.h:151
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_min
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
SDL_JOYAXISMOTION
@ SDL_JOYAXISMOTION
Definition: SDL_events.h:111
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_sensor_drivers
static SDL_SensorDriver * SDL_sensor_drivers[]
Definition: SDL_sensor.c:35
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_next_sensor_instance_id
static SDL_atomic_t SDL_next_sensor_instance_id
Definition: SDL_sensor.c:49
SDL_SensorClose
void SDL_SensorClose(SDL_Sensor *sensor)
Definition: SDL_sensor.c:390
SDL_sensors
static SDL_Sensor * SDL_sensors
Definition: SDL_sensor.c:46
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:263
SDL_sensor_lock
static SDL_mutex * SDL_sensor_lock
Definition: SDL_sensor.c:48
SDL_Event
General event structure.
Definition: SDL_events.h:557
i
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)
Definition: SDL_x11sym.h:50
SDL_UnlockSensors
static void SDL_UnlockSensors(void)
Definition: SDL_sensor.c:60