2018-08-21 12:11:34 -07:00
|
|
|
/*
|
|
|
|
|
Simple DirectMedia Layer
|
2025-01-01 07:45:41 -08:00
|
|
|
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
2018-08-21 12:11:34 -07:00
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
|
appreciated but is not required.
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
misrepresented as being the original software.
|
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
*/
|
2022-11-29 18:34:15 -08:00
|
|
|
#include "SDL_internal.h"
|
2018-08-21 12:11:34 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// This is the sensor API for Simple DirectMedia Layer
|
2018-08-21 12:11:34 -07:00
|
|
|
|
|
|
|
|
#include "SDL_syssensor.h"
|
|
|
|
|
|
|
|
|
|
#include "../events/SDL_events_c.h"
|
2023-06-19 16:17:34 -07:00
|
|
|
#include "../joystick/SDL_gamepad_c.h"
|
2018-08-21 12:11:34 -07:00
|
|
|
|
|
|
|
|
static SDL_SensorDriver *SDL_sensor_drivers[] = {
|
|
|
|
|
#ifdef SDL_SENSOR_ANDROID
|
|
|
|
|
&SDL_ANDROID_SensorDriver,
|
|
|
|
|
#endif
|
2018-08-21 17:24:12 -07:00
|
|
|
#ifdef SDL_SENSOR_COREMOTION
|
|
|
|
|
&SDL_COREMOTION_SensorDriver,
|
|
|
|
|
#endif
|
2020-04-08 08:34:27 -07:00
|
|
|
#ifdef SDL_SENSOR_WINDOWS
|
2021-11-12 08:28:02 -08:00
|
|
|
&SDL_WINDOWS_SensorDriver,
|
2020-04-08 08:34:27 -07:00
|
|
|
#endif
|
2022-09-20 22:45:24 -04:00
|
|
|
#ifdef SDL_SENSOR_VITA
|
|
|
|
|
&SDL_VITA_SensorDriver,
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef SDL_SENSOR_N3DS
|
|
|
|
|
&SDL_N3DS_SensorDriver,
|
|
|
|
|
#endif
|
2018-08-21 13:29:21 -07:00
|
|
|
#if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED)
|
|
|
|
|
&SDL_DUMMY_SensorDriver
|
|
|
|
|
#endif
|
2018-08-21 12:11:34 -07:00
|
|
|
};
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
#ifndef SDL_THREAD_SAFETY_ANALYSIS
|
|
|
|
|
static
|
|
|
|
|
#endif
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
SDL_Mutex *SDL_sensor_lock = NULL; // This needs to support recursive locks
|
2023-08-08 22:08:40 -07:00
|
|
|
static SDL_AtomicInt SDL_sensor_lock_pending;
|
|
|
|
|
static int SDL_sensors_locked;
|
2024-08-22 09:21:26 -07:00
|
|
|
static bool SDL_sensors_initialized;
|
2022-12-13 14:03:40 -08:00
|
|
|
static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
#define CHECK_SENSOR_MAGIC(sensor, result) \
|
2024-06-03 04:09:28 -07:00
|
|
|
if (!SDL_ObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR)) { \
|
|
|
|
|
SDL_InvalidParamError("sensor"); \
|
|
|
|
|
SDL_UnlockSensors(); \
|
2024-08-22 17:33:49 -07:00
|
|
|
return result; \
|
2023-08-08 22:08:40 -07:00
|
|
|
}
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
bool SDL_SensorsInitialized(void)
|
2023-08-08 22:08:40 -07:00
|
|
|
{
|
|
|
|
|
return SDL_sensors_initialized;
|
|
|
|
|
}
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2023-08-08 22:08:40 -07:00
|
|
|
void SDL_LockSensors(void)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2023-08-08 22:08:40 -07:00
|
|
|
(void)SDL_AtomicIncRef(&SDL_sensor_lock_pending);
|
2022-12-13 14:03:40 -08:00
|
|
|
SDL_LockMutex(SDL_sensor_lock);
|
2023-08-08 22:08:40 -07:00
|
|
|
(void)SDL_AtomicDecRef(&SDL_sensor_lock_pending);
|
|
|
|
|
|
|
|
|
|
++SDL_sensors_locked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SDL_UnlockSensors(void)
|
|
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
bool last_unlock = false;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
--SDL_sensors_locked;
|
|
|
|
|
|
|
|
|
|
if (!SDL_sensors_initialized) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// NOTE: There's a small window here where another thread could lock the mutex after we've checked for pending locks
|
2024-09-16 23:21:31 -07:00
|
|
|
if (!SDL_sensors_locked && SDL_GetAtomicInt(&SDL_sensor_lock_pending) == 0) {
|
2024-08-22 09:21:26 -07:00
|
|
|
last_unlock = true;
|
2023-08-08 22:08:40 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The last unlock after sensors are uninitialized will cleanup the mutex,
|
|
|
|
|
* allowing applications to lock sensors while reinitializing the system.
|
|
|
|
|
*/
|
|
|
|
|
if (last_unlock) {
|
|
|
|
|
SDL_Mutex *sensor_lock = SDL_sensor_lock;
|
|
|
|
|
|
|
|
|
|
SDL_LockMutex(sensor_lock);
|
|
|
|
|
{
|
|
|
|
|
SDL_UnlockMutex(SDL_sensor_lock);
|
|
|
|
|
|
|
|
|
|
SDL_sensor_lock = NULL;
|
|
|
|
|
}
|
|
|
|
|
SDL_UnlockMutex(sensor_lock);
|
|
|
|
|
SDL_DestroyMutex(sensor_lock);
|
|
|
|
|
} else {
|
|
|
|
|
SDL_UnlockMutex(SDL_sensor_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
bool SDL_SensorsLocked(void)
|
2023-08-08 22:08:40 -07:00
|
|
|
{
|
2023-11-03 09:27:29 -07:00
|
|
|
return (SDL_sensors_locked > 0);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
2023-08-08 22:08:40 -07:00
|
|
|
void SDL_AssertSensorsLocked(void)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_assert(SDL_SensorsLocked());
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
bool SDL_InitSensors(void)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
int i;
|
|
|
|
|
bool status;
|
2018-08-21 12:11:34 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Create the sensor list lock
|
2022-11-27 17:38:43 +01:00
|
|
|
if (SDL_sensor_lock == NULL) {
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_sensor_lock = SDL_CreateMutex();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
if (!SDL_InitSubSystem(SDL_INIT_EVENTS)) {
|
|
|
|
|
return false;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_LockSensors();
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
SDL_sensors_initialized = true;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
status = false;
|
2018-08-21 12:11:34 -07:00
|
|
|
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
2024-08-22 17:33:49 -07:00
|
|
|
if (SDL_sensor_drivers[i]->Init()) {
|
|
|
|
|
status = true;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
if (!status) {
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_QuitSensors();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-21 12:11:34 -07:00
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
bool SDL_SensorsOpened(void)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2024-08-22 09:21:26 -07:00
|
|
|
bool opened;
|
2022-12-29 23:07:30 -08:00
|
|
|
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_LockSensors();
|
2022-12-29 23:07:30 -08:00
|
|
|
{
|
|
|
|
|
if (SDL_sensors != NULL) {
|
2024-08-22 09:21:26 -07:00
|
|
|
opened = true;
|
2022-12-29 23:07:30 -08:00
|
|
|
} else {
|
2024-08-22 09:21:26 -07:00
|
|
|
opened = false;
|
2022-12-27 18:10:06 -08:00
|
|
|
}
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
2022-12-29 23:07:30 -08:00
|
|
|
|
|
|
|
|
return opened;
|
2022-12-27 18:10:06 -08:00
|
|
|
}
|
|
|
|
|
|
2024-07-26 18:57:18 -07:00
|
|
|
SDL_SensorID *SDL_GetSensors(int *count)
|
2022-12-27 18:10:06 -08:00
|
|
|
{
|
|
|
|
|
int i, num_sensors, device_index;
|
|
|
|
|
int sensor_index = 0, total_sensors = 0;
|
|
|
|
|
SDL_SensorID *sensors;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
|
|
|
|
total_sensors += SDL_sensor_drivers[i]->GetCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sensors = (SDL_SensorID *)SDL_malloc((total_sensors + 1) * sizeof(*sensors));
|
|
|
|
|
if (sensors) {
|
2023-01-31 10:04:51 -08:00
|
|
|
if (count) {
|
|
|
|
|
*count = total_sensors;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-27 18:10:06 -08:00
|
|
|
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
|
|
|
|
num_sensors = SDL_sensor_drivers[i]->GetCount();
|
|
|
|
|
for (device_index = 0; device_index < num_sensors; ++device_index) {
|
|
|
|
|
SDL_assert(sensor_index < total_sensors);
|
|
|
|
|
sensors[sensor_index] = SDL_sensor_drivers[i]->GetDeviceInstanceID(device_index);
|
|
|
|
|
SDL_assert(sensors[sensor_index] > 0);
|
|
|
|
|
++sensor_index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SDL_assert(sensor_index == total_sensors);
|
|
|
|
|
sensors[sensor_index] = 0;
|
|
|
|
|
} else {
|
2023-01-31 10:04:51 -08:00
|
|
|
if (count) {
|
|
|
|
|
*count = 0;
|
|
|
|
|
}
|
2022-12-27 18:10:06 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
2024-07-26 18:57:18 -07:00
|
|
|
return sensors;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2022-12-27 18:10:06 -08:00
|
|
|
* Get the driver and device index for a sensor instance ID
|
2018-08-21 12:11:34 -07:00
|
|
|
* This should be called while the sensor lock is held, to prevent another thread from updating the list
|
|
|
|
|
*/
|
2024-08-22 09:21:26 -07:00
|
|
|
static bool SDL_GetDriverAndSensorIndex(SDL_SensorID instance_id, SDL_SensorDriver **driver, int *driver_index)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2022-12-27 18:10:06 -08:00
|
|
|
int i, num_sensors, device_index;
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2022-12-27 18:10:06 -08:00
|
|
|
if (instance_id > 0) {
|
2018-08-21 12:11:34 -07:00
|
|
|
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
|
|
|
|
num_sensors = SDL_sensor_drivers[i]->GetCount();
|
2022-12-27 18:10:06 -08:00
|
|
|
for (device_index = 0; device_index < num_sensors; ++device_index) {
|
|
|
|
|
SDL_SensorID sensor_id = SDL_sensor_drivers[i]->GetDeviceInstanceID(device_index);
|
|
|
|
|
if (sensor_id == instance_id) {
|
|
|
|
|
*driver = SDL_sensor_drivers[i];
|
|
|
|
|
*driver_index = device_index;
|
2024-08-22 09:21:26 -07:00
|
|
|
return true;
|
2022-12-27 18:10:06 -08:00
|
|
|
}
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-04 21:25:50 -08:00
|
|
|
SDL_SetError("Sensor %" SDL_PRIu32 " not found", instance_id);
|
2024-08-22 09:21:26 -07:00
|
|
|
return false;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the implementation dependent name of a sensor
|
|
|
|
|
*/
|
2024-07-14 15:22:03 -07:00
|
|
|
const char *SDL_GetSensorNameForID(SDL_SensorID instance_id)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
SDL_SensorDriver *driver;
|
2022-12-27 18:10:06 -08:00
|
|
|
int device_index;
|
2018-08-21 12:11:34 -07:00
|
|
|
const char *name = NULL;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
2022-12-27 18:10:06 -08:00
|
|
|
if (SDL_GetDriverAndSensorIndex(instance_id, &driver, &device_index)) {
|
2024-07-26 18:57:18 -07:00
|
|
|
name = SDL_GetPersistentString(driver->GetDeviceName(device_index));
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
2024-07-18 15:56:41 -07:00
|
|
|
return name;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
2024-07-14 15:22:03 -07:00
|
|
|
SDL_SensorType SDL_GetSensorTypeForID(SDL_SensorID instance_id)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
SDL_SensorDriver *driver;
|
2022-12-27 18:10:06 -08:00
|
|
|
int device_index;
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_SensorType type = SDL_SENSOR_INVALID;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
2022-12-27 18:10:06 -08:00
|
|
|
if (SDL_GetDriverAndSensorIndex(instance_id, &driver, &device_index)) {
|
2018-08-21 12:11:34 -07:00
|
|
|
type = driver->GetDeviceType(device_index);
|
|
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 15:22:03 -07:00
|
|
|
int SDL_GetSensorNonPortableTypeForID(SDL_SensorID instance_id)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
SDL_SensorDriver *driver;
|
2022-12-27 18:10:06 -08:00
|
|
|
int device_index;
|
2018-08-21 12:11:34 -07:00
|
|
|
int type = -1;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
2022-12-27 18:10:06 -08:00
|
|
|
if (SDL_GetDriverAndSensorIndex(instance_id, &driver, &device_index)) {
|
2018-08-21 12:11:34 -07:00
|
|
|
type = driver->GetDeviceNonPortableType(device_index);
|
|
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Open a sensor for use - the index passed as an argument refers to
|
|
|
|
|
* the N'th sensor on the system. This index is the value which will
|
|
|
|
|
* identify this sensor in future sensor events.
|
|
|
|
|
*
|
|
|
|
|
* This function returns a sensor identifier, or NULL if an error occurred.
|
|
|
|
|
*/
|
2022-12-27 18:10:06 -08:00
|
|
|
SDL_Sensor *SDL_OpenSensor(SDL_SensorID instance_id)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
SDL_SensorDriver *driver;
|
2022-12-27 18:10:06 -08:00
|
|
|
int device_index;
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_Sensor *sensor;
|
|
|
|
|
SDL_Sensor *sensorlist;
|
|
|
|
|
const char *sensorname = NULL;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
|
2022-12-27 18:10:06 -08:00
|
|
|
if (!SDL_GetDriverAndSensorIndex(instance_id, &driver, &device_index)) {
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sensorlist = SDL_sensors;
|
|
|
|
|
/* If the sensor is already open, return it
|
|
|
|
|
* it is important that we have a single sensor * for each instance id
|
|
|
|
|
*/
|
|
|
|
|
while (sensorlist) {
|
|
|
|
|
if (instance_id == sensorlist->instance_id) {
|
2022-11-30 12:51:59 -08:00
|
|
|
sensor = sensorlist;
|
|
|
|
|
++sensor->ref_count;
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
return sensor;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
sensorlist = sensorlist->next;
|
|
|
|
|
}
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Create and initialize the sensor
|
2024-09-09 03:00:34 +02:00
|
|
|
sensor = (SDL_Sensor *)SDL_calloc(1, sizeof(*sensor));
|
2023-11-09 22:29:15 +01:00
|
|
|
if (!sensor) {
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2024-08-22 09:21:26 -07:00
|
|
|
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, true);
|
2018-08-21 12:11:34 -07:00
|
|
|
sensor->driver = driver;
|
|
|
|
|
sensor->instance_id = instance_id;
|
|
|
|
|
sensor->type = driver->GetDeviceType(device_index);
|
|
|
|
|
sensor->non_portable_type = driver->GetDeviceNonPortableType(device_index);
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
if (!driver->Open(sensor, device_index)) {
|
2024-08-22 09:21:26 -07:00
|
|
|
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, false);
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_free(sensor);
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sensorname = driver->GetDeviceName(device_index);
|
|
|
|
|
if (sensorname) {
|
|
|
|
|
sensor->name = SDL_strdup(sensorname);
|
|
|
|
|
} else {
|
|
|
|
|
sensor->name = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Add sensor to list
|
2018-08-21 12:11:34 -07:00
|
|
|
++sensor->ref_count;
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Link the sensor in the list
|
2018-08-21 12:11:34 -07:00
|
|
|
sensor->next = SDL_sensors;
|
|
|
|
|
SDL_sensors = sensor;
|
|
|
|
|
|
|
|
|
|
driver->Update(sensor);
|
|
|
|
|
|
2022-12-27 18:10:06 -08:00
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
2018-08-21 12:11:34 -07:00
|
|
|
return sensor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find the SDL_Sensor that owns this instance id
|
|
|
|
|
*/
|
2024-07-14 12:06:35 -07:00
|
|
|
SDL_Sensor *SDL_GetSensorFromID(SDL_SensorID instance_id)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
SDL_Sensor *sensor;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
for (sensor = SDL_sensors; sensor; sensor = sensor->next) {
|
|
|
|
|
if (sensor->instance_id == instance_id) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
return sensor;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 16:59:51 -07:00
|
|
|
/*
|
|
|
|
|
* Get the properties associated with a sensor.
|
|
|
|
|
*/
|
|
|
|
|
SDL_PropertiesID SDL_GetSensorProperties(SDL_Sensor *sensor)
|
|
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
SDL_PropertiesID result;
|
2023-10-11 16:59:51 -07:00
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor, 0);
|
|
|
|
|
|
|
|
|
|
if (sensor->props == 0) {
|
|
|
|
|
sensor->props = SDL_CreateProperties();
|
|
|
|
|
}
|
2024-08-22 17:33:49 -07:00
|
|
|
result = sensor->props;
|
2023-10-11 16:59:51 -07:00
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
return result;
|
2023-10-11 16:59:51 -07:00
|
|
|
}
|
|
|
|
|
|
2018-08-21 12:11:34 -07:00
|
|
|
/*
|
|
|
|
|
* Get the friendly name of this sensor
|
|
|
|
|
*/
|
2022-12-27 06:23:39 -08:00
|
|
|
const char *SDL_GetSensorName(SDL_Sensor *sensor)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
const char *result;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor, NULL);
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
result = SDL_GetPersistentString(sensor->name);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_UnlockSensors();
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
return result;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the type of this sensor
|
|
|
|
|
*/
|
2022-12-27 06:23:39 -08:00
|
|
|
SDL_SensorType SDL_GetSensorType(SDL_Sensor *sensor)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
SDL_SensorType result;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor, SDL_SENSOR_INVALID);
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
result = sensor->type;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_UnlockSensors();
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
return result;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the platform dependent type of this sensor
|
|
|
|
|
*/
|
2022-12-27 06:23:39 -08:00
|
|
|
int SDL_GetSensorNonPortableType(SDL_Sensor *sensor)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
int result;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor, -1);
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
result = sensor->non_portable_type;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_UnlockSensors();
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
return result;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the instance id for this opened sensor
|
|
|
|
|
*/
|
2024-07-14 08:46:24 -07:00
|
|
|
SDL_SensorID SDL_GetSensorID(SDL_Sensor *sensor)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
SDL_SensorID result;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor, 0);
|
|
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
result = sensor->instance_id;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_UnlockSensors();
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
return result;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Get the current state of this sensor
|
|
|
|
|
*/
|
2024-09-18 07:52:28 -07:00
|
|
|
bool SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
2024-08-22 17:33:49 -07:00
|
|
|
CHECK_SENSOR_MAGIC(sensor, false);
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
|
|
|
|
|
SDL_memcpy(data, sensor->data, num_values * sizeof(*data));
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_UnlockSensors();
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
return true;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2022-12-27 06:23:39 -08:00
|
|
|
* Close a sensor previously opened with SDL_OpenSensor()
|
2018-08-21 12:11:34 -07:00
|
|
|
*/
|
2022-12-27 06:23:39 -08:00
|
|
|
void SDL_CloseSensor(SDL_Sensor *sensor)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
SDL_Sensor *sensorlist;
|
|
|
|
|
SDL_Sensor *sensorlistprev;
|
|
|
|
|
|
|
|
|
|
SDL_LockSensors();
|
2023-08-08 22:08:40 -07:00
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor,);
|
2018-08-21 12:11:34 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// First decrement ref count
|
2023-08-08 22:08:40 -07:00
|
|
|
if (--sensor->ref_count > 0) {
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2023-10-11 16:59:51 -07:00
|
|
|
SDL_DestroyProperties(sensor->props);
|
|
|
|
|
|
2023-08-08 22:08:40 -07:00
|
|
|
sensor->driver->Close(sensor);
|
|
|
|
|
sensor->hwdata = NULL;
|
2024-08-22 09:21:26 -07:00
|
|
|
SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, false);
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
sensorlist = SDL_sensors;
|
|
|
|
|
sensorlistprev = NULL;
|
|
|
|
|
while (sensorlist) {
|
|
|
|
|
if (sensor == sensorlist) {
|
|
|
|
|
if (sensorlistprev) {
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// unlink this entry
|
2023-08-08 22:08:40 -07:00
|
|
|
sensorlistprev->next = sensorlist->next;
|
|
|
|
|
} else {
|
|
|
|
|
SDL_sensors = sensor->next;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-08-08 22:08:40 -07:00
|
|
|
sensorlistprev = sensorlist;
|
|
|
|
|
sensorlist = sensorlist->next;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Free the data associated with this sensor
|
2024-07-18 15:56:41 -07:00
|
|
|
SDL_free(sensor->name);
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_free(sensor);
|
|
|
|
|
}
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-27 15:05:51 -08:00
|
|
|
void SDL_QuitSensors(void)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
2022-12-13 14:03:40 -08:00
|
|
|
SDL_LockSensors();
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Stop the event polling
|
2018-08-21 12:11:34 -07:00
|
|
|
while (SDL_sensors) {
|
|
|
|
|
SDL_sensors->ref_count = 1;
|
2022-12-27 06:23:39 -08:00
|
|
|
SDL_CloseSensor(SDL_sensors);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Quit the sensor setup
|
2018-08-21 12:11:34 -07:00
|
|
|
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
2022-11-30 12:51:59 -08:00
|
|
|
SDL_sensor_drivers[i]->Quit();
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
|
|
|
|
|
2024-08-22 09:21:26 -07:00
|
|
|
SDL_sensors_initialized = false;
|
2023-08-08 22:08:40 -07:00
|
|
|
|
|
|
|
|
SDL_UnlockSensors();
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// These are global for SDL_syssensor.c and SDL_events.c
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2024-08-22 17:33:49 -07:00
|
|
|
void SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_timestamp, float *data, int num_values)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_AssertSensorsLocked();
|
|
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Allow duplicate events, for things like steps and heartbeats
|
2018-08-21 12:11:34 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Update internal sensor state
|
2018-08-21 12:11:34 -07:00
|
|
|
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
|
2022-11-30 12:51:59 -08:00
|
|
|
SDL_memcpy(sensor->data, data, num_values * sizeof(*data));
|
2018-08-21 12:11:34 -07:00
|
|
|
|
Use C++ style comments consistently in SDL source code
Implemented using this script:
find . -type f -exec sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' {} \;
git checkout \
core/linux/SDL_evdev_kbd_default_keymap.h \
events/imKStoUCS.* \
hidapi \
joystick/controller_type.c \
joystick/controller_type.h \
joystick/hidapi/steam/controller_constants.h \
joystick/hidapi/steam/controller_structs.h \
joystick/SDL_gamepad_db.h \
libm \
render/*/*Shader*.h \
render/vitagxm/SDL_render_vita_gxm_shaders.h \
render/metal/SDL_shaders_metal_*.h \
stdlib/SDL_malloc.c \
stdlib/SDL_qsort.c \
stdlib/SDL_strtokr.c \
test/ \
video/directx/SDL_d3d12_xbox_cmacros.h \
video/directx/d3d12.h \
video/directx/d3d12sdklayers.h \
video/khronos \
video/x11/edid-parse.c \
video/x11/xsettings-client.* \
video/yuv2rgb
sed -i'' -e 's,/\* *\([^*]*\)\*/ *$,// \1,' -e 's, \+$,,' hidapi/SDL_hidapi.c
2024-08-22 10:30:45 -07:00
|
|
|
// Post the event, if desired
|
2023-01-23 17:54:09 -08:00
|
|
|
if (SDL_EventEnabled(SDL_EVENT_SENSOR_UPDATE)) {
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_Event event;
|
2023-01-23 17:54:09 -08:00
|
|
|
event.type = SDL_EVENT_SENSOR_UPDATE;
|
2022-12-04 08:31:19 -08:00
|
|
|
event.common.timestamp = timestamp;
|
2018-08-21 12:11:34 -07:00
|
|
|
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));
|
2022-11-30 12:51:59 -08:00
|
|
|
SDL_memcpy(event.sensor.data, data, num_values * sizeof(*data));
|
2022-12-04 08:31:19 -08:00
|
|
|
event.sensor.sensor_timestamp = sensor_timestamp;
|
2024-08-22 17:33:49 -07:00
|
|
|
SDL_PushEvent(&event);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-06-19 16:17:34 -07:00
|
|
|
|
|
|
|
|
SDL_GamepadSensorWatcher(timestamp, sensor->instance_id, sensor_timestamp, data, num_values);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
|
2023-06-14 22:03:44 -07:00
|
|
|
void SDL_UpdateSensor(SDL_Sensor *sensor)
|
|
|
|
|
{
|
2023-08-08 22:08:40 -07:00
|
|
|
SDL_LockSensors();
|
|
|
|
|
{
|
|
|
|
|
CHECK_SENSOR_MAGIC(sensor,);
|
|
|
|
|
|
|
|
|
|
sensor->driver->Update(sensor);
|
|
|
|
|
}
|
|
|
|
|
SDL_UnlockSensors();
|
2023-06-14 22:03:44 -07:00
|
|
|
}
|
|
|
|
|
|
2022-12-27 06:23:39 -08:00
|
|
|
void SDL_UpdateSensors(void)
|
2018-08-21 12:11:34 -07:00
|
|
|
{
|
|
|
|
|
int i;
|
2022-12-29 23:07:30 -08:00
|
|
|
SDL_Sensor *sensor;
|
2018-08-21 12:11:34 -07:00
|
|
|
|
2018-11-19 21:17:00 -08:00
|
|
|
if (!SDL_WasInit(SDL_INIT_SENSOR)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-21 12:11:34 -07:00
|
|
|
SDL_LockSensors();
|
|
|
|
|
|
|
|
|
|
for (sensor = SDL_sensors; sensor; sensor = sensor->next) {
|
|
|
|
|
sensor->driver->Update(sensor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this needs to happen AFTER walking the sensor list above, so that any
|
|
|
|
|
dangling hardware data from removed devices can be free'd
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) {
|
|
|
|
|
SDL_sensor_drivers[i]->Detect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SDL_UnlockSensors();
|
|
|
|
|
}
|