Atlas - SDL_hidapijoystick_c.h

Home / ext / SDL / src / joystick / hidapi Lines: 1 | Size: 9669 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2026 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "SDL_internal.h" 22 23#ifndef SDL_JOYSTICK_HIDAPI_H 24#define SDL_JOYSTICK_HIDAPI_H 25 26#include "../usb_ids.h" 27 28// This is the full set of HIDAPI drivers available 29#define SDL_JOYSTICK_HIDAPI_GAMECUBE 30#define SDL_JOYSTICK_HIDAPI_LUNA 31#define SDL_JOYSTICK_HIDAPI_PS3 32#define SDL_JOYSTICK_HIDAPI_PS4 33#define SDL_JOYSTICK_HIDAPI_PS5 34#define SDL_JOYSTICK_HIDAPI_STADIA 35#define SDL_JOYSTICK_HIDAPI_STEAM 36#define SDL_JOYSTICK_HIDAPI_STEAMDECK 37#define SDL_JOYSTICK_HIDAPI_SWITCH 38#ifdef HAVE_LIBUSB 39#define SDL_JOYSTICK_HIDAPI_SWITCH2 40#endif 41#define SDL_JOYSTICK_HIDAPI_WII 42#define SDL_JOYSTICK_HIDAPI_XBOX360 43#define SDL_JOYSTICK_HIDAPI_XBOXONE 44#define SDL_JOYSTICK_HIDAPI_SHIELD 45#define SDL_JOYSTICK_HIDAPI_STEAM_HORI 46#define SDL_JOYSTICK_HIDAPI_STEAM_TRITON 47#define SDL_JOYSTICK_HIDAPI_LG4FF 48#define SDL_JOYSTICK_HIDAPI_8BITDO 49#define SDL_JOYSTICK_HIDAPI_FLYDIGI 50#define SDL_JOYSTICK_HIDAPI_GAMESIR 51#define SDL_JOYSTICK_HIDAPI_GIP 52#define SDL_JOYSTICK_HIDAPI_SINPUT 53#define SDL_JOYSTICK_HIDAPI_ZUIKI 54 55// Joystick capability definitions 56#define SDL_JOYSTICK_CAP_MONO_LED 0x00000001 57#define SDL_JOYSTICK_CAP_RGB_LED 0x00000002 58#define SDL_JOYSTICK_CAP_PLAYER_LED 0x00000004 59#define SDL_JOYSTICK_CAP_RUMBLE 0x00000010 60#define SDL_JOYSTICK_CAP_TRIGGER_RUMBLE 0x00000020 61 62// Whether HIDAPI is enabled by default 63#if defined(SDL_PLATFORM_ANDROID) || \ 64 defined(SDL_PLATFORM_IOS) || \ 65 defined(SDL_PLATFORM_TVOS) || \ 66 defined(SDL_PLATFORM_VISIONOS) 67// On Android, HIDAPI prompts for permissions and acquires exclusive access to the device, and on Apple mobile platforms it doesn't do anything except for handling Bluetooth Steam Controllers, so we'll leave it off by default. 68#define SDL_HIDAPI_DEFAULT false 69#else 70#define SDL_HIDAPI_DEFAULT true 71#endif 72 73// The maximum size of a USB packet for HID devices 74#define USB_PACKET_LENGTH 64 75 76// Forward declaration 77struct SDL_HIDAPI_DeviceDriver; 78 79typedef struct SDL_HIDAPI_Device 80{ 81 char *name; 82 char *manufacturer_string; 83 char *product_string; 84 char *path; 85 Uint16 vendor_id; 86 Uint16 product_id; 87 Uint16 version; 88 char *serial; 89 SDL_GUID guid; 90 int interface_number; // Available on Windows and Linux 91 int interface_class; 92 int interface_subclass; 93 int interface_protocol; 94 Uint16 usage_page; // Available on Windows and macOS 95 Uint16 usage; // Available on Windows and macOS 96 bool is_bluetooth; 97 SDL_JoystickType joystick_type; 98 SDL_GamepadType type; 99 int steam_virtual_gamepad_slot; 100 101 struct SDL_HIDAPI_DeviceDriver *driver; 102 void *context; 103 SDL_hid_device *dev; 104 SDL_AtomicInt rumble_pending; 105 int num_joysticks; 106 SDL_JoystickID *joysticks; 107 108 // Used during scanning for device changes 109 bool seen; 110 111 // Used to flag devices that failed open 112 // This can happen on Windows with Bluetooth devices that have turned off 113 bool broken; 114 115 struct SDL_HIDAPI_Device *parent; 116 int num_children; 117 struct SDL_HIDAPI_Device **children; 118 119 struct SDL_HIDAPI_Device *next; 120} SDL_HIDAPI_Device; 121 122typedef struct SDL_HIDAPI_DeviceDriver 123{ 124 const char *name; 125 bool enabled; 126 void (*RegisterHints)(SDL_HintCallback callback, void *userdata); 127 void (*UnregisterHints)(SDL_HintCallback callback, void *userdata); 128 bool (*IsEnabled)(void); 129 bool (*IsSupportedDevice)(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol); 130 bool (*InitDevice)(SDL_HIDAPI_Device *device); 131 int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id); 132 void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index); 133 bool (*UpdateDevice)(SDL_HIDAPI_Device *device); 134 bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); 135 bool (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); 136 bool (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); 137 Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); 138 bool (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); 139 bool (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size); 140 bool (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled); 141 void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); 142 void (*FreeDevice)(SDL_HIDAPI_Device *device); 143 144} SDL_HIDAPI_DeviceDriver; 145 146// HIDAPI device support 147extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined; 148extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube; 149extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGIP; 150extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons; 151extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna; 152extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic; 153extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3; 154extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty; 155extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3SonySixaxis; 156extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4; 157extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5; 158extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield; 159extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia; 160extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam; 161extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck; 162extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch; 163extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch2; 164extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii; 165extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360; 166extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W; 167extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne; 168extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamHori; 169extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamTriton; 170extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLg4ff; 171extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_Driver8BitDo; 172extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverFlydigi; 173extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameSir; 174extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSInput; 175extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverZUIKI; 176 177#define LOAD16(A, B) (Sint16)((Uint16)(A) | (((Uint16)(B)) << 8)) 178#define LOAD32(A, B, C, D) ((((Uint32)(A)) << 0) | \ 179 (((Uint32)(B)) << 8) | \ 180 (((Uint32)(C)) << 16) | \ 181 (((Uint32)(D)) << 24)) 182 183// Return true if a HID device is present and supported as a joystick of the given type 184extern bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type); 185 186// Return true if a HID device is present and supported as a joystick 187extern bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); 188 189// Return the name of a connected device, which should be freed with SDL_free(), or NULL if it's not available 190extern char *HIDAPI_GetDeviceProductName(Uint16 vendor_id, Uint16 product_id); 191 192// Return the manufacturer of a connected device, which should be freed with SDL_free(), or NULL if it's not available 193extern char *HIDAPI_GetDeviceManufacturerName(Uint16 vendor_id, Uint16 product_id); 194 195// Return the type of a joystick if it's present and supported 196extern SDL_JoystickType HIDAPI_GetJoystickTypeFromGUID(SDL_GUID guid); 197 198// Return the type of a game controller if it's present and supported 199extern SDL_GamepadType HIDAPI_GetGamepadTypeFromGUID(SDL_GUID guid); 200 201extern void HIDAPI_UpdateDevices(void); 202extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name); 203extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 product_id); 204extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial); 205extern bool HIDAPI_HasConnectedUSBDevice(const char *serial); 206extern void HIDAPI_DisconnectBluetoothDevice(const char *serial); 207extern bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID); 208extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID); 209extern void HIDAPI_UpdateDeviceProperties(SDL_HIDAPI_Device *device); 210 211extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size); 212 213extern bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product); 214 215extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max); 216 217#endif // SDL_JOYSTICK_HIDAPI_H 218
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.