Atlas - SDL_sysjoystick.h
Home / ext / SDL / src / joystick Lines: 1 | Size: 10078 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_sysjoystick_h_ 24#define SDL_sysjoystick_h_ 25 26// This is the system specific header for the SDL joystick API 27#include "SDL_joystick_c.h" 28 29// Set up for C function definitions, even when using C++ 30#ifdef __cplusplus 31extern "C" { 32#endif 33 34// The SDL joystick structure 35 36typedef struct SDL_JoystickAxisInfo 37{ 38 Sint16 initial_value; // Initial axis state 39 Sint16 value; // Current axis state 40 Sint16 zero; // Zero point on the axis (-32768 for triggers) 41 bool has_initial_value; // Whether we've seen a value on the axis yet 42 bool has_second_value; // Whether we've seen a second value on the axis yet 43 bool sent_initial_value; // Whether we've sent the initial axis value 44 bool sending_initial_value; // Whether we are sending the initial axis value 45} SDL_JoystickAxisInfo; 46 47typedef struct SDL_JoystickBallData 48{ 49 int dx; 50 int dy; 51} SDL_JoystickBallData; 52 53typedef struct SDL_JoystickTouchpadFingerInfo 54{ 55 bool down; 56 float x; 57 float y; 58 float pressure; 59} SDL_JoystickTouchpadFingerInfo; 60 61typedef struct SDL_JoystickTouchpadInfo 62{ 63 int nfingers; 64 SDL_JoystickTouchpadFingerInfo *fingers; 65} SDL_JoystickTouchpadInfo; 66 67typedef struct SDL_JoystickSensorInfo 68{ 69 SDL_SensorType type; 70 bool enabled; 71 float rate; 72 float data[3]; // If this needs to expand, update SDL_GamepadSensorEvent 73} SDL_JoystickSensorInfo; 74 75#define _guarded SDL_GUARDED_BY(SDL_joystick_lock) 76 77struct SDL_Joystick 78{ 79 SDL_JoystickID instance_id _guarded; // Device instance, monotonically increasing from 0 80 char *name _guarded; // Joystick name - system dependent 81 char *path _guarded; // Joystick path - system dependent 82 char *serial _guarded; // Joystick serial 83 SDL_GUID guid _guarded; // Joystick guid 84 Uint16 firmware_version _guarded; // Firmware version, if available 85 Uint64 steam_handle _guarded; // Steam controller API handle 86 bool swap_face_buttons _guarded; // Whether we should swap face buttons 87 bool is_virtual _guarded; // Whether this is a virtual joystick 88 89 int naxes _guarded; // Number of axis controls on the joystick 90 SDL_JoystickAxisInfo *axes _guarded; 91 92 int nballs _guarded; // Number of trackballs on the joystick 93 SDL_JoystickBallData *balls _guarded; // Current ball motion deltas 94 95 int nhats _guarded; // Number of hats on the joystick 96 Uint8 *hats _guarded; // Current hat states 97 98 int nbuttons _guarded; // Number of buttons on the joystick 99 bool *buttons _guarded; // Current button states 100 101 int ntouchpads _guarded; // Number of touchpads on the joystick 102 SDL_JoystickTouchpadInfo *touchpads _guarded; // Current touchpad states 103 104 int nsensors _guarded; // Number of sensors on the joystick 105 int nsensors_enabled _guarded; 106 SDL_JoystickSensorInfo *sensors _guarded; 107 108 Uint16 low_frequency_rumble _guarded; 109 Uint16 high_frequency_rumble _guarded; 110 Uint64 rumble_expiration _guarded; 111 Uint64 rumble_resend _guarded; 112 113 Uint16 left_trigger_rumble _guarded; 114 Uint16 right_trigger_rumble _guarded; 115 Uint64 trigger_rumble_expiration _guarded; 116 Uint64 trigger_rumble_resend _guarded; 117 118 Uint8 led_red _guarded; 119 Uint8 led_green _guarded; 120 Uint8 led_blue _guarded; 121 Uint64 led_expiration _guarded; 122 123 bool attached _guarded; 124 SDL_JoystickConnectionState connection_state _guarded; 125 SDL_PowerState battery_state _guarded; 126 int battery_percent _guarded; 127 128 bool delayed_guide_button _guarded; // true if this device has the guide button event delayed 129 130 SDL_SensorID accel_sensor _guarded; 131 SDL_Sensor *accel _guarded; 132 SDL_SensorID gyro_sensor _guarded; 133 SDL_Sensor *gyro _guarded; 134 float sensor_transform[3][3] _guarded; 135 136 Uint64 update_complete _guarded; 137 138 struct SDL_JoystickDriver *driver _guarded; 139 140 struct joystick_hwdata *hwdata _guarded; // Driver dependent information 141 142 SDL_PropertiesID props _guarded; 143 144 int ref_count _guarded; // Reference count for multiple opens 145 146 struct SDL_Joystick *next _guarded; // pointer to next joystick we have allocated 147}; 148 149#undef _guarded 150 151// Device bus definitions 152#define SDL_HARDWARE_BUS_UNKNOWN 0x00 153#define SDL_HARDWARE_BUS_USB 0x03 154#define SDL_HARDWARE_BUS_BLUETOOTH 0x05 155#define SDL_HARDWARE_BUS_VIRTUAL 0xFF 156 157// Macro to combine a USB vendor ID and product ID into a single Uint32 value 158#define MAKE_VIDPID(VID, PID) (((Uint32)(VID)) << 16 | (PID)) 159 160typedef struct SDL_JoystickDriver 161{ 162 /* Function to scan the system for joysticks. 163 * Joystick 0 should be the system default joystick. 164 * This function should return 0, or -1 on an unrecoverable error. 165 */ 166 bool (*Init)(void); 167 168 // Function to return the number of joystick devices plugged in right now 169 int (*GetCount)(void); 170 171 // Function to cause any queued joystick insertions to be processed 172 void (*Detect)(void); 173 174 // Function to determine whether a device is currently detected by this driver 175 bool (*IsDevicePresent)(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); 176 177 // Function to get the device-dependent name of a joystick 178 const char *(*GetDeviceName)(int device_index); 179 180 // Function to get the device-dependent path of a joystick 181 const char *(*GetDevicePath)(int device_index); 182 183 // Function to get the Steam virtual gamepad slot of a joystick 184 int (*GetDeviceSteamVirtualGamepadSlot)(int device_index); 185 186 // Function to get the player index of a joystick 187 int (*GetDevicePlayerIndex)(int device_index); 188 189 // Function to set the player index of a joystick 190 void (*SetDevicePlayerIndex)(int device_index, int player_index); 191 192 // Function to return the stable GUID for a plugged in device 193 SDL_GUID (*GetDeviceGUID)(int device_index); 194 195 // Function to get the current instance id of the joystick located at device_index 196 SDL_JoystickID (*GetDeviceInstanceID)(int device_index); 197 198 /* Function to open a joystick for use. 199 The joystick to open is specified by the device index. 200 This should fill the nbuttons and naxes fields of the joystick structure. 201 It returns 0, or -1 if there is an error. 202 */ 203 bool (*Open)(SDL_Joystick *joystick, int device_index); 204 205 // Rumble functionality 206 bool (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); 207 bool (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); 208 209 // LED functionality 210 bool (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); 211 212 // General effects 213 bool (*SendEffect)(SDL_Joystick *joystick, const void *data, int size); 214 215 // Sensor functionality 216 bool (*SetSensorsEnabled)(SDL_Joystick *joystick, bool enabled); 217 218 /* Function to update the state of a joystick - called as a device poll. 219 * This function shouldn't update the joystick structure directly, 220 * but instead should call SDL_PrivateJoystick*() to deliver events 221 * and update joystick device state. 222 */ 223 void (*Update)(SDL_Joystick *joystick); 224 225 // Function to close a joystick after use 226 void (*Close)(SDL_Joystick *joystick); 227 228 // Function to perform any system-specific joystick related cleanup 229 void (*Quit)(void); 230 231 // Function to get the autodetected controller mapping; returns false if there isn't any. 232 bool (*GetGamepadMapping)(int device_index, SDL_GamepadMapping *out); 233 234} SDL_JoystickDriver; 235 236// Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF 237#define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF 238 239/* Dualshock4 only rumbles for about 5 seconds max, resend rumble command every 2 seconds 240 * to make long rumble work. */ 241#define SDL_RUMBLE_RESEND_MS 2000 242 243#define SDL_LED_MIN_REPEAT_MS 5000 244 245// The available joystick drivers 246extern SDL_JoystickDriver SDL_PRIVATE_JoystickDriver; 247extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver; 248extern SDL_JoystickDriver SDL_BSD_JoystickDriver; 249extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver; 250extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver; 251extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver; 252extern SDL_JoystickDriver SDL_HAIKU_JoystickDriver; 253extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver; 254extern SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver; 255extern SDL_JoystickDriver SDL_IOS_JoystickDriver; 256extern SDL_JoystickDriver SDL_LINUX_JoystickDriver; 257extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver; 258extern SDL_JoystickDriver SDL_WGI_JoystickDriver; 259extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver; 260extern SDL_JoystickDriver SDL_WINMM_JoystickDriver; 261extern SDL_JoystickDriver SDL_PS2_JoystickDriver; 262extern SDL_JoystickDriver SDL_PSP_JoystickDriver; 263extern SDL_JoystickDriver SDL_VITA_JoystickDriver; 264extern SDL_JoystickDriver SDL_N3DS_JoystickDriver; 265extern SDL_JoystickDriver SDL_GAMEINPUT_JoystickDriver; 266 267// Ends C function definitions when using C++ 268#ifdef __cplusplus 269} 270#endif 271 272#endif // SDL_sysjoystick_h_ 273[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.