2018-08-09 16:00:17 -07:00
|
|
|
/*
|
|
|
|
Simple DirectMedia Layer
|
2022-01-03 09:40:00 -08:00
|
|
|
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
2018-08-09 16:00:17 -07:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
#include "../../SDL_internal.h"
|
|
|
|
|
|
|
|
#ifndef SDL_JOYSTICK_HIDAPI_H
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_H
|
|
|
|
|
2020-02-04 15:26:56 -08:00
|
|
|
#include "SDL_atomic.h"
|
2022-08-19 11:11:23 -07:00
|
|
|
#include "SDL_hints.h"
|
2020-02-04 15:26:56 -08:00
|
|
|
#include "SDL_mutex.h"
|
|
|
|
#include "SDL_joystick.h"
|
|
|
|
#include "SDL_gamecontroller.h"
|
2021-11-07 22:58:44 -08:00
|
|
|
#include "SDL_hidapi.h"
|
2020-01-18 11:21:14 -08:00
|
|
|
#include "../usb_ids.h"
|
2018-08-09 16:00:17 -07:00
|
|
|
|
|
|
|
/* This is the full set of HIDAPI drivers available */
|
2021-01-23 11:06:35 -08:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
|
2021-07-07 06:05:35 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_LUNA
|
2022-08-23 22:45:37 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS3
|
2018-08-09 16:00:17 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS4
|
2020-11-05 17:03:28 -08:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_PS5
|
2021-01-23 11:06:35 -08:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_STADIA
|
2022-11-10 19:16:53 -08:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_STEAM /* Simple support for BLE Steam Controller, hint is disabled by default */
|
2018-08-09 16:00:17 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_SWITCH
|
2022-09-01 15:29:01 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_WII
|
2018-08-09 16:00:17 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_XBOX360
|
|
|
|
#define SDL_JOYSTICK_HIDAPI_XBOXONE
|
2022-07-09 20:55:36 -07:00
|
|
|
#define SDL_JOYSTICK_HIDAPI_SHIELD
|
2018-08-09 16:00:17 -07:00
|
|
|
|
2022-08-19 11:11:23 -07:00
|
|
|
/* Whether HIDAPI is enabled by default */
|
|
|
|
#define SDL_HIDAPI_DEFAULT SDL_TRUE
|
|
|
|
|
2020-02-04 15:26:56 -08:00
|
|
|
/* The maximum size of a USB packet for HID devices */
|
|
|
|
#define USB_PACKET_LENGTH 64
|
|
|
|
|
2019-12-19 15:01:30 -08: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-16 17:36:47 -08:00
|
|
|
char *serial;
|
2019-12-19 15:01:30 -08:00
|
|
|
SDL_JoystickGUID guid;
|
|
|
|
int interface_number; /* Available on Windows and Linux */
|
2020-01-18 11:21:14 -08:00
|
|
|
int interface_class;
|
|
|
|
int interface_subclass;
|
|
|
|
int interface_protocol;
|
2019-12-19 15:01:30 -08:00
|
|
|
Uint16 usage_page; /* Available on Windows and Mac OS X */
|
|
|
|
Uint16 usage; /* Available on Windows and Mac OS X */
|
2022-09-26 14:20:34 -07:00
|
|
|
SDL_bool is_bluetooth;
|
2022-09-23 00:15:40 -07:00
|
|
|
SDL_JoystickType joystick_type;
|
2022-09-22 23:42:25 -07:00
|
|
|
SDL_GameControllerType type;
|
2019-12-19 15:01:30 -08:00
|
|
|
|
|
|
|
struct _SDL_HIDAPI_DeviceDriver *driver;
|
|
|
|
void *context;
|
2020-02-04 15:26:56 -08:00
|
|
|
SDL_mutex *dev_lock;
|
2021-11-07 22:58:44 -08:00
|
|
|
SDL_hid_device *dev;
|
2020-02-04 15:26:56 -08:00
|
|
|
SDL_atomic_t rumble_pending;
|
2019-12-19 15:01:30 -08:00
|
|
|
int num_joysticks;
|
|
|
|
SDL_JoystickID *joysticks;
|
|
|
|
|
|
|
|
/* Used during scanning for device changes */
|
|
|
|
SDL_bool seen;
|
|
|
|
|
2020-12-13 01:20:38 -08:00
|
|
|
/* Used to flag that the device is being updated */
|
|
|
|
SDL_bool updating;
|
|
|
|
|
2022-07-28 19:22:27 -07:00
|
|
|
struct _SDL_HIDAPI_Device *parent;
|
|
|
|
int num_children;
|
|
|
|
struct _SDL_HIDAPI_Device **children;
|
|
|
|
|
2019-12-19 15:01:30 -08:00
|
|
|
struct _SDL_HIDAPI_Device *next;
|
|
|
|
} SDL_HIDAPI_Device;
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
typedef struct _SDL_HIDAPI_DeviceDriver
|
|
|
|
{
|
2022-08-19 11:11:23 -07:00
|
|
|
const char *name;
|
2018-08-09 16:00:17 -07:00
|
|
|
SDL_bool enabled;
|
2022-08-19 11:11:23 -07:00
|
|
|
void (*RegisterHints)(SDL_HintCallback callback, void *userdata);
|
|
|
|
void (*UnregisterHints)(SDL_HintCallback callback, void *userdata);
|
|
|
|
SDL_bool (*IsEnabled)(void);
|
2022-08-30 14:56:11 -07: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 15:01:30 -08:00
|
|
|
SDL_bool (*InitDevice)(SDL_HIDAPI_Device *device);
|
2019-12-20 20:12:03 -08: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 15:01:30 -08:00
|
|
|
SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
|
|
|
|
SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
|
2020-02-04 12:48:53 -08:00
|
|
|
int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
|
2020-11-11 18:57:37 -08:00
|
|
|
int (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
|
2021-11-11 09:13:08 -08:00
|
|
|
Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
|
2020-04-30 08:57:29 -07:00
|
|
|
int (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
|
2021-07-08 13:22:41 -07:00
|
|
|
int (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size);
|
2020-11-17 10:30:20 -08:00
|
|
|
int (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled);
|
2019-12-19 15:01:30 -08:00
|
|
|
void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
|
|
|
|
void (*FreeDevice)(SDL_HIDAPI_Device *device);
|
2018-08-09 16:00:17 -07:00
|
|
|
|
|
|
|
} SDL_HIDAPI_DeviceDriver;
|
|
|
|
|
2020-02-04 12:48:53 -08:00
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
/* HIDAPI device support */
|
2022-07-28 19:22:27 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined;
|
2021-01-23 11:06:35 -08:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
|
2022-08-03 13:07:47 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons;
|
2021-07-07 06:05:35 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;
|
2022-08-03 13:07:47 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic;
|
2022-08-23 22:45:37 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3;
|
2022-09-23 02:39:35 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty;
|
2018-08-09 16:00:17 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
|
2020-11-05 17:03:28 -08:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
|
2022-08-03 13:07:47 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield;
|
2021-01-23 11:06:35 -08:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia;
|
2018-08-09 16:00:17 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
|
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
|
2022-09-01 15:29:01 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii;
|
2018-08-09 16:00:17 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
|
2019-12-19 15:01:32 -08:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
|
2018-08-09 16:00:17 -07:00
|
|
|
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
|
|
|
|
|
2021-07-26 23:29:20 -07: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 16:00:17 -07:00
|
|
|
/* Return true if a HID device is present and supported as a joystick */
|
2019-10-22 10:57:07 -07:00
|
|
|
extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
|
2018-08-09 16:00:17 -07:00
|
|
|
|
2022-09-23 00:15:40 -07:00
|
|
|
/* Return the type of a joystick if it's present and supported */
|
2022-09-23 00:36:46 -07:00
|
|
|
extern SDL_JoystickType HIDAPI_GetJoystickTypeFromGUID(SDL_JoystickGUID guid);
|
2022-09-23 00:15:40 -07:00
|
|
|
|
2022-09-22 23:42:25 -07: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 15:01:35 -08:00
|
|
|
extern void HIDAPI_UpdateDevices(void);
|
2022-09-22 18:22:17 -07: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 14:20:34 -07:00
|
|
|
extern SDL_bool HIDAPI_HasConnectedUSBDevice(const char *serial);
|
|
|
|
extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);
|
2020-11-23 18:24:05 -08: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 15:01:30 -08:00
|
|
|
|
2022-09-02 11:37:16 -07:00
|
|
|
extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size);
|
2020-11-06 11:30:52 -08:00
|
|
|
|
2021-01-23 11:21:01 -08:00
|
|
|
extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max);
|
|
|
|
|
2018-08-09 16:00:17 -07:00
|
|
|
#endif /* SDL_JOYSTICK_HIDAPI_H */
|
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|