mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 08:15:44 +00:00
update sdl to 2.32.6
This commit is contained in:
parent
e557f5962b
commit
ddc1f8c1e2
1339 changed files with 53966 additions and 19207 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -29,25 +29,25 @@
|
|||
*/
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_hidapi.h"
|
||||
#include "SDL_hidapi_c.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_hidapi_c.h"
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#ifndef SDL_HIDAPI_DISABLED
|
||||
|
||||
#if defined(__WIN32__) || defined(__WINGDK__)
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
#if defined(__MACOSX__)
|
||||
#include <AvailabilityMacros.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <mach/mach.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/hid/IOHIDDevice.h>
|
||||
#include <IOKit/usb/USBSpec.h>
|
||||
#include <AvailabilityMacros.h>
|
||||
#include <mach/mach.h>
|
||||
/* Things named "Master" were renamed to "Main" in macOS 12.0's SDK. */
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < 120000
|
||||
#define kIOMainPortDefault kIOMasterPortDefault
|
||||
|
|
@ -56,16 +56,16 @@
|
|||
|
||||
#include "../core/linux/SDL_udev.h"
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
#include <poll.h>
|
||||
#include "../core/linux/SDL_sandbox.h"
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_INOTIFY
|
||||
#include <unistd.h> /* just in case we didn't use that SDL_USE_LIBUDEV block... */
|
||||
#include <errno.h> /* errno, strerror */
|
||||
#include <errno.h> /* errno, strerror */
|
||||
#include <fcntl.h>
|
||||
#include <limits.h> /* For the definition of NAME_MAX */
|
||||
#include <sys/inotify.h>
|
||||
#include <unistd.h> /* just in case we didn't use that SDL_USE_LIBUDEV block... */
|
||||
#endif
|
||||
|
||||
#if defined(SDL_USE_LIBUDEV) || defined(HAVE_INOTIFY)
|
||||
|
|
@ -166,7 +166,6 @@ static LRESULT CALLBACK ControllerWndProc(HWND hwnd, UINT message, WPARAM wParam
|
|||
}
|
||||
#endif /* defined(__WIN32__) || defined(__WINGDK__) */
|
||||
|
||||
|
||||
#if defined(__MACOSX__)
|
||||
static void CallbackIOServiceFunc(void *context, io_iterator_t portIterator)
|
||||
{
|
||||
|
|
@ -221,7 +220,7 @@ static int StrIsInteger(const char *string)
|
|||
}
|
||||
#endif /* HAVE_INOTIFY */
|
||||
|
||||
static void HIDAPI_InitializeDiscovery()
|
||||
static void HIDAPI_InitializeDiscovery(void)
|
||||
{
|
||||
SDL_HIDAPI_discovery.m_bInitialized = SDL_TRUE;
|
||||
SDL_HIDAPI_discovery.m_unDeviceChangeCounter = 1;
|
||||
|
|
@ -360,7 +359,7 @@ static void HIDAPI_InitializeDiscovery()
|
|||
}
|
||||
}
|
||||
|
||||
static void HIDAPI_UpdateDiscovery()
|
||||
static void HIDAPI_UpdateDiscovery(void)
|
||||
{
|
||||
if (!SDL_HIDAPI_discovery.m_bInitialized) {
|
||||
HIDAPI_InitializeDiscovery();
|
||||
|
|
@ -477,7 +476,7 @@ static void HIDAPI_UpdateDiscovery()
|
|||
}
|
||||
}
|
||||
|
||||
static void HIDAPI_ShutdownDiscovery()
|
||||
static void HIDAPI_ShutdownDiscovery(void)
|
||||
{
|
||||
if (!SDL_HIDAPI_discovery.m_bInitialized) {
|
||||
return;
|
||||
|
|
@ -557,9 +556,9 @@ static void HIDAPI_ShutdownDiscovery()
|
|||
#define read_thread PLATFORM_read_thread
|
||||
|
||||
#undef HIDAPI_H__
|
||||
#if __LINUX__
|
||||
#ifdef __LINUX__
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
||||
|
||||
#define udev_device_get_sysattr_value udev_ctx->udev_device_get_sysattr_value
|
||||
|
|
@ -579,23 +578,23 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
|||
#define udev_enumerate_unref udev_ctx->udev_enumerate_unref
|
||||
|
||||
#include "linux/hid.c"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
#define HAVE_PLATFORM_BACKEND
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
||||
#elif __MACOSX__
|
||||
#elif defined(__MACOSX__)
|
||||
#include "mac/hid.c"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
#define HAVE_PLATFORM_BACKEND
|
||||
#define udev_ctx 1
|
||||
#elif __WINDOWS__ || __WINGDK__
|
||||
#elif defined(__WINDOWS__) || defined(__WINGDK__)
|
||||
#include "windows/hid.c"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
#define HAVE_PLATFORM_BACKEND
|
||||
#define udev_ctx 1
|
||||
#elif __ANDROID__
|
||||
#elif defined(__ANDROID__)
|
||||
/* The implementation for Android is in a separate .cpp file */
|
||||
#include "hidapi/hidapi.h"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
#define udev_ctx 1
|
||||
#elif __IPHONEOS__ || __TVOS__
|
||||
#define udev_ctx 1
|
||||
#elif defined(__IPHONEOS__) || defined(__TVOS__)
|
||||
/* The implementation for iOS and tvOS is in a separate .m file */
|
||||
#include "hidapi/hidapi.h"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
|
|
@ -631,9 +630,11 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
|||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_STEAMXBOX
|
||||
#define HAVE_DRIVER_BACKEND 1
|
||||
#else
|
||||
#define HAVE_DRIVER_BACKEND 0
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DRIVER_BACKEND
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
|
||||
/* DRIVER HIDAPI Implementation */
|
||||
|
||||
|
|
@ -809,8 +810,8 @@ static struct
|
|||
/* this is awkwardly inlined, so we need to re-implement it here
|
||||
* so we can override the libusb_control_transfer call */
|
||||
static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
|
||||
uint8_t descriptor_index, uint16_t lang_id,
|
||||
unsigned char *data, int length)
|
||||
uint8_t descriptor_index, uint16_t lang_id,
|
||||
unsigned char *data, int length)
|
||||
{
|
||||
return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,
|
||||
data, (uint16_t)length, 1000); /* Endpoint 0 IN */
|
||||
|
|
@ -876,6 +877,41 @@ static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
|
|||
#undef make_path
|
||||
#undef read_thread
|
||||
|
||||
/* If the platform has any backend other than libusb, try to avoid using
|
||||
* libusb as the main backend for devices, since it detaches drivers and
|
||||
* therefore makes devices inaccessible to the rest of the OS.
|
||||
*
|
||||
* We do this by whitelisting devices we know to be accessible _exclusively_
|
||||
* via libusb; these are typically devices that look like HIDs but have a
|
||||
* quirk that requires direct access to the hardware.
|
||||
*/
|
||||
static const struct {
|
||||
Uint16 vendor;
|
||||
Uint16 product;
|
||||
} SDL_libusb_whitelist[] = {
|
||||
{ 0x057e, 0x0337 } /* Nintendo WUP-028, Wii U/Switch GameCube Adapter */
|
||||
};
|
||||
|
||||
static SDL_bool
|
||||
IsInWhitelist(Uint16 vendor, Uint16 product)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SDL_arraysize(SDL_libusb_whitelist); i += 1) {
|
||||
if (vendor == SDL_libusb_whitelist[i].vendor &&
|
||||
product == SDL_libusb_whitelist[i].product) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
#if defined(HAVE_PLATFORM_BACKEND) || HAVE_DRIVER_BACKEND
|
||||
#define use_libusb_whitelist_default SDL_TRUE
|
||||
#else
|
||||
#define use_libusb_whitelist_default SDL_FALSE
|
||||
#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND */
|
||||
static SDL_bool use_libusb_whitelist = use_libusb_whitelist_default;
|
||||
|
||||
#endif /* HAVE_LIBUSB */
|
||||
|
||||
#endif /* !SDL_HIDAPI_DISABLED */
|
||||
|
|
@ -898,7 +934,7 @@ struct hidapi_backend
|
|||
const wchar_t *(*hid_error)(void *device);
|
||||
};
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
static const struct hidapi_backend PLATFORM_Backend = {
|
||||
(void *)PLATFORM_hid_write,
|
||||
(void *)PLATFORM_hid_read_timeout,
|
||||
|
|
@ -957,7 +993,7 @@ struct SDL_hid_device_
|
|||
};
|
||||
static char device_magic;
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
#if defined(HAVE_PLATFORM_BACKEND) || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
|
||||
static SDL_hid_device *CreateHIDDeviceWrapper(void *device, const struct hidapi_backend *backend)
|
||||
{
|
||||
|
|
@ -982,8 +1018,8 @@ static void DeleteHIDDeviceWrapper(SDL_hid_device *device)
|
|||
return retval; \
|
||||
}
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
#ifndef SDL_HIDAPI_DISABLED
|
||||
#if defined(HAVE_PLATFORM_BACKEND) || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
|
||||
#define COPY_IF_EXISTS(var) \
|
||||
if (pSrc->var != NULL) { \
|
||||
|
|
@ -1061,6 +1097,8 @@ int SDL_hid_init(void)
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_LIBUSB
|
||||
use_libusb_whitelist = SDL_GetHintBoolean("SDL_HIDAPI_LIBUSB_WHITELIST",
|
||||
use_libusb_whitelist_default);
|
||||
if (SDL_getenv("SDL_HIDAPI_DISABLE_LIBUSB") != NULL) {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"libusb disabled by SDL_HIDAPI_DISABLE_LIBUSB");
|
||||
|
|
@ -1130,9 +1168,9 @@ int SDL_hid_init(void)
|
|||
}
|
||||
#endif /* HAVE_LIBUSB */
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
++attempts;
|
||||
#if __LINUX__
|
||||
#ifdef __LINUX__
|
||||
udev_ctx = SDL_UDEV_GetUdevSyms();
|
||||
#endif /* __LINUX __ */
|
||||
if (udev_ctx && PLATFORM_hid_init() == 0) {
|
||||
|
|
@ -1161,15 +1199,15 @@ int SDL_hid_exit(void)
|
|||
}
|
||||
SDL_hidapi_refcount = 0;
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#ifndef SDL_HIDAPI_DISABLED
|
||||
HIDAPI_ShutdownDiscovery();
|
||||
#endif
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
if (udev_ctx) {
|
||||
result |= PLATFORM_hid_exit();
|
||||
}
|
||||
#if __LINUX__
|
||||
#ifdef __LINUX__
|
||||
SDL_UDEV_ReleaseUdevSyms();
|
||||
#endif /* __LINUX __ */
|
||||
#endif /* HAVE_PLATFORM_BACKEND */
|
||||
|
|
@ -1191,7 +1229,7 @@ Uint32 SDL_hid_device_change_count(void)
|
|||
{
|
||||
Uint32 counter = 0;
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#ifndef SDL_HIDAPI_DISABLED
|
||||
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1211,7 +1249,7 @@ Uint32 SDL_hid_device_change_count(void)
|
|||
|
||||
struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned short product_id)
|
||||
{
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
#if defined(HAVE_PLATFORM_BACKEND) || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
#ifdef HAVE_LIBUSB
|
||||
struct SDL_hid_device_info *usb_devs = NULL;
|
||||
struct SDL_hid_device_info *usb_dev;
|
||||
|
|
@ -1220,7 +1258,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
|||
struct SDL_hid_device_info *driver_devs = NULL;
|
||||
struct SDL_hid_device_info *driver_dev;
|
||||
#endif
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
struct SDL_hid_device_info *raw_devs = NULL;
|
||||
struct SDL_hid_device_info *raw_dev;
|
||||
#endif
|
||||
|
|
@ -1237,6 +1275,16 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
|||
SDL_Log("libusb devices found:");
|
||||
#endif
|
||||
for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
|
||||
if (use_libusb_whitelist) {
|
||||
if (!IsInWhitelist(usb_dev->vendor_id, usb_dev->product_id)) {
|
||||
#ifdef DEBUG_HIDAPI
|
||||
SDL_Log("Device was not in libusb whitelist: %ls %ls 0x%.4hx 0x%.4hx",
|
||||
usb_dev->manufacturer_string, usb_dev->product_string,
|
||||
usb_dev->vendor_id, usb_dev->product_id);
|
||||
#endif /* DEBUG_HIDAPI */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
new_dev = (struct SDL_hid_device_info *)SDL_malloc(sizeof(struct SDL_hid_device_info));
|
||||
if (new_dev == NULL) {
|
||||
LIBUSB_hid_free_enumeration(usb_devs);
|
||||
|
|
@ -1261,7 +1309,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
|||
}
|
||||
#endif /* HAVE_LIBUSB */
|
||||
|
||||
#ifdef HAVE_DRIVER_BACKEND
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
driver_devs = DRIVER_hid_enumerate(vendor_id, product_id);
|
||||
for (driver_dev = driver_devs; driver_dev; driver_dev = driver_dev->next) {
|
||||
new_dev = (struct SDL_hid_device_info *)SDL_malloc(sizeof(struct SDL_hid_device_info));
|
||||
|
|
@ -1276,7 +1324,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
|||
}
|
||||
#endif /* HAVE_DRIVER_BACKEND */
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
if (udev_ctx) {
|
||||
raw_devs = PLATFORM_hid_enumerate(vendor_id, product_id);
|
||||
#ifdef DEBUG_HIDAPI
|
||||
|
|
@ -1299,7 +1347,7 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
|||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_DRIVER_BACKEND
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
for (driver_dev = driver_devs; driver_dev; driver_dev = driver_dev->next) {
|
||||
if (raw_dev->vendor_id == driver_dev->vendor_id &&
|
||||
raw_dev->product_id == driver_dev->product_id &&
|
||||
|
|
@ -1364,14 +1412,14 @@ void SDL_hid_free_enumeration(struct SDL_hid_device_info *devs)
|
|||
|
||||
SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
|
||||
{
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
#if defined(HAVE_PLATFORM_BACKEND) || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
void *pDevice = NULL;
|
||||
|
||||
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
if (udev_ctx) {
|
||||
pDevice = PLATFORM_hid_open(vendor_id, product_id, serial_number);
|
||||
if (pDevice != NULL) {
|
||||
|
|
@ -1403,14 +1451,14 @@ SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id
|
|||
|
||||
SDL_hid_device *SDL_hid_open_path(const char *path, int bExclusive /* = false */)
|
||||
{
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
#if defined(HAVE_PLATFORM_BACKEND) || HAVE_DRIVER_BACKEND || defined(HAVE_LIBUSB)
|
||||
void *pDevice = NULL;
|
||||
|
||||
if (SDL_hidapi_refcount == 0 && SDL_hid_init() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
#ifdef HAVE_PLATFORM_BACKEND
|
||||
if (udev_ctx) {
|
||||
pDevice = PLATFORM_hid_open_path(path, bExclusive);
|
||||
if (pDevice != NULL) {
|
||||
|
|
@ -1580,7 +1628,7 @@ int SDL_hid_get_indexed_string(SDL_hid_device *device, int string_index, wchar_t
|
|||
|
||||
void SDL_hid_ble_scan(SDL_bool active)
|
||||
{
|
||||
#if !SDL_HIDAPI_DISABLED && (__IPHONEOS__ || __TVOS__)
|
||||
#if !defined(SDL_HIDAPI_DISABLED) && (defined(__IPHONEOS__) || defined(__TVOS__))
|
||||
hid_ble_scan(active);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
#define HID_DEVICE_MANAGER_JAVA_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, HIDDeviceManager, function)
|
||||
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#ifndef SDL_HIDAPI_DISABLED
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "../../core/android/SDL_android.h"
|
||||
|
|
@ -744,7 +744,7 @@ public:
|
|||
env->CallVoidMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerClose, m_nId );
|
||||
ExceptionCheck( env, "Close" );
|
||||
}
|
||||
|
||||
|
||||
hid_mutex_guard dataLock( &m_dataLock );
|
||||
m_vecData.clear();
|
||||
|
||||
|
|
@ -1139,7 +1139,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx
|
|||
hid_mutex_guard l( &g_DevicesMutex );
|
||||
for ( hid_device_ref<CHIDDevice> pCurr = g_Devices; pCurr; pCurr = pCurr->next )
|
||||
{
|
||||
if ( SDL_strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 )
|
||||
if ( SDL_strcmp( pCurr->GetDeviceInfo()->path, path ) == 0 )
|
||||
{
|
||||
hid_device *pValue = pCurr->GetDevice();
|
||||
if ( pValue )
|
||||
|
|
|
|||
|
|
@ -406,7 +406,7 @@ namespace NAMESPACE {
|
|||
*/
|
||||
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);
|
||||
|
||||
#if __IPHONEOS__ || __TVOS__
|
||||
#if defined(__IPHONEOS__) || defined(__TVOS__)
|
||||
HID_API_EXPORT void HID_API_CALL hid_ble_scan(int active);
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#ifndef SDL_HIDAPI_DISABLED
|
||||
|
||||
#include "SDL_hints.h"
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ static void RingBuffer_init( RingBuffer *this )
|
|||
this->_last = 0;
|
||||
pthread_mutex_init( &this->accessLock, 0 );
|
||||
}
|
||||
|
||||
|
||||
static bool RingBuffer_write( RingBuffer *this, const uint8_t *src )
|
||||
{
|
||||
pthread_mutex_lock( &this->accessLock );
|
||||
|
|
@ -290,7 +290,9 @@ typedef enum
|
|||
{
|
||||
static uint64_t s_unLastUpdateTick = 0;
|
||||
static mach_timebase_info_data_t s_timebase_info;
|
||||
|
||||
uint64_t ticksNow;
|
||||
NSArray<CBPeripheral *> *peripherals;
|
||||
|
||||
if ( self.centralManager == nil )
|
||||
{
|
||||
return 0;
|
||||
|
|
@ -300,11 +302,11 @@ typedef enum
|
|||
{
|
||||
mach_timebase_info( &s_timebase_info );
|
||||
}
|
||||
|
||||
uint64_t ticksNow = mach_approximate_time();
|
||||
|
||||
ticksNow = mach_approximate_time();
|
||||
if ( !bForce && ( ( (ticksNow - s_unLastUpdateTick) * s_timebase_info.numer ) / s_timebase_info.denom ) < (5ull * NSEC_PER_SEC) )
|
||||
return (int)self.deviceMap.count;
|
||||
|
||||
|
||||
// we can see previously connected BLE peripherals but can't connect until the CBCentralManager
|
||||
// is fully powered up - only do work when we are in that state
|
||||
if ( self.centralManager.state != CBManagerStatePoweredOn )
|
||||
|
|
@ -312,24 +314,25 @@ typedef enum
|
|||
|
||||
// only update our last-check-time if we actually did work, otherwise there can be a long delay during initial power-up
|
||||
s_unLastUpdateTick = mach_approximate_time();
|
||||
|
||||
|
||||
// if a pair is in-flight, the central manager may still give it back via retrieveConnected... and
|
||||
// cause the SDL layer to attempt to initialize it while some of its endpoints haven't yet been established
|
||||
if ( self.nPendingPairs > 0 )
|
||||
return (int)self.deviceMap.count;
|
||||
|
||||
NSArray<CBPeripheral *> *peripherals = [self.centralManager retrieveConnectedPeripheralsWithServices: @[ [CBUUID UUIDWithString:@"180A"]]];
|
||||
peripherals = [self.centralManager retrieveConnectedPeripheralsWithServices: @[ [CBUUID UUIDWithString:@"180A"]]];
|
||||
for ( CBPeripheral *peripheral in peripherals )
|
||||
{
|
||||
// we already know this peripheral
|
||||
if ( [self.deviceMap objectForKey: peripheral] != nil )
|
||||
continue;
|
||||
|
||||
|
||||
NSLog( @"connected peripheral: %@", peripheral );
|
||||
if ( [peripheral.name isEqualToString:@"SteamController"] )
|
||||
{
|
||||
HIDBLEDevice *steamController;
|
||||
self.nPendingPairs += 1;
|
||||
HIDBLEDevice *steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
|
||||
steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
|
||||
[self.deviceMap setObject:steamController forKey:peripheral];
|
||||
[self.centralManager connectPeripheral:peripheral options:nil];
|
||||
}
|
||||
|
|
@ -392,7 +395,7 @@ typedef enum
|
|||
case CBCentralManagerStatePoweredOn:
|
||||
{
|
||||
NSLog( @"CoreBluetooth BLE hardware is powered on and ready" );
|
||||
|
||||
|
||||
// at startup, if we have no already attached peripherals, do a 20s scan for new unpaired devices,
|
||||
// otherwise callers should occaisionally do additional scans. we don't want to continuously be
|
||||
// scanning because it drains battery, causes other nearby people to have a hard time pairing their
|
||||
|
|
@ -408,23 +411,23 @@ typedef enum
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case CBCentralManagerStatePoweredOff:
|
||||
NSLog( @"CoreBluetooth BLE hardware is powered off" );
|
||||
break;
|
||||
|
||||
|
||||
case CBCentralManagerStateUnauthorized:
|
||||
NSLog( @"CoreBluetooth BLE state is unauthorized" );
|
||||
break;
|
||||
|
||||
|
||||
case CBCentralManagerStateUnknown:
|
||||
NSLog( @"CoreBluetooth BLE state is unknown" );
|
||||
break;
|
||||
|
||||
|
||||
case CBCentralManagerStateUnsupported:
|
||||
NSLog( @"CoreBluetooth BLE hardware is unsupported on this platform" );
|
||||
break;
|
||||
|
||||
|
||||
case CBCentralManagerStateResetting:
|
||||
NSLog( @"CoreBluetooth BLE manager is resetting" );
|
||||
break;
|
||||
|
|
@ -449,12 +452,13 @@ typedef enum
|
|||
{
|
||||
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
|
||||
NSString *log = [NSString stringWithFormat:@"Found '%@'", localName];
|
||||
|
||||
|
||||
if ( [localName isEqualToString:@"SteamController"] )
|
||||
{
|
||||
HIDBLEDevice *steamController;
|
||||
NSLog( @"%@ : %@ - %@", log, peripheral, advertisementData );
|
||||
self.nPendingPairs += 1;
|
||||
HIDBLEDevice *steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
|
||||
steamController = [[HIDBLEDevice alloc] initWithPeripheral:peripheral];
|
||||
[self.deviceMap setObject:steamController forKey:peripheral];
|
||||
[self.centralManager connectPeripheral:peripheral options:nil];
|
||||
}
|
||||
|
|
@ -475,7 +479,7 @@ typedef enum
|
|||
|
||||
|
||||
// Core Bluetooth devices calling back on event boundaries of their run-loops. so annoying.
|
||||
static void process_pending_events()
|
||||
static void process_pending_events(void)
|
||||
{
|
||||
CFRunLoopRunResult res;
|
||||
do
|
||||
|
|
@ -552,7 +556,7 @@ static void process_pending_events()
|
|||
{
|
||||
#if FEATURE_REPORT_LOGGING
|
||||
uint8_t *reportBytes = (uint8_t *)report;
|
||||
|
||||
|
||||
NSLog( @"HIDBLE:send_feature_report (%02zu/19) [%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]", GetBluetoothSegmentSize( report->segment ),
|
||||
reportBytes[1], reportBytes[2], reportBytes[3], reportBytes[4], reportBytes[5], reportBytes[6],
|
||||
reportBytes[7], reportBytes[8], reportBytes[9], reportBytes[10], reportBytes[11], reportBytes[12],
|
||||
|
|
@ -568,7 +572,7 @@ static void process_pending_events()
|
|||
// fire-and-forget - we are going to not wait for the response here because all Steam Controller BLE send_feature_report's are ignored,
|
||||
// except errors.
|
||||
[_bleSteamController writeValue:[NSData dataWithBytes:&report->segment length:sendSize] forCharacteristic:_bleCharacteristicReport type:CBCharacteristicWriteWithResponse];
|
||||
|
||||
|
||||
// pretend we received a result anybody cares about
|
||||
return 19;
|
||||
|
||||
|
|
@ -578,18 +582,18 @@ static void process_pending_events()
|
|||
_waitStateForWriteFeatureReport = BLEDeviceWaitState_Waiting;
|
||||
[_bleSteamController writeValue:[NSData dataWithBytes:&report->segment length:sendSize
|
||||
] forCharacteristic:_bleCharacteristicReport type:CBCharacteristicWriteWithResponse];
|
||||
|
||||
|
||||
while ( _waitStateForWriteFeatureReport == BLEDeviceWaitState_Waiting )
|
||||
{
|
||||
process_pending_events();
|
||||
}
|
||||
|
||||
|
||||
if ( _waitStateForWriteFeatureReport == BLEDeviceWaitState_Error )
|
||||
{
|
||||
_waitStateForWriteFeatureReport = BLEDeviceWaitState_None;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
_waitStateForWriteFeatureReport = BLEDeviceWaitState_None;
|
||||
return 19;
|
||||
#endif
|
||||
|
|
@ -599,20 +603,20 @@ static void process_pending_events()
|
|||
{
|
||||
_waitStateForReadFeatureReport = BLEDeviceWaitState_Waiting;
|
||||
[_bleSteamController readValueForCharacteristic:_bleCharacteristicReport];
|
||||
|
||||
|
||||
while ( _waitStateForReadFeatureReport == BLEDeviceWaitState_Waiting )
|
||||
process_pending_events();
|
||||
|
||||
|
||||
if ( _waitStateForReadFeatureReport == BLEDeviceWaitState_Error )
|
||||
{
|
||||
_waitStateForReadFeatureReport = BLEDeviceWaitState_None;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
memcpy( buffer, _featureReport, sizeof(_featureReport) );
|
||||
|
||||
|
||||
_waitStateForReadFeatureReport = BLEDeviceWaitState_None;
|
||||
|
||||
|
||||
#if FEATURE_REPORT_LOGGING
|
||||
NSLog( @"HIDBLE:get_feature_report (19) [%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]",
|
||||
buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6],
|
||||
|
|
@ -657,7 +661,7 @@ static void process_pending_events()
|
|||
for (CBCharacteristic *aChar in service.characteristics)
|
||||
{
|
||||
NSLog( @"Found Characteristic %@", aChar );
|
||||
|
||||
|
||||
if ( [aChar.UUID isEqual:[CBUUID UUIDWithString:VALVE_INPUT_CHAR]] )
|
||||
{
|
||||
self.bleCharacteristicInput = aChar;
|
||||
|
|
@ -704,7 +708,7 @@ static void process_pending_events()
|
|||
else if ( [characteristic.UUID isEqual:_bleCharacteristicReport.UUID] )
|
||||
{
|
||||
memset( _featureReport, 0, sizeof(_featureReport) );
|
||||
|
||||
|
||||
if ( error != nil )
|
||||
{
|
||||
NSLog( @"HIDBLE: get_feature_report error: %@", error );
|
||||
|
|
@ -789,13 +793,13 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path( const char *path, int bE
|
|||
NSString *nssPath = [NSString stringWithUTF8String:path];
|
||||
HIDBLEManager *bleManager = HIDBLEManager.sharedInstance;
|
||||
NSEnumerator<HIDBLEDevice *> *devices = [bleManager.deviceMap objectEnumerator];
|
||||
|
||||
|
||||
for ( HIDBLEDevice *device in devices )
|
||||
{
|
||||
// we have the device but it hasn't found its service or characteristics until it is connected
|
||||
if ( !device.ready || !device.connected || !device.bleCharacteristicInput )
|
||||
continue;
|
||||
|
||||
|
||||
if ( [device.bleSteamController.identifier.UUIDString isEqualToString:nssPath] )
|
||||
{
|
||||
result = (hid_device *)malloc( sizeof( hid_device ) );
|
||||
|
|
@ -829,7 +833,7 @@ int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
|
|||
{
|
||||
/* All Nonblocking operation is handled by the library. */
|
||||
dev->blocking = !nonblock;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -851,11 +855,13 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
|
|||
if ( ( vendor_id == 0 || vendor_id == VALVE_USB_VID ) &&
|
||||
( product_id == 0 || product_id == D0G_BLE2_PID ) )
|
||||
{
|
||||
NSEnumerator<HIDBLEDevice *> *devices;
|
||||
HIDBLEManager *bleManager = HIDBLEManager.sharedInstance;
|
||||
[bleManager updateConnectedSteamControllers:false];
|
||||
NSEnumerator<HIDBLEDevice *> *devices = [bleManager.deviceMap objectEnumerator];
|
||||
devices = [bleManager.deviceMap objectEnumerator];
|
||||
for ( HIDBLEDevice *device in devices )
|
||||
{
|
||||
struct hid_device_info *device_info;
|
||||
// there are several brief windows in connecting to an already paired device and
|
||||
// one long window waiting for users to confirm pairing where we don't want
|
||||
// to consider a device ready - if we hand it back to SDL or another
|
||||
|
|
@ -873,7 +879,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
|
|||
}
|
||||
continue;
|
||||
}
|
||||
struct hid_device_info *device_info = (struct hid_device_info *)malloc( sizeof(struct hid_device_info) );
|
||||
device_info = (struct hid_device_info *)malloc( sizeof(struct hid_device_info) );
|
||||
memset( device_info, 0, sizeof(struct hid_device_info) );
|
||||
device_info->next = root;
|
||||
root = device_info;
|
||||
|
|
@ -947,13 +953,14 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char
|
|||
|
||||
int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
|
||||
{
|
||||
size_t written;
|
||||
HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle;
|
||||
|
||||
if ( !device_handle.connected )
|
||||
return -1;
|
||||
|
||||
size_t written = [device_handle get_feature_report:data[0] into:data];
|
||||
|
||||
written = [device_handle get_feature_report:data[0] into:data];
|
||||
|
||||
return written == length-1 ? (int)length : (int)written;
|
||||
}
|
||||
|
||||
|
|
@ -969,16 +976,17 @@ int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
|
|||
|
||||
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
|
||||
{
|
||||
int result;
|
||||
HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle;
|
||||
|
||||
if ( !device_handle.connected )
|
||||
return -1;
|
||||
|
||||
|
||||
if ( milliseconds != 0 )
|
||||
{
|
||||
NSLog( @"hid_read_timeout with non-zero wait" );
|
||||
}
|
||||
int result = (int)[device_handle read_input_report:data];
|
||||
result = (int)[device_handle read_input_report:data];
|
||||
#if FEATURE_REPORT_LOGGING
|
||||
NSLog( @"HIDBLE:hid_read_timeout (%d) [%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x]", result,
|
||||
data[1], data[2], data[3], data[4], data[5], data[6],
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ static struct usb_string_cache_entry *usb_string_cache = NULL;
|
|||
static size_t usb_string_cache_size = 0;
|
||||
static size_t usb_string_cache_insert_pos = 0;
|
||||
|
||||
static int usb_string_cache_grow()
|
||||
static int usb_string_cache_grow(void)
|
||||
{
|
||||
struct usb_string_cache_entry *new_cache;
|
||||
size_t allocSize;
|
||||
|
|
@ -537,7 +537,7 @@ static int usb_string_cache_grow()
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void usb_string_cache_destroy()
|
||||
static void usb_string_cache_destroy(void)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < usb_string_cache_insert_pos; i++) {
|
||||
|
|
@ -711,9 +711,11 @@ static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_de
|
|||
static const int XB1_IFACE_SUBCLASS = 71;
|
||||
static const int XB1_IFACE_PROTOCOL = 208;
|
||||
static const int SUPPORTED_VENDORS[] = {
|
||||
0x03f0, /* HP */
|
||||
0x044f, /* Thrustmaster */
|
||||
0x045e, /* Microsoft */
|
||||
0x0738, /* Mad Catz */
|
||||
0x0b05, /* ASUS */
|
||||
0x0e6f, /* PDP */
|
||||
0x0f0d, /* Hori */
|
||||
0x10f5, /* Turtle Beach */
|
||||
|
|
@ -722,6 +724,7 @@ static int is_xboxone(unsigned short vendor_id, const struct libusb_interface_de
|
|||
0x24c6, /* PowerA */
|
||||
0x2dc8, /* 8BitDo */
|
||||
0x2e24, /* Hyperkin */
|
||||
0x3537, /* GameSir */
|
||||
};
|
||||
|
||||
if (intf_desc->bInterfaceNumber == 0 &&
|
||||
|
|
|
|||
|
|
@ -504,7 +504,7 @@ int HID_API_EXPORT hid_exit(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void process_pending_events() {
|
||||
static void process_pending_events(void) {
|
||||
SInt32 res;
|
||||
do {
|
||||
res = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.001, FALSE);
|
||||
|
|
@ -957,7 +957,9 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length)
|
|||
size_t len = 0;
|
||||
if (rpt != NULL) {
|
||||
len = (length < rpt->len)? length: rpt->len;
|
||||
memcpy(data, rpt->data, len);
|
||||
if (data != NULL) {
|
||||
memcpy(data, rpt->data, len);
|
||||
}
|
||||
dev->input_reports = rpt->next;
|
||||
free(rpt->data);
|
||||
free(rpt);
|
||||
|
|
@ -1133,11 +1135,14 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
|
|||
|
||||
void HID_API_EXPORT hid_close(hid_device *dev)
|
||||
{
|
||||
int disconnected;
|
||||
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
/* Disconnect the report callback before close. */
|
||||
if (!dev->disconnected) {
|
||||
disconnected = dev->disconnected;
|
||||
if (!disconnected) {
|
||||
IOHIDDeviceRegisterInputReportCallback(
|
||||
dev->device_handle, dev->input_report_buf, dev->max_input_report_len,
|
||||
NULL, dev);
|
||||
|
|
@ -1161,7 +1166,7 @@ void HID_API_EXPORT hid_close(hid_device *dev)
|
|||
/* Close the OS handle to the device, but only if it's not
|
||||
been unplugged. If it's been unplugged, then calling
|
||||
IOHIDDeviceClose() will crash. */
|
||||
if (!dev->disconnected) {
|
||||
if (!disconnected) {
|
||||
IOHIDDeviceClose(dev->device_handle, kIOHIDOptionsTypeNone);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ static void register_error(hid_device *device, const char *op)
|
|||
}
|
||||
|
||||
#ifndef HIDAPI_USE_DDK
|
||||
static int lookup_functions()
|
||||
static int lookup_functions(void)
|
||||
{
|
||||
lib_handle = LoadLibrary(TEXT("hid.dll"));
|
||||
if (lib_handle) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue