Path: blob/master/thirdparty/sdl/joystick/SDL_sysjoystick.h
9903 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122#ifndef SDL_sysjoystick_h_23#define SDL_sysjoystick_h_2425// This is the system specific header for the SDL joystick API26#include "SDL_joystick_c.h"2728#include <stdlib.h>2930// Set up for C function definitions, even when using C++31#ifdef __cplusplus32extern "C" {33#endif3435// The SDL joystick structure3637typedef struct SDL_JoystickAxisInfo38{39Sint16 initial_value; // Initial axis state40Sint16 value; // Current axis state41Sint16 zero; // Zero point on the axis (-32768 for triggers)42bool has_initial_value; // Whether we've seen a value on the axis yet43bool has_second_value; // Whether we've seen a second value on the axis yet44bool sent_initial_value; // Whether we've sent the initial axis value45bool sending_initial_value; // Whether we are sending the initial axis value46} SDL_JoystickAxisInfo;4748typedef struct SDL_JoystickBallData49{50int dx;51int dy;52} SDL_JoystickBallData;5354typedef struct SDL_JoystickTouchpadFingerInfo55{56bool down;57float x;58float y;59float pressure;60} SDL_JoystickTouchpadFingerInfo;6162typedef struct SDL_JoystickTouchpadInfo63{64int nfingers;65SDL_JoystickTouchpadFingerInfo *fingers;66} SDL_JoystickTouchpadInfo;6768typedef struct SDL_JoystickSensorInfo69{70SDL_SensorType type;71bool enabled;72float rate;73float data[3]; // If this needs to expand, update SDL_GamepadSensorEvent74} SDL_JoystickSensorInfo;7576#define _guarded SDL_GUARDED_BY(SDL_joystick_lock)7778struct SDL_Joystick79{80SDL_JoystickID instance_id _guarded; // Device instance, monotonically increasing from 081char *name _guarded; // Joystick name - system dependent82char *path _guarded; // Joystick path - system dependent83char *serial _guarded; // Joystick serial84SDL_GUID guid _guarded; // Joystick guid85Uint16 firmware_version _guarded; // Firmware version, if available86Uint64 steam_handle _guarded; // Steam controller API handle87bool swap_face_buttons _guarded; // Whether we should swap face buttons88bool is_virtual _guarded; // Whether this is a virtual joystick8990int naxes _guarded; // Number of axis controls on the joystick91SDL_JoystickAxisInfo *axes _guarded;9293int nballs _guarded; // Number of trackballs on the joystick94SDL_JoystickBallData *balls _guarded; // Current ball motion deltas9596int nhats _guarded; // Number of hats on the joystick97Uint8 *hats _guarded; // Current hat states9899int nbuttons _guarded; // Number of buttons on the joystick100bool *buttons _guarded; // Current button states101102int ntouchpads _guarded; // Number of touchpads on the joystick103SDL_JoystickTouchpadInfo *touchpads _guarded; // Current touchpad states104105int nsensors _guarded; // Number of sensors on the joystick106int nsensors_enabled _guarded;107SDL_JoystickSensorInfo *sensors _guarded;108109Uint16 low_frequency_rumble _guarded;110Uint16 high_frequency_rumble _guarded;111Uint64 rumble_expiration _guarded;112Uint64 rumble_resend _guarded;113114Uint16 left_trigger_rumble _guarded;115Uint16 right_trigger_rumble _guarded;116Uint64 trigger_rumble_expiration _guarded;117Uint64 trigger_rumble_resend _guarded;118119Uint8 led_red _guarded;120Uint8 led_green _guarded;121Uint8 led_blue _guarded;122Uint64 led_expiration _guarded;123124bool attached _guarded;125SDL_JoystickConnectionState connection_state _guarded;126SDL_PowerState battery_state _guarded;127int battery_percent _guarded;128129bool delayed_guide_button _guarded; // true if this device has the guide button event delayed130131SDL_SensorID accel_sensor _guarded;132SDL_Sensor *accel _guarded;133SDL_SensorID gyro_sensor _guarded;134SDL_Sensor *gyro _guarded;135float sensor_transform[3][3] _guarded;136137Uint64 update_complete _guarded;138139struct SDL_JoystickDriver *driver _guarded;140141struct joystick_hwdata *hwdata _guarded; // Driver dependent information142143SDL_PropertiesID props _guarded;144145int ref_count _guarded; // Reference count for multiple opens146147struct SDL_Joystick *next _guarded; // pointer to next joystick we have allocated148};149150#undef _guarded151152// Device bus definitions153#define SDL_HARDWARE_BUS_UNKNOWN 0x00154#define SDL_HARDWARE_BUS_USB 0x03155#define SDL_HARDWARE_BUS_BLUETOOTH 0x05156#define SDL_HARDWARE_BUS_VIRTUAL 0xFF157158// Macro to combine a USB vendor ID and product ID into a single Uint32 value159#define MAKE_VIDPID(VID, PID) (((Uint32)(VID)) << 16 | (PID))160161typedef struct SDL_JoystickDriver162{163/* Function to scan the system for joysticks.164* Joystick 0 should be the system default joystick.165* This function should return 0, or -1 on an unrecoverable error.166*/167bool (*Init)(void);168169// Function to return the number of joystick devices plugged in right now170int (*GetCount)(void);171172// Function to cause any queued joystick insertions to be processed173void (*Detect)(void);174175// Function to determine whether a device is currently detected by this driver176bool (*IsDevicePresent)(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);177178// Function to get the device-dependent name of a joystick179const char *(*GetDeviceName)(int device_index);180181// Function to get the device-dependent path of a joystick182const char *(*GetDevicePath)(int device_index);183184// Function to get the Steam virtual gamepad slot of a joystick185int (*GetDeviceSteamVirtualGamepadSlot)(int device_index);186187// Function to get the player index of a joystick188int (*GetDevicePlayerIndex)(int device_index);189190// Function to set the player index of a joystick191void (*SetDevicePlayerIndex)(int device_index, int player_index);192193// Function to return the stable GUID for a plugged in device194SDL_GUID (*GetDeviceGUID)(int device_index);195196// Function to get the current instance id of the joystick located at device_index197SDL_JoystickID (*GetDeviceInstanceID)(int device_index);198199/* Function to open a joystick for use.200The joystick to open is specified by the device index.201This should fill the nbuttons and naxes fields of the joystick structure.202It returns 0, or -1 if there is an error.203*/204bool (*Open)(SDL_Joystick *joystick, int device_index);205206// Rumble functionality207bool (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);208bool (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);209210// LED functionality211bool (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);212213// General effects214bool (*SendEffect)(SDL_Joystick *joystick, const void *data, int size);215216// Sensor functionality217bool (*SetSensorsEnabled)(SDL_Joystick *joystick, bool enabled);218219/* Function to update the state of a joystick - called as a device poll.220* This function shouldn't update the joystick structure directly,221* but instead should call SDL_PrivateJoystick*() to deliver events222* and update joystick device state.223*/224void (*Update)(SDL_Joystick *joystick);225226// Function to close a joystick after use227void (*Close)(SDL_Joystick *joystick);228229// Function to perform any system-specific joystick related cleanup230void (*Quit)(void);231232// Function to get the autodetected controller mapping; returns false if there isn't any.233bool (*GetGamepadMapping)(int device_index, SDL_GamepadMapping *out);234235} SDL_JoystickDriver;236237// Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF238#define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF239240/* Dualshock4 only rumbles for about 5 seconds max, resend rumble command every 2 seconds241* to make long rumble work. */242#define SDL_RUMBLE_RESEND_MS 2000243244#define SDL_LED_MIN_REPEAT_MS 5000245246// The available joystick drivers247extern SDL_JoystickDriver SDL_PRIVATE_JoystickDriver;248extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;249extern SDL_JoystickDriver SDL_BSD_JoystickDriver;250extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;251extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;252extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;253extern SDL_JoystickDriver SDL_HAIKU_JoystickDriver;254extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver;255extern SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver;256extern SDL_JoystickDriver SDL_IOS_JoystickDriver;257extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;258extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;259extern SDL_JoystickDriver SDL_WGI_JoystickDriver;260extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;261extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;262extern SDL_JoystickDriver SDL_PS2_JoystickDriver;263extern SDL_JoystickDriver SDL_PSP_JoystickDriver;264extern SDL_JoystickDriver SDL_VITA_JoystickDriver;265extern SDL_JoystickDriver SDL_N3DS_JoystickDriver;266extern SDL_JoystickDriver SDL_GAMEINPUT_JoystickDriver;267268// Ends C function definitions when using C++269#ifdef __cplusplus270}271#endif272273#endif // SDL_sysjoystick_h_274275276