2018-08-09 23:00:17 +00:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2020-01-17 04:49:25 +00:00
|
|
|
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
2018-08-09 23:00:17 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
#include "../../SDL_internal.h"
|
|
|
|
|
|
|
|
#ifndef SDL_JOYSTICK_HIDAPI_H
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_H
|
|
|
|
|
|
|
|
#include "../../hidapi/hidapi/hidapi.h"
|
2020-01-18 19:21:14 +00:00
|
|
|
#include "../usb_ids.h"
|
2018-08-09 23:00:17 +00:00
|
|
|
|
|
|
|
/* This is the full set of HIDAPI drivers available */
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS4
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_SWITCH
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_XBOX360
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_XBOXONE
|
2019-12-19 23:01:35 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
|
2018-08-09 23:00:17 +00:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2018-08-16 06:14:45 +00:00
|
|
|
/* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
|
2018-08-09 23:00:17 +00:00
|
|
|
#undef SDL_JOYSTICK_HIDAPI_XBOXONE
|
2018-10-05 08:41:59 +00:00
|
|
|
/* It turns out HIDAPI for Xbox controllers doesn't allow background input */
|
|
|
|
#undef SDL_JOYSTICK_HIDAPI_XBOX360
|
2018-08-09 23:00:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __MACOSX__
|
|
|
|
/* On Mac OS X, Xbox One controllers are handled by the Xbox 360 driver */
|
|
|
|
#undef SDL_JOYSTICK_HIDAPI_XBOXONE
|
|
|
|
#endif
|
|
|
|
|
2020-01-30 04:09:11 +00:00
|
|
|
#if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
|
|
|
|
/* Very basic Steam Controller support on mobile devices */
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_STEAM
|
|
|
|
#endif
|
|
|
|
|
2019-12-19 23:01:30 +00:00
|
|
|
/* Forward declaration */
|
|
|
|
struct _SDL_HIDAPI_DeviceDriver;
|
|
|
|
|
|
|
|
typedef struct _SDL_HIDAPI_Device
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *path;
|
|
|
|
Uint16 vendor_id;
|
|
|
|
Uint16 product_id;
|
|
|
|
Uint16 version;
|
|
|
|
SDL_JoystickGUID guid;
|
|
|
|
int interface_number; /* Available on Windows and Linux */
|
2020-01-18 19:21:14 +00:00
|
|
|
int interface_class;
|
|
|
|
int interface_subclass;
|
|
|
|
int interface_protocol;
|
2019-12-19 23:01:30 +00:00
|
|
|
Uint16 usage_page; /* Available on Windows and Mac OS X */
|
|
|
|
Uint16 usage; /* Available on Windows and Mac OS X */
|
|
|
|
|
|
|
|
struct _SDL_HIDAPI_DeviceDriver *driver;
|
|
|
|
void *context;
|
|
|
|
hid_device *dev;
|
|
|
|
int num_joysticks;
|
|
|
|
SDL_JoystickID *joysticks;
|
|
|
|
|
|
|
|
/* Used during scanning for device changes */
|
|
|
|
SDL_bool seen;
|
|
|
|
|
|
|
|
struct _SDL_HIDAPI_Device *next;
|
|
|
|
} SDL_HIDAPI_Device;
|
|
|
|
|
2018-08-09 23:00:17 +00:00
|
|
|
typedef struct _SDL_HIDAPI_DeviceDriver
|
|
|
|
{
|
|
|
|
const char *hint;
|
|
|
|
SDL_bool enabled;
|
2020-01-19 19:43:36 +00:00
|
|
|
SDL_bool (*IsSupportedDevice)(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
|
2018-08-09 23:00:17 +00:00
|
|
|
const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
|
2019-12-19 23:01:30 +00:00
|
|
|
SDL_bool (*InitDevice)(SDL_HIDAPI_Device *device);
|
2019-12-21 04:12:03 +00:00
|
|
|
int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
|
|
|
|
void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
|
2019-12-19 23:01:30 +00:00
|
|
|
SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
|
|
|
|
SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
|
2020-02-04 20:48:53 +00:00
|
|
|
int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
|
2019-12-19 23:01:30 +00:00
|
|
|
void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
|
|
|
|
void (*FreeDevice)(SDL_HIDAPI_Device *device);
|
2018-08-09 23:00:17 +00:00
|
|
|
|
|
|
|
} SDL_HIDAPI_DeviceDriver;
|
|
|
|
|
2020-02-04 20:48:53 +00:00
|
|
|
|
|
|
|
/* The maximum size of a USB packet for HID devices */
|
|
|
|
#define USB_PACKET_LENGTH 64
|
|
|
|
|
2018-08-09 23:00:17 +00:00
|
|
|
/* HIDAPI device support */
|
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
|
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
|
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
|
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
|
2019-12-19 23:01:32 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
|
2018-08-09 23:00:17 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
|
2019-12-19 23:01:35 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
|
2018-08-09 23:00:17 +00:00
|
|
|
|
|
|
|
/* Return true if a HID device is present and supported as a joystick */
|
2019-10-22 17:57:07 +00:00
|
|
|
extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
|
2018-08-09 23:00:17 +00:00
|
|
|
|
2019-12-19 23:01:35 +00:00
|
|
|
extern void HIDAPI_UpdateDevices(void);
|
2019-12-19 23:01:30 +00:00
|
|
|
extern SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);
|
|
|
|
extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);
|
|
|
|
|
2018-08-09 23:00:17 +00:00
|
|
|
#endif /* SDL_JOYSTICK_HIDAPI_H */
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|