|
SDL
2.0
|
#include "../SDL_internal.h"#include "SDL.h"#include "SDL_atomic.h"#include "SDL_events.h"#include "SDL_syssensor.h"#include "../events/SDL_events_c.h"
Include dependency graph for SDL_sensor.c:Go to the source code of this file.
Functions | |
| void | SDL_LockSensors (void) |
| void | SDL_UnlockSensors (void) |
| int | SDL_SensorInit (void) |
| int | SDL_NumSensors (void) |
| Count the number of sensors attached to the system right now. More... | |
| SDL_SensorID | SDL_GetNextSensorInstanceID () |
| static SDL_bool | SDL_GetDriverAndSensorIndex (int device_index, SDL_SensorDriver **driver, int *driver_index) |
| const char * | SDL_SensorGetDeviceName (int device_index) |
| Get the implementation dependent name of a sensor. More... | |
| SDL_SensorType | SDL_SensorGetDeviceType (int device_index) |
| Get the type of a sensor. More... | |
| int | SDL_SensorGetDeviceNonPortableType (int device_index) |
| Get the platform dependent type of a sensor. More... | |
| SDL_SensorID | SDL_SensorGetDeviceInstanceID (int device_index) |
| Get the instance ID of a sensor. More... | |
| SDL_Sensor * | SDL_SensorOpen (int device_index) |
| Open a sensor for use. More... | |
| SDL_Sensor * | SDL_SensorFromInstanceID (SDL_SensorID instance_id) |
| static int | SDL_PrivateSensorValid (SDL_Sensor *sensor) |
| const char * | SDL_SensorGetName (SDL_Sensor *sensor) |
| Get the implementation dependent name of a sensor. More... | |
| SDL_SensorType | SDL_SensorGetType (SDL_Sensor *sensor) |
| Get the type of a sensor. More... | |
| int | SDL_SensorGetNonPortableType (SDL_Sensor *sensor) |
| Get the platform dependent type of a sensor. More... | |
| SDL_SensorID | SDL_SensorGetInstanceID (SDL_Sensor *sensor) |
| Get the instance ID of a sensor. More... | |
| int | SDL_SensorGetData (SDL_Sensor *sensor, float *data, int num_values) |
| void | SDL_SensorClose (SDL_Sensor *sensor) |
| void | SDL_SensorQuit (void) |
| int | SDL_PrivateSensorUpdate (SDL_Sensor *sensor, float *data, int num_values) |
| void | SDL_SensorUpdate (void) |
Variables | |
| static SDL_SensorDriver * | SDL_sensor_drivers [] |
| static SDL_Sensor * | SDL_sensors = NULL |
| static SDL_bool | SDL_updating_sensor = SDL_FALSE |
| static SDL_mutex * | SDL_sensor_lock = NULL |
| static SDL_atomic_t | SDL_next_sensor_instance_id |
|
static |
Definition at line 124 of file SDL_sensor.c.
References SDL_SensorDriver::GetCount, i, SDL_arraysize, SDL_FALSE, SDL_sensor_drivers, SDL_SetError, and SDL_TRUE.
Referenced by SDL_SensorGetDeviceInstanceID(), SDL_SensorGetDeviceName(), SDL_SensorGetDeviceNonPortableType(), SDL_SensorGetDeviceType(), and SDL_SensorOpen().
| SDL_SensorID SDL_GetNextSensorInstanceID | ( | void | ) |
Definition at line 114 of file SDL_sensor.c.
References SDL_AtomicIncRef, and SDL_next_sensor_instance_id.
Gyroscope sensor
The gyroscope returns the current rate of rotation in radians per second. The rotation is positive in the counter-clockwise direction. That is, an observer looking from a positive location on one of the axes would see positive rotation on that axis when it appeared to be rotating counter-clockwise.
values[0]: Angular speed around the x axis (pitch) values[1]: Angular speed around the y axis (yaw) values[2]: Angular speed around the z axis (roll)
For phones held in portrait mode and game controllers held in front of you, the axes are defined as follows: -X ... +X : left ... right -Y ... +Y : bottom ... top -Z ... +Z : farther ... closer
The axis data is not changed when the phone or controller is rotated.
If you are using the sensor API or handling events from multiple threads you should use these locking functions to protect access to the sensors.
In particular, you are guaranteed that the sensor list won't change, so the API functions that take a sensor index will be valid, and sensor events will not be delivered.
Definition at line 54 of file SDL_sensor.c.
References SDL_LockMutex, and SDL_sensor_lock.
Referenced by SDL_NumSensors(), SDL_SensorClose(), SDL_SensorFromInstanceID(), SDL_SensorGetDeviceInstanceID(), SDL_SensorGetDeviceName(), SDL_SensorGetDeviceNonPortableType(), SDL_SensorGetDeviceType(), SDL_SensorOpen(), SDL_SensorQuit(), and SDL_SensorUpdate().
Count the number of sensors attached to the system right now.
Definition at line 99 of file SDL_sensor.c.
References SDL_SensorDriver::GetCount, i, SDL_arraysize, SDL_LockSensors(), SDL_sensor_drivers, and SDL_UnlockSensors().
Definition at line 478 of file SDL_sensor.c.
References SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_memcpy, SDL_memset, SDL_min, SDL_PushEvent, and SDL_SENSORUPDATE.
|
static |
Definition at line 307 of file SDL_sensor.c.
References NULL, and SDL_SetError.
Referenced by SDL_SensorClose(), SDL_SensorGetData(), SDL_SensorGetInstanceID(), SDL_SensorGetName(), SDL_SensorGetNonPortableType(), and SDL_SensorGetType().
| void SDL_SensorClose | ( | SDL_Sensor * | sensor | ) |
Close a sensor previously opened with SDL_SensorOpen()
Definition at line 392 of file SDL_sensor.c.
References NULL, SDL_free, SDL_LockSensors(), SDL_PrivateSensorValid(), SDL_sensors, SDL_UnlockSensors(), and SDL_updating_sensor.
Referenced by SDL_SensorQuit(), and SDL_SensorUpdate().
| SDL_Sensor* SDL_SensorFromInstanceID | ( | SDL_SensorID | instance_id | ) |
Return the SDL_Sensor associated with an instance id.
Definition at line 289 of file SDL_sensor.c.
References SDL_LockSensors(), SDL_sensors, and SDL_UnlockSensors().
Get the current state of an opened sensor.
The number of values and interpretation of the data is sensor dependent.
| sensor | The sensor to query |
| data | A pointer filled with the current sensor state |
| num_values | The number of values to write to data |
Definition at line 377 of file SDL_sensor.c.
References SDL_arraysize, SDL_memcpy, SDL_min, and SDL_PrivateSensorValid().
| SDL_SensorID SDL_SensorGetDeviceInstanceID | ( | int | device_index | ) |
Get the instance ID of a sensor.
This can be called before any sensors are opened.
Definition at line 195 of file SDL_sensor.c.
References SDL_SensorDriver::GetDeviceInstanceID, SDL_GetDriverAndSensorIndex(), SDL_LockSensors(), and SDL_UnlockSensors().
| const char* SDL_SensorGetDeviceName | ( | int | device_index | ) |
Get the implementation dependent name of a sensor.
This can be called before any sensors are opened.
Definition at line 149 of file SDL_sensor.c.
References SDL_SensorDriver::GetDeviceName, NULL, SDL_GetDriverAndSensorIndex(), SDL_LockSensors(), and SDL_UnlockSensors().
Get the platform dependent type of a sensor.
This can be called before any sensors are opened.
Definition at line 180 of file SDL_sensor.c.
References SDL_SensorDriver::GetDeviceNonPortableType, SDL_GetDriverAndSensorIndex(), SDL_LockSensors(), and SDL_UnlockSensors().
| SDL_SensorType SDL_SensorGetDeviceType | ( | int | device_index | ) |
Get the type of a sensor.
This can be called before any sensors are opened.
Definition at line 165 of file SDL_sensor.c.
References SDL_SensorDriver::GetDeviceType, SDL_GetDriverAndSensorIndex(), SDL_LockSensors(), SDL_SENSOR_INVALID, and SDL_UnlockSensors().
| SDL_SensorID SDL_SensorGetInstanceID | ( | SDL_Sensor * | sensor | ) |
Get the instance ID of a sensor.
This can be called before any sensors are opened.
Definition at line 364 of file SDL_sensor.c.
References SDL_PrivateSensorValid().
| const char* SDL_SensorGetName | ( | SDL_Sensor * | sensor | ) |
Get the implementation dependent name of a sensor.
Definition at line 325 of file SDL_sensor.c.
References NULL, and SDL_PrivateSensorValid().
| int SDL_SensorGetNonPortableType | ( | SDL_Sensor * | sensor | ) |
Get the platform dependent type of a sensor.
This can be called before any sensors are opened.
Definition at line 351 of file SDL_sensor.c.
References SDL_PrivateSensorValid().
| SDL_SensorType SDL_SensorGetType | ( | SDL_Sensor * | sensor | ) |
Get the type of a sensor.
This can be called before any sensors are opened.
Definition at line 338 of file SDL_sensor.c.
References SDL_PrivateSensorValid(), and SDL_SENSOR_INVALID.
Definition at line 71 of file SDL_sensor.c.
References i, SDL_arraysize, SDL_CreateMutex, SDL_INIT_EVENTS, SDL_InitSubSystem, SDL_sensor_drivers, and SDL_sensor_lock.
Referenced by SDL_InitSubSystem().
| SDL_Sensor* SDL_SensorOpen | ( | int | device_index | ) |
Open a sensor for use.
The index passed as an argument refers to the N'th sensor on the system.
Definition at line 217 of file SDL_sensor.c.
References SDL_SensorDriver::GetDeviceInstanceID, SDL_SensorDriver::GetDeviceName, SDL_SensorDriver::GetDeviceNonPortableType, SDL_SensorDriver::GetDeviceType, NULL, SDL_SensorDriver::Open, SDL_calloc, SDL_free, SDL_GetDriverAndSensorIndex(), SDL_LockSensors(), SDL_OutOfMemory, SDL_sensors, SDL_strdup, SDL_UnlockSensors(), and SDL_SensorDriver::Update.
Definition at line 442 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_sensor_drivers, SDL_sensor_lock, SDL_SensorClose(), SDL_sensors, SDL_UnlockSensors(), and SDL_updating_sensor.
Referenced by SDL_QuitSubSystem().
Update the current state of the open sensors.
This is called automatically by the event loop if sensor events are enabled.
This needs to be called from the thread that initialized the sensor subsystem.
Definition at line 505 of file SDL_sensor.c.
References SDL_SensorDriver::Detect, i, SDL_arraysize, SDL_FALSE, SDL_INIT_SENSOR, SDL_LockSensors(), SDL_sensor_drivers, SDL_SensorClose(), SDL_sensors, SDL_TRUE, SDL_UnlockSensors(), SDL_updating_sensor, and SDL_WasInit.
Definition at line 62 of file SDL_sensor.c.
References SDL_sensor_lock, and SDL_UnlockMutex.
Referenced by SDL_NumSensors(), SDL_SensorClose(), SDL_SensorFromInstanceID(), SDL_SensorGetDeviceInstanceID(), SDL_SensorGetDeviceName(), SDL_SensorGetDeviceNonPortableType(), SDL_SensorGetDeviceType(), SDL_SensorOpen(), SDL_SensorQuit(), and SDL_SensorUpdate().
|
static |
Definition at line 51 of file SDL_sensor.c.
Referenced by SDL_GetNextSensorInstanceID().
|
static |
Definition at line 34 of file SDL_sensor.c.
Referenced by SDL_GetDriverAndSensorIndex(), SDL_NumSensors(), SDL_SensorInit(), SDL_SensorQuit(), and SDL_SensorUpdate().
Definition at line 50 of file SDL_sensor.c.
Referenced by SDL_LockSensors(), SDL_SensorInit(), SDL_SensorQuit(), and SDL_UnlockSensors().
|
static |
Definition at line 48 of file SDL_sensor.c.
Referenced by SDL_SensorClose(), SDL_SensorFromInstanceID(), SDL_SensorOpen(), SDL_SensorQuit(), and SDL_SensorUpdate().
Definition at line 49 of file SDL_sensor.c.
Referenced by SDL_SensorClose(), SDL_SensorQuit(), and SDL_SensorUpdate().