2018-08-09 23:00:17 +00:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2022-01-03 17:40:00 +00:00
|
|
|
Copyright (C) 1997-2022 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
|
|
|
|
|
2020-02-04 23:26:56 +00:00
|
|
|
#include "SDL_atomic.h"
|
2022-08-19 18:11:23 +00:00
|
|
|
#include "SDL_hints.h"
|
2020-02-04 23:26:56 +00:00
|
|
|
#include "SDL_mutex.h"
|
|
|
|
#include "SDL_joystick.h"
|
|
|
|
#include "SDL_gamecontroller.h"
|
2021-11-08 06:58:44 +00:00
|
|
|
#include "SDL_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 */
|
2021-01-23 19:06:35 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
|
2021-07-07 13:05:35 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_LUNA
|
2022-08-24 05:45:37 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS3
|
2018-08-09 23:00:17 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS4
|
2020-11-06 01:03:28 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS5
|
2021-01-23 19:06:35 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_STADIA
|
2018-08-09 23:00:17 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_SWITCH
|
2022-09-01 22:29:01 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_WII
|
2018-08-09 23:00:17 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_XBOX360
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_XBOXONE
|
2022-07-10 03:55:36 +00:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_SHIELD
|
2018-08-09 23:00:17 +00:00
|
|
|
|
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
|
|
|
|
|
2022-08-19 18:11:23 +00:00
|
|
|
/* Whether HIDAPI is enabled by default */
|
|
|
|
#define SDL_HIDAPI_DEFAULT SDL_TRUE
|
|
|
|
|
2020-02-04 23:26:56 +00:00
|
|
|
/* The maximum size of a USB packet for HID devices */
|
|
|
|
#define USB_PACKET_LENGTH 64
|
|
|
|
|
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;
|
2020-11-17 01:36:47 +00:00
|
|
|
char *serial;
|
2019-12-19 23:01:30 +00:00
|
|
|
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 */
|
2022-09-26 21:20:34 +00:00
|
|
|
SDL_bool is_bluetooth;
|
2022-09-23 07:15:40 +00:00
|
|
|
SDL_JoystickType joystick_type;
|
2022-09-23 06:42:25 +00:00
|
|
|
SDL_GameControllerType type;
|
2019-12-19 23:01:30 +00:00
|
|
|
|
|
|
|
struct _SDL_HIDAPI_DeviceDriver *driver;
|
|
|
|
void *context;
|
2020-02-04 23:26:56 +00:00
|
|
|
SDL_mutex *dev_lock;
|
2021-11-08 06:58:44 +00:00
|
|
|
SDL_hid_device *dev;
|
2020-02-04 23:26:56 +00:00
|
|
|
SDL_atomic_t rumble_pending;
|
2019-12-19 23:01:30 +00:00
|
|
|
int num_joysticks;
|
|
|
|
SDL_JoystickID *joysticks;
|
|
|
|
|
|
|
|
/* Used during scanning for device changes */
|
|
|
|
SDL_bool seen;
|
|
|
|
|
2020-12-13 09:20:38 +00:00
|
|
|
/* Used to flag that the device is being updated */
|
|
|
|
SDL_bool updating;
|
|
|
|
|
2022-07-29 02:22:27 +00:00
|
|
|
struct _SDL_HIDAPI_Device *parent;
|
|
|
|
int num_children;
|
|
|
|
struct _SDL_HIDAPI_Device **children;
|
|
|
|
|
2019-12-19 23:01:30 +00:00
|
|
|
struct _SDL_HIDAPI_Device *next;
|
|
|
|
} SDL_HIDAPI_Device;
|
|
|
|
|
2018-08-09 23:00:17 +00:00
|
|
|
typedef struct _SDL_HIDAPI_DeviceDriver
|
|
|
|
{
|
2022-08-19 18:11:23 +00:00
|
|
|
const char *name;
|
2018-08-09 23:00:17 +00:00
|
|
|
SDL_bool enabled;
|
2022-08-19 18:11:23 +00:00
|
|
|
void (*RegisterHints)(SDL_HintCallback callback, void *userdata);
|
|
|
|
void (*UnregisterHints)(SDL_HintCallback callback, void *userdata);
|
|
|
|
SDL_bool (*IsEnabled)(void);
|
2022-08-30 21:56:11 +00:00
|
|
|
SDL_bool (*IsSupportedDevice)(SDL_HIDAPI_Device *device, 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);
|
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);
|
2020-11-12 02:57:37 +00:00
|
|
|
int (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
|
2021-11-11 17:13:08 +00:00
|
|
|
Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
|
2020-04-30 15:57:29 +00:00
|
|
|
int (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
|
2021-07-08 20:22:41 +00:00
|
|
|
int (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size);
|
2020-11-17 18:30:20 +00:00
|
|
|
int (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled);
|
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
|
|
|
|
2018-08-09 23:00:17 +00:00
|
|
|
/* HIDAPI device support */
|
2022-07-29 02:22:27 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined;
|
2021-01-23 19:06:35 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
|
2022-08-03 20:07:47 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons;
|
2021-07-07 13:05:35 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;
|
2022-08-03 20:07:47 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic;
|
2022-08-24 05:45:37 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3;
|
2022-09-23 09:39:35 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty;
|
2018-08-09 23:00:17 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
|
2020-11-06 01:03:28 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
|
2022-08-03 20:07:47 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield;
|
2021-01-23 19:06:35 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia;
|
2018-08-09 23:00:17 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
|
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
|
2022-09-01 22:29:01 +00:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii;
|
2018-08-09 23:00:17 +00:00
|
|
|
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;
|
|
|
|
|
2021-07-27 06:29:20 +00:00
|
|
|
/* Return true if a HID device is present and supported as a joystick of the given type */
|
|
|
|
extern SDL_bool HIDAPI_IsDeviceTypePresent(SDL_GameControllerType type);
|
|
|
|
|
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
|
|
|
|
2022-09-23 07:15:40 +00:00
|
|
|
/* Return the type of a joystick if it's present and supported */
|
2022-09-23 07:36:46 +00:00
|
|
|
extern SDL_JoystickType HIDAPI_GetJoystickTypeFromGUID(SDL_JoystickGUID guid);
|
2022-09-23 07:15:40 +00:00
|
|
|
|
2022-09-23 06:42:25 +00:00
|
|
|
/* Return the type of a game controller if it's present and supported */
|
|
|
|
extern SDL_GameControllerType HIDAPI_GetGameControllerTypeFromGUID(SDL_JoystickGUID guid);
|
|
|
|
|
2019-12-19 23:01:35 +00:00
|
|
|
extern void HIDAPI_UpdateDevices(void);
|
2022-09-23 01:22:17 +00:00
|
|
|
extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name);
|
|
|
|
extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 product_id);
|
|
|
|
extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial);
|
2022-09-26 21:20:34 +00:00
|
|
|
extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial);
|
|
|
|
extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);
|
2020-11-24 02:24:05 +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);
|
2019-12-19 23:01:30 +00:00
|
|
|
|
2022-09-02 18:37:16 +00:00
|
|
|
extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size);
|
2020-11-06 19:30:52 +00:00
|
|
|
|
2021-01-23 19:21:01 +00:00
|
|
|
extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max);
|
|
|
|
|
2018-08-09 23:00:17 +00:00
|
|
|
#endif /* SDL_JOYSTICK_HIDAPI_H */
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|