mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-29 06:28:29 +00:00
Build hidapi code into SDL as a new public API
This prevents conflicts with hidapi linked with applications, as well as allowing applications to make use of HIDAPI on Android and other platforms that might not normally have an implementation available.
This commit is contained in:
@@ -827,3 +827,18 @@
|
||||
#define SDL_LinuxSetThreadPriorityAndPolicy SDL_LinuxSetThreadPriorityAndPolicy_REAL
|
||||
#define SDL_GameControllerGetAppleSFSymbolsNameForButton SDL_GameControllerGetAppleSFSymbolsNameForButton_REAL
|
||||
#define SDL_GameControllerGetAppleSFSymbolsNameForAxis SDL_GameControllerGetAppleSFSymbolsNameForAxis_REAL
|
||||
#define SDL_hid_init SDL_hid_init_REAL
|
||||
#define SDL_hid_exit SDL_hid_exit_REAL
|
||||
#define SDL_hid_enumerate SDL_hid_enumerate_REAL
|
||||
#define SDL_hid_free_enumeration SDL_hid_free_enumeration_REAL
|
||||
#define SDL_hid_write SDL_hid_write_REAL
|
||||
#define SDL_hid_read_timeout SDL_hid_read_timeout_REAL
|
||||
#define SDL_hid_read SDL_hid_read_REAL
|
||||
#define SDL_hid_set_nonblocking SDL_hid_set_nonblocking_REAL
|
||||
#define SDL_hid_send_feature_report SDL_hid_send_feature_report_REAL
|
||||
#define SDL_hid_get_feature_report SDL_hid_get_feature_report_REAL
|
||||
#define SDL_hid_close SDL_hid_close_REAL
|
||||
#define SDL_hid_get_manufacturer_string SDL_hid_get_manufacturer_string_REAL
|
||||
#define SDL_hid_get_product_string SDL_hid_get_product_string_REAL
|
||||
#define SDL_hid_get_serial_number_string SDL_hid_get_serial_number_string_REAL
|
||||
#define SDL_hid_get_indexed_string SDL_hid_get_indexed_string_REAL
|
||||
|
@@ -896,3 +896,18 @@ SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriorityAndPolicy,(Sint64 a, int b, int c)
|
||||
#endif
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForButton,(SDL_GameController *a, SDL_GameControllerButton b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForAxis,(SDL_GameController *a, SDL_GameControllerAxis b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_init,(void),(),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_exit,(void),(),return)
|
||||
SDL_DYNAPI_PROC(SDL_hid_device_info*,SDL_hid_enumerate,(unsigned short a, unsigned short b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_hid_free_enumeration,(SDL_hid_device_info *a),(a),)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_write,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_read_timeout,(SDL_hid_device *a, unsigned char *b, size_t c, int d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_read,(SDL_hid_device *a, unsigned char *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_set_nonblocking,(SDL_hid_device *a, int b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_send_feature_report,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_get_feature_report,(SDL_hid_device *a, unsigned char *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(void,SDL_hid_close,(SDL_hid_device *a),(a),)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_get_manufacturer_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_get_product_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_get_serial_number_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_hid_get_indexed_string,(SDL_hid_device *a, int b, wchar_t *c, size_t d),(a,b,c,d),return)
|
||||
|
@@ -31,14 +31,12 @@
|
||||
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_hidapi.h"
|
||||
#include "SDL_hidapi_c.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
#ifndef SDL_DISABLE_HIDAPI
|
||||
|
||||
/* Platform HIDAPI Implementation */
|
||||
|
||||
#define hid_device_ PLATFORM_hid_device_
|
||||
#define hid_device PLATFORM_hid_device
|
||||
#define hid_device_info PLATFORM_hid_device_info
|
||||
#define hid_init PLATFORM_hid_init
|
||||
#define hid_exit PLATFORM_hid_exit
|
||||
#define hid_enumerate PLATFORM_hid_enumerate
|
||||
@@ -99,11 +97,18 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
||||
#include "windows/hid.c"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
#define udev_ctx 1
|
||||
#elif __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__
|
||||
/* The implementation for iOS and tvOS is in a separate .m file */
|
||||
#include "hidapi/hidapi.h"
|
||||
#define HAVE_PLATFORM_BACKEND 1
|
||||
#define udev_ctx 1
|
||||
#endif
|
||||
|
||||
#undef hid_device_
|
||||
#undef hid_device
|
||||
#undef hid_device_info
|
||||
#undef hid_init
|
||||
#undef hid_exit
|
||||
#undef hid_enumerate
|
||||
@@ -137,9 +142,6 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
||||
|
||||
/* DRIVER HIDAPI Implementation */
|
||||
|
||||
#define hid_device_ DRIVER_hid_device_
|
||||
#define hid_device DRIVER_hid_device
|
||||
#define hid_device_info DRIVER_hid_device_info
|
||||
#define hid_init DRIVER_hid_init
|
||||
#define hid_exit DRIVER_hid_exit
|
||||
#define hid_enumerate DRIVER_hid_enumerate
|
||||
@@ -166,9 +168,6 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
||||
#error Need a driver hid.c for this platform!
|
||||
#endif
|
||||
|
||||
#undef hid_device_
|
||||
#undef hid_device
|
||||
#undef hid_device_info
|
||||
#undef hid_init
|
||||
#undef hid_exit
|
||||
#undef hid_enumerate
|
||||
@@ -276,9 +275,6 @@ static struct
|
||||
#define libusb_handle_events libusb_ctx.handle_events
|
||||
#define libusb_handle_events_completed libusb_ctx.handle_events_completed
|
||||
|
||||
#define hid_device_ LIBUSB_hid_device_
|
||||
#define hid_device LIBUSB_hid_device
|
||||
#define hid_device_info LIBUSB_hid_device_info
|
||||
#define hid_init LIBUSB_hid_init
|
||||
#define hid_exit LIBUSB_hid_exit
|
||||
#define hid_enumerate LIBUSB_hid_enumerate
|
||||
@@ -327,9 +323,6 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
|
||||
#undef HIDAPI_H__
|
||||
#include "libusb/hid.c"
|
||||
|
||||
#undef hid_device_
|
||||
#undef hid_device
|
||||
#undef hid_device_info
|
||||
#undef hid_init
|
||||
#undef hid_exit
|
||||
#undef hid_enumerate
|
||||
@@ -357,24 +350,23 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
|
||||
|
||||
#endif /* SDL_LIBUSB_DYNAMIC */
|
||||
|
||||
#endif /* !SDL_DISABLE_HIDAPI */
|
||||
|
||||
/* Shared HIDAPI Implementation */
|
||||
|
||||
#undef HIDAPI_H__
|
||||
#include "hidapi/hidapi.h"
|
||||
|
||||
struct hidapi_backend {
|
||||
int (*hid_write)(hid_device* device, const unsigned char* data, size_t length);
|
||||
int (*hid_read_timeout)(hid_device* device, unsigned char* data, size_t length, int milliseconds);
|
||||
int (*hid_read)(hid_device* device, unsigned char* data, size_t length);
|
||||
int (*hid_set_nonblocking)(hid_device* device, int nonblock);
|
||||
int (*hid_send_feature_report)(hid_device* device, const unsigned char* data, size_t length);
|
||||
int (*hid_get_feature_report)(hid_device* device, unsigned char* data, size_t length);
|
||||
void (*hid_close)(hid_device* device);
|
||||
int (*hid_get_manufacturer_string)(hid_device* device, wchar_t* string, size_t maxlen);
|
||||
int (*hid_get_product_string)(hid_device* device, wchar_t* string, size_t maxlen);
|
||||
int (*hid_get_serial_number_string)(hid_device* device, wchar_t* string, size_t maxlen);
|
||||
int (*hid_get_indexed_string)(hid_device* device, int string_index, wchar_t* string, size_t maxlen);
|
||||
const wchar_t* (*hid_error)(hid_device* device);
|
||||
int (*hid_write)(SDL_hid_device* device, const unsigned char* data, size_t length);
|
||||
int (*hid_read_timeout)(SDL_hid_device* device, unsigned char* data, size_t length, int milliseconds);
|
||||
int (*hid_read)(SDL_hid_device* device, unsigned char* data, size_t length);
|
||||
int (*hid_set_nonblocking)(SDL_hid_device* device, int nonblock);
|
||||
int (*hid_send_feature_report)(SDL_hid_device* device, const unsigned char* data, size_t length);
|
||||
int (*hid_get_feature_report)(SDL_hid_device* device, unsigned char* data, size_t length);
|
||||
void (*hid_close)(SDL_hid_device* device);
|
||||
int (*hid_get_manufacturer_string)(SDL_hid_device* device, wchar_t* string, size_t maxlen);
|
||||
int (*hid_get_product_string)(SDL_hid_device* device, wchar_t* string, size_t maxlen);
|
||||
int (*hid_get_serial_number_string)(SDL_hid_device* device, wchar_t* string, size_t maxlen);
|
||||
int (*hid_get_indexed_string)(SDL_hid_device* device, int string_index, wchar_t* string, size_t maxlen);
|
||||
const wchar_t* (*hid_error)(SDL_hid_device* device);
|
||||
};
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
@@ -431,14 +423,14 @@ static const struct hidapi_backend LIBUSB_Backend = {
|
||||
typedef struct _HIDDeviceWrapper HIDDeviceWrapper;
|
||||
struct _HIDDeviceWrapper
|
||||
{
|
||||
hid_device *device; /* must be first field */
|
||||
SDL_hid_device *device; /* must be first field */
|
||||
const struct hidapi_backend *backend;
|
||||
};
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
|
||||
|
||||
static HIDDeviceWrapper *
|
||||
CreateHIDDeviceWrapper(hid_device *device, const struct hidapi_backend *backend)
|
||||
CreateHIDDeviceWrapper(SDL_hid_device *device, const struct hidapi_backend *backend)
|
||||
{
|
||||
HIDDeviceWrapper *ret = (HIDDeviceWrapper *)SDL_malloc(sizeof(*ret));
|
||||
ret->device = device;
|
||||
@@ -446,16 +438,16 @@ CreateHIDDeviceWrapper(hid_device *device, const struct hidapi_backend *backend)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static hid_device *
|
||||
static SDL_hid_device *
|
||||
WrapHIDDevice(HIDDeviceWrapper *wrapper)
|
||||
{
|
||||
return (hid_device *)wrapper;
|
||||
return (SDL_hid_device *)wrapper;
|
||||
}
|
||||
|
||||
#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
|
||||
|
||||
static HIDDeviceWrapper *
|
||||
UnwrapHIDDevice(hid_device *device)
|
||||
UnwrapHIDDevice(SDL_hid_device *device)
|
||||
{
|
||||
return (HIDDeviceWrapper *)device;
|
||||
}
|
||||
@@ -466,6 +458,8 @@ DeleteHIDDeviceWrapper(HIDDeviceWrapper *device)
|
||||
SDL_free(device);
|
||||
}
|
||||
|
||||
#ifndef SDL_DISABLE_HIDAPI
|
||||
|
||||
#define COPY_IF_EXISTS(var) \
|
||||
if (pSrc->var != NULL) { \
|
||||
pDst->var = SDL_strdup(pSrc->var); \
|
||||
@@ -479,10 +473,8 @@ DeleteHIDDeviceWrapper(HIDDeviceWrapper *device)
|
||||
pDst->var = NULL; \
|
||||
}
|
||||
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
static void
|
||||
LIBUSB_CopyHIDDeviceInfo(struct LIBUSB_hid_device_info *pSrc,
|
||||
struct hid_device_info *pDst)
|
||||
CopyHIDDeviceInfo(struct SDL_hid_device_info *pSrc, struct SDL_hid_device_info *pDst)
|
||||
{
|
||||
COPY_IF_EXISTS(path)
|
||||
pDst->vendor_id = pSrc->vendor_id;
|
||||
@@ -499,58 +491,26 @@ LIBUSB_CopyHIDDeviceInfo(struct LIBUSB_hid_device_info *pSrc,
|
||||
pDst->interface_protocol = pSrc->interface_protocol;
|
||||
pDst->next = NULL;
|
||||
}
|
||||
#endif /* SDL_LIBUSB_DYNAMIC */
|
||||
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
static void
|
||||
DRIVER_CopyHIDDeviceInfo(struct DRIVER_hid_device_info *pSrc,
|
||||
struct hid_device_info *pDst)
|
||||
{
|
||||
COPY_IF_EXISTS(path)
|
||||
pDst->vendor_id = pSrc->vendor_id;
|
||||
pDst->product_id = pSrc->product_id;
|
||||
WCOPY_IF_EXISTS(serial_number)
|
||||
pDst->release_number = pSrc->release_number;
|
||||
WCOPY_IF_EXISTS(manufacturer_string)
|
||||
WCOPY_IF_EXISTS(product_string)
|
||||
pDst->usage_page = pSrc->usage_page;
|
||||
pDst->usage = pSrc->usage;
|
||||
pDst->interface_number = pSrc->interface_number;
|
||||
pDst->interface_class = pSrc->interface_class;
|
||||
pDst->interface_subclass = pSrc->interface_subclass;
|
||||
pDst->interface_protocol = pSrc->interface_protocol;
|
||||
pDst->next = NULL;
|
||||
}
|
||||
#endif /* HAVE_DRIVER_BACKEND */
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
static void
|
||||
PLATFORM_CopyHIDDeviceInfo(struct PLATFORM_hid_device_info *pSrc,
|
||||
struct hid_device_info *pDst)
|
||||
{
|
||||
COPY_IF_EXISTS(path)
|
||||
pDst->vendor_id = pSrc->vendor_id;
|
||||
pDst->product_id = pSrc->product_id;
|
||||
WCOPY_IF_EXISTS(serial_number)
|
||||
pDst->release_number = pSrc->release_number;
|
||||
WCOPY_IF_EXISTS(manufacturer_string)
|
||||
WCOPY_IF_EXISTS(product_string)
|
||||
pDst->usage_page = pSrc->usage_page;
|
||||
pDst->usage = pSrc->usage;
|
||||
pDst->interface_number = pSrc->interface_number;
|
||||
pDst->interface_class = pSrc->interface_class;
|
||||
pDst->interface_subclass = pSrc->interface_subclass;
|
||||
pDst->interface_protocol = pSrc->interface_protocol;
|
||||
pDst->next = NULL;
|
||||
}
|
||||
#endif /* HAVE_PLATFORM_BACKEND */
|
||||
|
||||
#undef COPY_IF_EXISTS
|
||||
#undef WCOPY_IF_EXISTS
|
||||
|
||||
#endif /* SDL_DISABLE_HIDAPI */
|
||||
|
||||
static SDL_bool SDL_hidapi_wasinit = SDL_FALSE;
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_init(void)
|
||||
static void SDL_SetHIDAPIError( const wchar_t *error )
|
||||
{
|
||||
if (error) {
|
||||
char *error_utf8 = SDL_iconv_wchar_utf8(error);
|
||||
if (error_utf8) {
|
||||
SDL_SetError("%s", error_utf8);
|
||||
SDL_free(error_utf8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_hid_init(void)
|
||||
{
|
||||
int attempts = 0, success = 0;
|
||||
|
||||
@@ -624,7 +584,7 @@ int HID_API_EXPORT HID_API_CALL hid_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_exit(void)
|
||||
int SDL_hid_exit(void)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
@@ -650,24 +610,24 @@ int HID_API_EXPORT HID_API_CALL hid_exit(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
|
||||
struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned short product_id)
|
||||
{
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
struct LIBUSB_hid_device_info *usb_devs = NULL;
|
||||
struct LIBUSB_hid_device_info *usb_dev;
|
||||
struct SDL_hid_device_info *usb_devs = NULL;
|
||||
struct SDL_hid_device_info *usb_dev;
|
||||
#endif
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
struct DRIVER_hid_device_info* driver_devs = NULL;
|
||||
struct DRIVER_hid_device_info* driver_dev;
|
||||
struct SDL_hid_device_info* driver_devs = NULL;
|
||||
struct SDL_hid_device_info* driver_dev;
|
||||
#endif
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
struct PLATFORM_hid_device_info *raw_devs = NULL;
|
||||
struct PLATFORM_hid_device_info *raw_dev;
|
||||
struct SDL_hid_device_info *raw_devs = NULL;
|
||||
struct SDL_hid_device_info *raw_dev;
|
||||
#endif
|
||||
struct hid_device_info *devs = NULL, *last = NULL, *new_dev;
|
||||
struct SDL_hid_device_info *devs = NULL, *last = NULL, *new_dev;
|
||||
|
||||
if (hid_init() != 0) {
|
||||
if (SDL_hid_init() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -678,14 +638,14 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
|
||||
SDL_Log("libusb devices found:");
|
||||
#endif
|
||||
for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
|
||||
new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
|
||||
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
|
||||
if (!new_dev) {
|
||||
LIBUSB_hid_free_enumeration(usb_devs);
|
||||
hid_free_enumeration(devs);
|
||||
SDL_hid_free_enumeration(devs);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
LIBUSB_CopyHIDDeviceInfo(usb_dev, new_dev);
|
||||
CopyHIDDeviceInfo(usb_dev, new_dev);
|
||||
#ifdef DEBUG_HIDAPI
|
||||
SDL_Log(" - %ls %ls 0x%.4hx 0x%.4hx",
|
||||
usb_dev->manufacturer_string, usb_dev->product_string,
|
||||
@@ -705,8 +665,8 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
|
||||
#ifdef 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 hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
|
||||
DRIVER_CopyHIDDeviceInfo(driver_dev, new_dev);
|
||||
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
|
||||
CopyHIDDeviceInfo(driver_dev, new_dev);
|
||||
|
||||
if (last != NULL) {
|
||||
last->next = new_dev;
|
||||
@@ -751,7 +711,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
|
||||
}
|
||||
#endif
|
||||
if (!bFound) {
|
||||
new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
|
||||
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
|
||||
if (!new_dev) {
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
if (libusb_ctx.libhandle) {
|
||||
@@ -759,11 +719,11 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
|
||||
}
|
||||
#endif
|
||||
PLATFORM_hid_free_enumeration(raw_devs);
|
||||
hid_free_enumeration(devs);
|
||||
SDL_hid_free_enumeration(devs);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
PLATFORM_CopyHIDDeviceInfo(raw_dev, new_dev);
|
||||
CopyHIDDeviceInfo(raw_dev, new_dev);
|
||||
new_dev->next = NULL;
|
||||
|
||||
if (last != NULL) {
|
||||
@@ -790,10 +750,10 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor
|
||||
#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
|
||||
}
|
||||
|
||||
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
|
||||
void SDL_hid_free_enumeration(struct SDL_hid_device_info *devs)
|
||||
{
|
||||
while (devs) {
|
||||
struct hid_device_info *next = devs->next;
|
||||
struct SDL_hid_device_info *next = devs->next;
|
||||
SDL_free(devs->path);
|
||||
SDL_free(devs->serial_number);
|
||||
SDL_free(devs->manufacturer_string);
|
||||
@@ -803,18 +763,18 @@ void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *d
|
||||
}
|
||||
}
|
||||
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
|
||||
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(SDL_LIBUSB_DYNAMIC)
|
||||
hid_device *pDevice = NULL;
|
||||
SDL_hid_device *pDevice = NULL;
|
||||
|
||||
if (hid_init() != 0) {
|
||||
if (SDL_hid_init() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
if (udev_ctx &&
|
||||
(pDevice = (hid_device*) PLATFORM_hid_open(vendor_id, product_id, serial_number)) != NULL) {
|
||||
(pDevice = (SDL_hid_device*) PLATFORM_hid_open(vendor_id, product_id, serial_number)) != NULL) {
|
||||
|
||||
HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
|
||||
return WrapHIDDevice(wrapper);
|
||||
@@ -822,7 +782,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi
|
||||
#endif /* HAVE_PLATFORM_BACKEND */
|
||||
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
if ((pDevice = (hid_device*) DRIVER_hid_open(vendor_id, product_id, serial_number)) != NULL) {
|
||||
if ((pDevice = (SDL_hid_device*) DRIVER_hid_open(vendor_id, product_id, serial_number)) != NULL) {
|
||||
|
||||
HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend);
|
||||
return WrapHIDDevice(wrapper);
|
||||
@@ -831,7 +791,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi
|
||||
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
if (libusb_ctx.libhandle &&
|
||||
(pDevice = (hid_device*) LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) {
|
||||
(pDevice = (SDL_hid_device*) LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) {
|
||||
|
||||
HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
|
||||
return WrapHIDDevice(wrapper);
|
||||
@@ -843,18 +803,18 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bExclusive /* = false */)
|
||||
SDL_hid_device *SDL_hid_open_path(const char *path, int bExclusive /* = false */)
|
||||
{
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
|
||||
hid_device *pDevice = NULL;
|
||||
SDL_hid_device *pDevice = NULL;
|
||||
|
||||
if (hid_init() != 0) {
|
||||
if (SDL_hid_init() != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if HAVE_PLATFORM_BACKEND
|
||||
if (udev_ctx &&
|
||||
(pDevice = (hid_device*) PLATFORM_hid_open_path(path, bExclusive)) != NULL) {
|
||||
(pDevice = (SDL_hid_device*) PLATFORM_hid_open_path(path, bExclusive)) != NULL) {
|
||||
|
||||
HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
|
||||
return WrapHIDDevice(wrapper);
|
||||
@@ -862,7 +822,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx
|
||||
#endif /* HAVE_PLATFORM_BACKEND */
|
||||
|
||||
#if HAVE_DRIVER_BACKEND
|
||||
if ((pDevice = (hid_device*) DRIVER_hid_open_path(path, bExclusive)) != NULL) {
|
||||
if ((pDevice = (SDL_hid_device*) DRIVER_hid_open_path(path, bExclusive)) != NULL) {
|
||||
|
||||
HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend);
|
||||
return WrapHIDDevice(wrapper);
|
||||
@@ -871,7 +831,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx
|
||||
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
if (libusb_ctx.libhandle &&
|
||||
(pDevice = (hid_device*) LIBUSB_hid_open_path(path, bExclusive)) != NULL) {
|
||||
(pDevice = (SDL_hid_device*) LIBUSB_hid_open_path(path, bExclusive)) != NULL) {
|
||||
|
||||
HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
|
||||
return WrapHIDDevice(wrapper);
|
||||
@@ -883,77 +843,111 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length)
|
||||
int SDL_hid_write(SDL_hid_device *device, const unsigned char *data, size_t length)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_write(wrapper->device, data, length);
|
||||
int result = wrapper->backend->hid_write(wrapper->device, data, length);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int milliseconds)
|
||||
int SDL_hid_read_timeout(SDL_hid_device *device, unsigned char *data, size_t length, int milliseconds)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_read_timeout(wrapper->device, data, length, milliseconds);
|
||||
int result = wrapper->backend->hid_read_timeout(wrapper->device, data, length, milliseconds);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length)
|
||||
int SDL_hid_read(SDL_hid_device *device, unsigned char *data, size_t length)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_read(wrapper->device, data, length);
|
||||
int result = wrapper->backend->hid_read(wrapper->device, data, length);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock)
|
||||
int SDL_hid_set_nonblocking(SDL_hid_device *device, int nonblock)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_set_nonblocking(wrapper->device, nonblock);
|
||||
int result = wrapper->backend->hid_set_nonblocking(wrapper->device, nonblock);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length)
|
||||
int SDL_hid_send_feature_report(SDL_hid_device *device, const unsigned char *data, size_t length)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_send_feature_report(wrapper->device, data, length);
|
||||
int result = wrapper->backend->hid_send_feature_report(wrapper->device, data, length);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length)
|
||||
int SDL_hid_get_feature_report(SDL_hid_device *device, unsigned char *data, size_t length)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_get_feature_report(wrapper->device, data, length);
|
||||
int result = wrapper->backend->hid_get_feature_report(wrapper->device, data, length);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device)
|
||||
void SDL_hid_close(SDL_hid_device *device)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
wrapper->backend->hid_close(wrapper->device);
|
||||
DeleteHIDDeviceWrapper(wrapper);
|
||||
}
|
||||
|
||||
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen)
|
||||
int SDL_hid_get_manufacturer_string(SDL_hid_device *device, wchar_t *string, size_t maxlen)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_get_manufacturer_string(wrapper->device, string, maxlen);
|
||||
int result = wrapper->backend->hid_get_manufacturer_string(wrapper->device, string, maxlen);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen)
|
||||
int SDL_hid_get_product_string(SDL_hid_device *device, wchar_t *string, size_t maxlen)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_get_product_string(wrapper->device, string, maxlen);
|
||||
int result = wrapper->backend->hid_get_product_string(wrapper->device, string, maxlen);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen)
|
||||
int SDL_hid_get_serial_number_string(SDL_hid_device *device, wchar_t *string, size_t maxlen)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_get_serial_number_string(wrapper->device, string, maxlen);
|
||||
int result = wrapper->backend->hid_get_serial_number_string(wrapper->device, string, maxlen);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen)
|
||||
int SDL_hid_get_indexed_string(SDL_hid_device *device, int string_index, wchar_t *string, size_t maxlen)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_get_indexed_string(wrapper->device, string_index, string, maxlen);
|
||||
}
|
||||
|
||||
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device)
|
||||
{
|
||||
HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
|
||||
return wrapper->backend->hid_error(wrapper->device);
|
||||
int result = wrapper->backend->hid_get_indexed_string(wrapper->device, string_index, string, maxlen);
|
||||
if (result < 0) {
|
||||
SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
|
||||
@@ -1013,6 +1007,4 @@ void SDL_EnableGameCubeAdaptors(void)
|
||||
}
|
||||
#endif /* HAVE_ENABLE_GAMECUBE_ADAPTORS */
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
||||
/* vi: set sts=4 ts=4 sw=4 expandtab: */
|
||||
|
@@ -22,6 +22,27 @@
|
||||
//
|
||||
// This layer glues the hidapi API to Android's USB and BLE stack.
|
||||
|
||||
#ifndef SDL_DISABLE_HIDAPI
|
||||
|
||||
#define hid_init PLATFORM_hid_init
|
||||
#define hid_exit PLATFORM_hid_exit
|
||||
#define hid_enumerate PLATFORM_hid_enumerate
|
||||
#define hid_free_enumeration PLATFORM_hid_free_enumeration
|
||||
#define hid_open PLATFORM_hid_open
|
||||
#define hid_open_path PLATFORM_hid_open_path
|
||||
#define hid_write PLATFORM_hid_write
|
||||
#define hid_read_timeout PLATFORM_hid_read_timeout
|
||||
#define hid_read PLATFORM_hid_read
|
||||
#define hid_set_nonblocking PLATFORM_hid_set_nonblocking
|
||||
#define hid_send_feature_report PLATFORM_hid_send_feature_report
|
||||
#define hid_get_feature_report PLATFORM_hid_get_feature_report
|
||||
#define hid_close PLATFORM_hid_close
|
||||
#define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string
|
||||
#define hid_get_product_string PLATFORM_hid_get_product_string
|
||||
#define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string
|
||||
#define hid_get_indexed_string PLATFORM_hid_get_indexed_string
|
||||
#define hid_error PLATFORM_hid_error
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <pthread.h>
|
||||
@@ -1264,3 +1285,5 @@ int hid_exit(void)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* SDL_DISABLE_HIDAPI */
|
||||
|
@@ -29,7 +29,14 @@
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#if defined(_WIN32) && !defined(NAMESPACE) && (0) /* SDL: don't export hidapi syms */
|
||||
#ifdef SDL_hidapi_h_
|
||||
#define SDL_HIDAPI_IMPLEMENTATION
|
||||
#define hid_device_ SDL_hid_device_
|
||||
#define hid_device SDL_hid_device
|
||||
#define hid_device_info SDL_hid_device_info
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(NAMESPACE) && !defined(SDL_HIDAPI_IMPLEMENTATION) /* SDL: don't export hidapi syms */
|
||||
#define HID_API_EXPORT __declspec(dllexport)
|
||||
#define HID_API_CALL
|
||||
#else
|
||||
@@ -50,6 +57,7 @@ extern "C" {
|
||||
namespace NAMESPACE {
|
||||
#endif
|
||||
|
||||
#ifndef SDL_HIDAPI_IMPLEMENTATION
|
||||
struct hid_device_;
|
||||
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
|
||||
|
||||
@@ -93,6 +101,7 @@ namespace NAMESPACE {
|
||||
/** Pointer to the next device */
|
||||
struct hid_device_info *next;
|
||||
};
|
||||
#endif /* !SDL_HIDAPI_IMPLEMENTATION */
|
||||
|
||||
|
||||
/** @brief Initialize the HIDAPI library.
|
||||
|
@@ -20,7 +20,26 @@
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
#ifndef SDL_DISABLE_HIDAPI
|
||||
|
||||
#define hid_init PLATFORM_hid_init
|
||||
#define hid_exit PLATFORM_hid_exit
|
||||
#define hid_enumerate PLATFORM_hid_enumerate
|
||||
#define hid_free_enumeration PLATFORM_hid_free_enumeration
|
||||
#define hid_open PLATFORM_hid_open
|
||||
#define hid_open_path PLATFORM_hid_open_path
|
||||
#define hid_write PLATFORM_hid_write
|
||||
#define hid_read_timeout PLATFORM_hid_read_timeout
|
||||
#define hid_read PLATFORM_hid_read
|
||||
#define hid_set_nonblocking PLATFORM_hid_set_nonblocking
|
||||
#define hid_send_feature_report PLATFORM_hid_send_feature_report
|
||||
#define hid_get_feature_report PLATFORM_hid_get_feature_report
|
||||
#define hid_close PLATFORM_hid_close
|
||||
#define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string
|
||||
#define hid_get_product_string PLATFORM_hid_get_product_string
|
||||
#define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string
|
||||
#define hid_get_indexed_string PLATFORM_hid_get_indexed_string
|
||||
#define hid_error PLATFORM_hid_error
|
||||
|
||||
#include <CoreBluetooth/CoreBluetooth.h>
|
||||
#include <QuartzCore/QuartzCore.h>
|
||||
@@ -737,7 +756,12 @@ void HID_API_EXPORT HID_API_CALL hid_ble_scan( bool bStart )
|
||||
}
|
||||
}
|
||||
|
||||
hid_device * HID_API_EXPORT hid_open_path( const char *path, int bExclusive /* = false */ )
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path( const char *path, int bExclusive /* = false */ )
|
||||
{
|
||||
hid_device *result = NULL;
|
||||
NSString *nssPath = [NSString stringWithUTF8String:path];
|
||||
@@ -851,6 +875,11 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
|
||||
{
|
||||
HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle;
|
||||
@@ -927,4 +956,9 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* !SDL_DISABLE_HIDAPI */
|
||||
|
@@ -31,8 +31,6 @@
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_mutex.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
|
||||
#if defined(HAVE__WCSDUP) && !defined(HAVE_WCSDUP)
|
||||
#define wcsdup _wcsdup
|
||||
#endif
|
||||
@@ -1742,5 +1740,3 @@ uint16_t get_usb_code_for_current_locale(void)
|
||||
#ifdef NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
@@ -22,8 +22,6 @@
|
||||
********************************************************/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */
|
||||
#endif
|
||||
@@ -902,5 +900,3 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev)
|
||||
#ifdef NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
@@ -21,8 +21,6 @@
|
||||
********************************************************/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
|
||||
/* See Apple Technical Note TN2187 for details on IOHidManager. */
|
||||
|
||||
#include <IOKit/hid/IOHIDManager.h>
|
||||
@@ -1191,5 +1189,3 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
@@ -21,8 +21,6 @@
|
||||
********************************************************/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#ifndef _WIN32_WINNT_WIN8
|
||||
@@ -1099,5 +1097,3 @@ int __cdecl main(int argc, char* argv[])
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
||||
|
@@ -32,7 +32,7 @@
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
#include "SDL_hidapi_rumble.h"
|
||||
#include "../../hidapi/SDL_hidapi.h"
|
||||
#include "../../hidapi/SDL_hidapi_c.h"
|
||||
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
|
||||
@@ -129,7 +129,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_free(ctx);
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
@@ -154,7 +154,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
} else {
|
||||
/* This is all that's needed to initialize the device. Really! */
|
||||
if (hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
|
||||
if (SDL_hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
|
||||
SDL_SetError("Couldn't initialize WUP-028");
|
||||
goto error;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
|
||||
SDL_Delay(10);
|
||||
|
||||
/* Add all the applicable joysticks */
|
||||
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
#ifdef DEBUG_GAMECUBE_PROTOCOL
|
||||
HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
|
||||
#endif
|
||||
@@ -204,7 +204,7 @@ error:
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
@@ -389,7 +389,7 @@ HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
int size;
|
||||
|
||||
/* Read input packet */
|
||||
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
|
||||
#ifdef DEBUG_GAMECUBE_PROTOCOL
|
||||
//HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
|
||||
#endif
|
||||
@@ -510,7 +510,7 @@ HIDAPI_DriverGameCube_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -87,7 +87,7 @@ HIDAPI_DriverLuna_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
SDL_free(ctx);
|
||||
@@ -386,7 +386,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_LUNA_PROTOCOL
|
||||
HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -413,7 +413,7 @@ HIDAPI_DriverLuna_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
|
||||
|
@@ -163,11 +163,11 @@ HIDAPI_DriverPS4_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
|
||||
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
|
||||
{
|
||||
SDL_memset(report, 0, length);
|
||||
report[0] = report_id;
|
||||
return hid_get_feature_report(dev, report, length);
|
||||
return SDL_hid_get_feature_report(dev, report, length);
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_DriverPS4_CanRumble(Uint16 vendor_id, Uint16 product_id)
|
||||
@@ -479,7 +479,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
ctx->joystick = joystick;
|
||||
ctx->last_packet = SDL_GetTicks();
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_free(ctx);
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
@@ -511,7 +511,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
ctx->is_bluetooth = SDL_TRUE;
|
||||
|
||||
/* Read a report to see if we're in enhanced mode */
|
||||
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
|
||||
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
|
||||
#ifdef DEBUG_PS4_PROTOCOL
|
||||
if (size > 0) {
|
||||
HIDAPI_DumpPacket("PS4 first packet: size = %d", data, size);
|
||||
@@ -684,7 +684,7 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
|
||||
HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
|
||||
{
|
||||
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
|
||||
static const float TOUCHPAD_SCALEY = 1.0f / 920; /* This is noted as being 944 resolution, but 920 feels better */
|
||||
@@ -846,7 +846,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_PS4_PROTOCOL
|
||||
HIDAPI_DumpPacket("PS4 packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -908,7 +908,7 @@ HIDAPI_DriverPS4_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
|
||||
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -192,11 +192,11 @@ HIDAPI_DriverPS5_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
|
||||
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
|
||||
{
|
||||
SDL_memset(report, 0, length);
|
||||
report[0] = report_id;
|
||||
return hid_get_feature_report(dev, report, length);
|
||||
return SDL_hid_get_feature_report(dev, report, length);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -553,7 +553,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
ctx->joystick = joystick;
|
||||
ctx->last_packet = SDL_GetTicks();
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_free(ctx);
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
@@ -562,7 +562,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
device->context = ctx;
|
||||
|
||||
/* Read a report to see what mode we're in */
|
||||
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
|
||||
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
|
||||
#ifdef DEBUG_PS5_PROTOCOL
|
||||
if (size > 0) {
|
||||
HIDAPI_DumpPacket("PS5 first packet: size = %d", data, size);
|
||||
@@ -761,7 +761,7 @@ HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet)
|
||||
HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet)
|
||||
{
|
||||
Sint16 axis;
|
||||
|
||||
@@ -855,7 +855,7 @@ HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, hid_device *dev
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet)
|
||||
HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet)
|
||||
{
|
||||
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
|
||||
static const float TOUCHPAD_SCALEY = 1.0f / 1070;
|
||||
@@ -1010,7 +1010,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_PS5_PROTOCOL
|
||||
HIDAPI_DumpPacket("PS5 packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -1071,7 +1071,7 @@ HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
|
||||
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -80,7 +80,7 @@ static int SDL_HIDAPI_RumbleThread(void *data)
|
||||
#ifdef DEBUG_RUMBLE
|
||||
HIDAPI_DumpPacket("Rumble packet: size = %d", request->data, request->size);
|
||||
#endif
|
||||
hid_write(request->device->dev, request->data, request->size);
|
||||
SDL_hid_write(request->device->dev, request->data, request->size);
|
||||
}
|
||||
SDL_UnlockMutex(request->device->dev_lock);
|
||||
(void)SDL_AtomicDecRef(&request->device->rumble_pending);
|
||||
|
@@ -88,7 +88,7 @@ HIDAPI_DriverStadia_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
SDL_free(ctx);
|
||||
@@ -267,7 +267,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_STADIA_PROTOCOL
|
||||
HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -287,7 +287,7 @@ HIDAPI_DriverStadia_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
|
||||
|
@@ -305,7 +305,7 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
|
||||
|
||||
#define BLE_MAX_READ_RETRIES 8
|
||||
|
||||
static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nActualDataLen )
|
||||
static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int nActualDataLen )
|
||||
{
|
||||
int nRet = -1;
|
||||
bool bBle = true; // only wireless/BLE for now, though macOS could do wired in the future
|
||||
@@ -339,7 +339,7 @@ static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nAc
|
||||
pBufferPtr += nBytesInPacket;
|
||||
nSegmentNumber++;
|
||||
|
||||
nRet = hid_send_feature_report( dev, uPacketBuffer, sizeof( uPacketBuffer ) );
|
||||
nRet = SDL_hid_send_feature_report( dev, uPacketBuffer, sizeof( uPacketBuffer ) );
|
||||
DPRINTF("SetFeatureReport() ret = %d\n", nRet);
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nAc
|
||||
return nRet;
|
||||
}
|
||||
|
||||
static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] )
|
||||
static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
|
||||
{
|
||||
int nRet = -1;
|
||||
bool bBle = true;
|
||||
@@ -366,7 +366,7 @@ static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] )
|
||||
{
|
||||
memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) );
|
||||
uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER;
|
||||
nRet = hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) );
|
||||
nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) );
|
||||
DPRINTF( "GetFeatureReport ble ret=%d\n", nRet );
|
||||
HEXDUMP( uSegmentBuffer, nRet );
|
||||
|
||||
@@ -400,7 +400,7 @@ static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] )
|
||||
return nRet;
|
||||
}
|
||||
|
||||
static int ReadResponse( hid_device *dev, uint8_t uBuffer[65], int nExpectedResponse )
|
||||
static int ReadResponse( SDL_hid_device *dev, uint8_t uBuffer[65], int nExpectedResponse )
|
||||
{
|
||||
int nRet = GetFeatureReport( dev, uBuffer );
|
||||
|
||||
@@ -421,7 +421,7 @@ static int ReadResponse( hid_device *dev, uint8_t uBuffer[65], int nExpectedResp
|
||||
//---------------------------------------------------------------------------
|
||||
// Reset steam controller (unmap buttons and pads) and re-fetch capability bits
|
||||
//---------------------------------------------------------------------------
|
||||
static bool ResetSteamController( hid_device *dev, bool bSuppressErrorSpew, uint32_t *punUpdateRateUS )
|
||||
static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, uint32_t *punUpdateRateUS )
|
||||
{
|
||||
// Firmware quirk: Set Feature and Get Feature requests always require a 65-byte buffer.
|
||||
unsigned char buf[65];
|
||||
@@ -606,18 +606,18 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
|
||||
//---------------------------------------------------------------------------
|
||||
// Read from a Steam Controller
|
||||
//---------------------------------------------------------------------------
|
||||
static int ReadSteamController( hid_device *dev, uint8_t *pData, int nDataSize )
|
||||
static int ReadSteamController( SDL_hid_device *dev, uint8_t *pData, int nDataSize )
|
||||
{
|
||||
memset( pData, 0, nDataSize );
|
||||
pData[ 0 ] = BLE_REPORT_NUMBER; // hid_read will also overwrite this with the same value, 0x03
|
||||
return hid_read( dev, pData, nDataSize );
|
||||
return SDL_hid_read( dev, pData, nDataSize );
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// Close a Steam Controller
|
||||
//---------------------------------------------------------------------------
|
||||
static void CloseSteamController( hid_device *dev )
|
||||
static void CloseSteamController( SDL_hid_device *dev )
|
||||
{
|
||||
// Switch the Steam Controller back to lizard mode so it works with the OS
|
||||
unsigned char buf[65];
|
||||
@@ -1040,12 +1040,12 @@ HIDAPI_DriverSteam_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
|
||||
}
|
||||
device->context = ctx;
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
goto error;
|
||||
}
|
||||
hid_set_nonblocking(device->dev, 1);
|
||||
SDL_hid_set_nonblocking(device->dev, 1);
|
||||
|
||||
if (!ResetSteamController(device->dev, false, &update_rate_in_us)) {
|
||||
SDL_SetError("Couldn't reset controller");
|
||||
@@ -1070,7 +1070,7 @@ error:
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
@@ -1266,7 +1266,7 @@ HIDAPI_DriverSteam_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
{
|
||||
CloseSteamController(device->dev);
|
||||
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -346,13 +346,13 @@ static int ReadInput(SDL_DriverSwitch_Context *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hid_read_timeout(ctx->device->dev, ctx->m_rgucReadBuffer, sizeof(ctx->m_rgucReadBuffer), 0);
|
||||
return SDL_hid_read_timeout(ctx->device->dev, ctx->m_rgucReadBuffer, sizeof(ctx->m_rgucReadBuffer), 0);
|
||||
}
|
||||
|
||||
static int WriteOutput(SDL_DriverSwitch_Context *ctx, const Uint8 *data, int size)
|
||||
{
|
||||
#ifdef SWITCH_SYNCHRONOUS_WRITES
|
||||
return hid_write(ctx->device->dev, data, size);
|
||||
return SDL_hid_write(ctx->device->dev, data, size);
|
||||
#else
|
||||
/* Use the rumble thread for general asynchronous writes */
|
||||
if (SDL_HIDAPI_LockRumble() < 0) {
|
||||
@@ -856,7 +856,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
|
||||
ctx->device = device;
|
||||
device->context = ctx;
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
goto error;
|
||||
@@ -986,7 +986,7 @@ error:
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
if (device->context) {
|
||||
@@ -1530,7 +1530,7 @@ HIDAPI_DriverSwitch_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
|
||||
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -88,14 +88,14 @@ HIDAPI_DriverXbox360_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot)
|
||||
static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot)
|
||||
{
|
||||
const SDL_bool blink = SDL_FALSE;
|
||||
Uint8 mode = (blink ? 0x02 : 0x06) + slot;
|
||||
Uint8 led_packet[] = { 0x01, 0x03, 0x00 };
|
||||
|
||||
led_packet[2] = mode;
|
||||
if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
|
||||
if (SDL_hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
@@ -136,7 +136,7 @@ HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
SDL_free(ctx);
|
||||
@@ -296,7 +296,7 @@ HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_XBOX_PROTOCOL
|
||||
HIDAPI_DumpPacket("Xbox 360 packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -318,7 +318,7 @@ HIDAPI_DriverXbox360_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
if (device->dev) {
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
}
|
||||
|
||||
|
@@ -62,14 +62,14 @@ HIDAPI_DriverXbox360W_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
|
||||
return "Xbox 360 Wireless Controller";
|
||||
}
|
||||
|
||||
static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot)
|
||||
static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot)
|
||||
{
|
||||
const SDL_bool blink = SDL_FALSE;
|
||||
Uint8 mode = (blink ? 0x02 : 0x06) + slot;
|
||||
Uint8 led_packet[] = { 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
led_packet[3] = 0x40 + (mode % 0x0e);
|
||||
if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
|
||||
if (SDL_hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
@@ -105,7 +105,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_free(ctx);
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
@@ -113,7 +113,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device)
|
||||
}
|
||||
device->context = ctx;
|
||||
|
||||
if (hid_write(device->dev, init_packet, sizeof(init_packet)) != sizeof(init_packet)) {
|
||||
if (SDL_hid_write(device->dev, init_packet, sizeof(init_packet)) != sizeof(init_packet)) {
|
||||
SDL_SetError("Couldn't write init packet");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ HIDAPI_DriverXbox360W_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_J
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverXbox360W_Context *ctx, Uint8 *data, int size)
|
||||
HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverXbox360W_Context *ctx, Uint8 *data, int size)
|
||||
{
|
||||
Sint16 axis;
|
||||
const SDL_bool invert_y_axes = SDL_TRUE;
|
||||
@@ -259,7 +259,7 @@ HIDAPI_DriverXbox360W_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
|
||||
}
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_XBOX_PROTOCOL
|
||||
HIDAPI_DumpPacket("Xbox 360 wireless packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -321,7 +321,7 @@ HIDAPI_DriverXbox360W_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -317,7 +317,7 @@ HIDAPI_DriverXboxOne_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
device->dev = hid_open_path(device->path, 0);
|
||||
device->dev = SDL_hid_open_path(device->path, 0);
|
||||
if (!device->dev) {
|
||||
SDL_free(ctx);
|
||||
SDL_SetError("Couldn't open %s", device->path);
|
||||
@@ -945,7 +945,7 @@ HIDAPI_DriverXboxOne_UpdateJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joy
|
||||
Uint8 data[USB_PACKET_LENGTH];
|
||||
int size;
|
||||
|
||||
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
|
||||
#ifdef DEBUG_XBOX_PROTOCOL
|
||||
HIDAPI_DumpPacket("Xbox One packet: size = %d", data, size);
|
||||
#endif
|
||||
@@ -1099,7 +1099,7 @@ HIDAPI_DriverXboxOne_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
|
||||
{
|
||||
SDL_LockMutex(device->dev_lock);
|
||||
{
|
||||
hid_close(device->dev);
|
||||
SDL_hid_close(device->dev);
|
||||
device->dev = NULL;
|
||||
|
||||
SDL_free(device->context);
|
||||
|
@@ -767,17 +767,7 @@ HIDAPI_JoystickInit(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
|
||||
/* The hidapi framwork is weak-linked on Apple platforms */
|
||||
int HID_API_EXPORT HID_API_CALL hid_init(void) __attribute__((weak_import));
|
||||
|
||||
if (hid_init == NULL) {
|
||||
SDL_SetError("Couldn't initialize hidapi, framework not available");
|
||||
return -1;
|
||||
}
|
||||
#endif /* __MACOSX__ || __IPHONEOS__ || __TVOS__ */
|
||||
|
||||
if (hid_init() < 0) {
|
||||
if (SDL_hid_init() < 0) {
|
||||
SDL_SetError("Couldn't initialize hidapi");
|
||||
return -1;
|
||||
}
|
||||
@@ -874,7 +864,7 @@ HIDAPI_ConvertString(const wchar_t *wide_string)
|
||||
}
|
||||
|
||||
static void
|
||||
HIDAPI_AddDevice(struct hid_device_info *info)
|
||||
HIDAPI_AddDevice(struct SDL_hid_device_info *info)
|
||||
{
|
||||
SDL_HIDAPI_Device *device;
|
||||
SDL_HIDAPI_Device *curr, *last = NULL;
|
||||
@@ -994,6 +984,7 @@ HIDAPI_AddDevice(struct hid_device_info *info)
|
||||
|
||||
HIDAPI_SetupDeviceDriver(device);
|
||||
|
||||
#define DEBUG_HIDAPI
|
||||
#ifdef DEBUG_HIDAPI
|
||||
SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, serial %s, interface %d, interface_class %d, interface_subclass %d, interface_protocol %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s (%s)\n", device->name, device->vendor_id, device->product_id, device->version, device->serial ? device->serial : "NONE", device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE", device->driver && device->driver->enabled ? "ENABLED" : "DISABLED");
|
||||
#endif
|
||||
@@ -1038,7 +1029,7 @@ static void
|
||||
HIDAPI_UpdateDeviceList(void)
|
||||
{
|
||||
SDL_HIDAPI_Device *device;
|
||||
struct hid_device_info *devs, *info;
|
||||
struct SDL_hid_device_info *devs, *info;
|
||||
|
||||
SDL_LockJoysticks();
|
||||
|
||||
@@ -1051,7 +1042,7 @@ HIDAPI_UpdateDeviceList(void)
|
||||
|
||||
/* Enumerate the devices */
|
||||
if (SDL_HIDAPI_numdrivers > 0) {
|
||||
devs = hid_enumerate(0, 0);
|
||||
devs = SDL_hid_enumerate(0, 0);
|
||||
if (devs) {
|
||||
for (info = devs; info; info = info->next) {
|
||||
device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
|
||||
@@ -1061,7 +1052,7 @@ HIDAPI_UpdateDeviceList(void)
|
||||
HIDAPI_AddDevice(info);
|
||||
}
|
||||
}
|
||||
hid_free_enumeration(devs);
|
||||
SDL_hid_free_enumeration(devs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1495,7 +1486,7 @@ HIDAPI_JoystickQuit(void)
|
||||
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI,
|
||||
SDL_HIDAPIDriverHintChanged, NULL);
|
||||
|
||||
hid_exit();
|
||||
SDL_hid_exit();
|
||||
|
||||
shutting_down = SDL_FALSE;
|
||||
initialized = SDL_FALSE;
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_gamecontroller.h"
|
||||
#include "../../hidapi/hidapi/hidapi.h"
|
||||
#include "SDL_hidapi.h"
|
||||
#include "../usb_ids.h"
|
||||
|
||||
/* This is the full set of HIDAPI drivers available */
|
||||
@@ -70,7 +70,7 @@ typedef struct _SDL_HIDAPI_Device
|
||||
struct _SDL_HIDAPI_DeviceDriver *driver;
|
||||
void *context;
|
||||
SDL_mutex *dev_lock;
|
||||
hid_device *dev;
|
||||
SDL_hid_device *dev;
|
||||
SDL_atomic_t rumble_pending;
|
||||
int num_joysticks;
|
||||
SDL_JoystickID *joysticks;
|
||||
|
@@ -146,6 +146,11 @@ static struct
|
||||
{ "US-ASCII", ENCODING_ASCII },
|
||||
{ "8859-1", ENCODING_LATIN1 },
|
||||
{ "ISO-8859-1", ENCODING_LATIN1 },
|
||||
#ifdef __WIN32__
|
||||
{ "WCHAR_T", ENCODING_UTF16LE },
|
||||
#else
|
||||
{ "WCHAR_T", ENCODING_UCS4NATIVE },
|
||||
#endif
|
||||
{ "UTF8", ENCODING_UTF8 },
|
||||
{ "UTF-8", ENCODING_UTF8 },
|
||||
{ "UTF16", ENCODING_UTF16 },
|
||||
|
Reference in New Issue
Block a user