Atlas - SDL_hidapijoystick_c.h

Home / ext / SDL / src / joystick / hidapi Lines: 1 | Size: 9388 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 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_GIP 51#define SDL_JOYSTICK_HIDAPI_SINPUT 52#define SDL_JOYSTICK_HIDAPI_ZUIKI 53 54// Joystick capability definitions 55#define SDL_JOYSTICK_CAP_MONO_LED 0x00000001 56#define SDL_JOYSTICK_CAP_RGB_LED 0x00000002 57#define SDL_JOYSTICK_CAP_PLAYER_LED 0x00000004 58#define SDL_JOYSTICK_CAP_RUMBLE 0x00000010 59#define SDL_JOYSTICK_CAP_TRIGGER_RUMBLE 0x00000020 60 61// Whether HIDAPI is enabled by default 62#if defined(SDL_PLATFORM_ANDROID) || \ 63 defined(SDL_PLATFORM_IOS) || \ 64 defined(SDL_PLATFORM_TVOS) || \ 65 defined(SDL_PLATFORM_VISIONOS) 66// 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. 67#define SDL_HIDAPI_DEFAULT false 68#else 69#define SDL_HIDAPI_DEFAULT true 70#endif 71 72// The maximum size of a USB packet for HID devices 73#define USB_PACKET_LENGTH 64 74 75// Forward declaration 76struct SDL_HIDAPI_DeviceDriver; 77 78typedef struct SDL_HIDAPI_Device 79{ 80 char *name; 81 char *manufacturer_string; 82 char *product_string; 83 char *path; 84 Uint16 vendor_id; 85 Uint16 product_id; 86 Uint16 version; 87 char *serial; 88 SDL_GUID guid; 89 int interface_number; // Available on Windows and Linux 90 int interface_class; 91 int interface_subclass; 92 int interface_protocol; 93 Uint16 usage_page; // Available on Windows and macOS 94 Uint16 usage; // Available on Windows and macOS 95 bool is_bluetooth; 96 SDL_JoystickType joystick_type; 97 SDL_GamepadType type; 98 int steam_virtual_gamepad_slot; 99 100 struct SDL_HIDAPI_DeviceDriver *driver; 101 void *context; 102 SDL_Mutex *dev_lock; 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 that the device is being updated 112 bool updating; 113 114 // Used to flag devices that failed open 115 // This can happen on Windows with Bluetooth devices that have turned off 116 bool broken; 117 118 struct SDL_HIDAPI_Device *parent; 119 int num_children; 120 struct SDL_HIDAPI_Device **children; 121 122 struct SDL_HIDAPI_Device *next; 123} SDL_HIDAPI_Device; 124 125typedef struct SDL_HIDAPI_DeviceDriver 126{ 127 const char *name; 128 bool enabled; 129 void (*RegisterHints)(SDL_HintCallback callback, void *userdata); 130 void (*UnregisterHints)(SDL_HintCallback callback, void *userdata); 131 bool (*IsEnabled)(void); 132 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); 133 bool (*InitDevice)(SDL_HIDAPI_Device *device); 134 int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id); 135 void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index); 136 bool (*UpdateDevice)(SDL_HIDAPI_Device *device); 137 bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); 138 bool (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); 139 bool (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); 140 Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); 141 bool (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); 142 bool (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size); 143 bool (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled); 144 void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); 145 void (*FreeDevice)(SDL_HIDAPI_Device *device); 146 147} SDL_HIDAPI_DeviceDriver; 148 149// HIDAPI device support 150extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined; 151extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube; 152extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGIP; 153extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons; 154extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna; 155extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic; 156extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3; 157extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty; 158extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3SonySixaxis; 159extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4; 160extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5; 161extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield; 162extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia; 163extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam; 164extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck; 165extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch; 166extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch2; 167extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii; 168extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360; 169extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W; 170extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne; 171extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamHori; 172extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamTriton; 173extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLg4ff; 174extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_Driver8BitDo; 175extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverFlydigi; 176extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSInput; 177extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverZUIKI; 178 179// Return true if a HID device is present and supported as a joystick of the given type 180extern bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type); 181 182// Return true if a HID device is present and supported as a joystick 183extern bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); 184 185// Return the name of a connected device, which should be freed with SDL_free(), or NULL if it's not available 186extern char *HIDAPI_GetDeviceProductName(Uint16 vendor_id, Uint16 product_id); 187 188// Return the manufacturer of a connected device, which should be freed with SDL_free(), or NULL if it's not available 189extern char *HIDAPI_GetDeviceManufacturerName(Uint16 vendor_id, Uint16 product_id); 190 191// Return the type of a joystick if it's present and supported 192extern SDL_JoystickType HIDAPI_GetJoystickTypeFromGUID(SDL_GUID guid); 193 194// Return the type of a game controller if it's present and supported 195extern SDL_GamepadType HIDAPI_GetGamepadTypeFromGUID(SDL_GUID guid); 196 197extern void HIDAPI_UpdateDevices(void); 198extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name); 199extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 product_id); 200extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial); 201extern bool HIDAPI_HasConnectedUSBDevice(const char *serial); 202extern void HIDAPI_DisconnectBluetoothDevice(const char *serial); 203extern bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID); 204extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID); 205extern void HIDAPI_UpdateDeviceProperties(SDL_HIDAPI_Device *device); 206 207extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size); 208 209extern bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product); 210 211extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max); 212 213#endif // SDL_JOYSTICK_HIDAPI_H 214
[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.