SDL  2.0
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.

References SDL_AtomicIncRef.

113 {
115 }
static SDL_atomic_t SDL_next_sensor_instance_id
Definition: SDL_sensor.c:49
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
Definition: SDL_atomic.h:234

§ SDL_PrivateSensorUpdate()

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

Definition at line 476 of file SDL_sensor.c.

References SDL_SensorEvent::data, SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_JOYAXISMOTION, SDL_memcpy, SDL_memset, SDL_min, SDL_PushEvent, SDL_SENSORUPDATE, and SDL_Event::sensor.

477 {
478  int posted;
479 
480  /* Allow duplicate events, for things like steps and heartbeats */
481 
482  /* Update internal sensor state */
483  num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
484  SDL_memcpy(sensor->data, data, num_values*sizeof(*data));
485 
486  /* Post the event, if desired */
487  posted = 0;
488 #if !SDL_EVENTS_DISABLED
491  event.type = SDL_SENSORUPDATE;
492  event.sensor.which = sensor->instance_id;
493  num_values = SDL_min(num_values, SDL_arraysize(event.sensor.data));
494  SDL_memset(event.sensor.data, 0, sizeof(event.sensor.data));
495  SDL_memcpy(event.sensor.data, data, num_values*sizeof(*data));
496  posted = SDL_PushEvent(&event) == 1;
497  }
498 #endif /* !SDL_EVENTS_DISABLED */
499  return posted;
500 }
#define SDL_min(x, y)
Definition: SDL_stdinc.h:406
#define SDL_ENABLE
Definition: SDL_events.h:756
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
SDL_SensorEvent sensor
Definition: SDL_events.h:578
#define SDL_memcpy
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
struct _cl_event * event
#define SDL_PushEvent
float data[6]
Definition: SDL_events.h:503
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
General event structure.
Definition: SDL_events.h:557
#define SDL_memset

§ SDL_SensorInit()

int SDL_SensorInit ( void  )

Definition at line 69 of file SDL_sensor.c.

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

Referenced by SDL_InitSubSystem().

70 {
71  int i, status;
72 
73  /* Create the sensor list lock */
74  if (!SDL_sensor_lock) {
76  }
77 
78 #if !SDL_EVENTS_DISABLED
80  return -1;
81  }
82 #endif /* !SDL_EVENTS_DISABLED */
83 
84  status = -1;
85  for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
86  if (SDL_sensor_drivers[i]->Init() >= 0) {
87  status = 0;
88  }
89  }
90  return status;
91 }
#define SDL_INIT_EVENTS
Definition: SDL.h:83
static SDL_mutex * SDL_sensor_lock
Definition: SDL_sensor.c:48
#define SDL_CreateMutex
#define SDL_InitSubSystem
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
static SDL_SensorDriver * SDL_sensor_drivers[]
Definition: SDL_sensor.c:35
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115

§ SDL_SensorQuit()

void SDL_SensorQuit ( void  )

Definition at line 440 of file SDL_sensor.c.

References i, NULL, SDL_SensorDriver::Quit, SDL_arraysize, SDL_assert, SDL_DestroyMutex, SDL_INIT_EVENTS, SDL_LockSensors(), SDL_QuitSubSystem, SDL_SensorClose(), SDL_sensors, SDL_UnlockSensors(), and SDL_updating_sensor.

Referenced by SDL_QuitSubSystem().

441 {
442  int i;
443 
444  /* Make sure we're not getting called in the middle of updating sensors */
446 
447  SDL_LockSensors();
448 
449  /* Stop the event polling */
450  while (SDL_sensors) {
451  SDL_sensors->ref_count = 1;
453  }
454 
455  /* Quit the sensor setup */
456  for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
458  }
459 
461 
462 #if !SDL_EVENTS_DISABLED
464 #endif
465 
466  if (SDL_sensor_lock) {
469  }
470 }
#define SDL_INIT_EVENTS
Definition: SDL.h:83
static SDL_mutex * SDL_sensor_lock
Definition: SDL_sensor.c:48
#define SDL_QuitSubSystem
void SDL_SensorClose(SDL_Sensor *sensor)
Definition: SDL_sensor.c:390
void(* Quit)(void)
Definition: SDL_syssensor.h:94
static void SDL_LockSensors(void)
Definition: SDL_sensor.c:52
static SDL_bool SDL_updating_sensor
Definition: SDL_sensor.c:47
static SDL_Sensor * SDL_sensors
Definition: SDL_sensor.c:46
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
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_DestroyMutex
static SDL_SensorDriver * SDL_sensor_drivers[]
Definition: SDL_sensor.c:35
static void SDL_UnlockSensors(void)
Definition: SDL_sensor.c:60
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115