1 /* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org> 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.h" 28 #include "SDL_joystick_c.h" 29 30 /* The SDL joystick structure */ 31 typedef struct _SDL_JoystickAxisInfo 32 { 33 Sint16 initial_value; /* Initial axis state */ 34 Sint16 value; /* Current axis state */ 35 Sint16 zero; /* Zero point on the axis (-32768 for triggers) */ 36 SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */ 37 SDL_bool has_second_value; /* Whether we've seen a second value on the axis yet */ 38 SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */ 39 SDL_bool sending_initial_value; /* Whether we are sending the initial axis value */ 40 } SDL_JoystickAxisInfo; 41 42 typedef struct _SDL_JoystickTouchpadFingerInfo 43 { 44 Uint8 state; 45 float x; 46 float y; 47 float pressure; 48 } SDL_JoystickTouchpadFingerInfo; 49 50 typedef struct _SDL_JoystickTouchpadInfo 51 { 52 int nfingers; 53 SDL_JoystickTouchpadFingerInfo *fingers; 54 } SDL_JoystickTouchpadInfo; 55 56 typedef struct _SDL_JoystickSensorInfo 57 { 58 SDL_SensorType type; 59 SDL_bool enabled; 60 float rate; 61 float data[3]; /* If this needs to expand, update SDL_ControllerSensorEvent */ 62 } SDL_JoystickSensorInfo; 63 64 struct _SDL_Joystick 65 { 66 SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */ 67 char *name; /* Joystick name - system dependent */ 68 char *serial; /* Joystick serial */ 69 SDL_JoystickGUID guid; /* Joystick guid */ 70 71 int naxes; /* Number of axis controls on the joystick */ 72 SDL_JoystickAxisInfo *axes; 73 74 int nhats; /* Number of hats on the joystick */ 75 Uint8 *hats; /* Current hat states */ 76 77 int nballs; /* Number of trackballs on the joystick */ 78 struct balldelta { 79 int dx; 80 int dy; 81 } *balls; /* Current ball motion deltas */ 82 83 int nbuttons; /* Number of buttons on the joystick */ 84 Uint8 *buttons; /* Current button states */ 85 86 int ntouchpads; /* Number of touchpads on the joystick */ 87 SDL_JoystickTouchpadInfo *touchpads; /* Current touchpad states */ 88 89 int nsensors; /* Number of sensors on the joystick */ 90 int nsensors_enabled; 91 SDL_JoystickSensorInfo *sensors; 92 93 Uint16 low_frequency_rumble; 94 Uint16 high_frequency_rumble; 95 Uint32 rumble_expiration; 96 97 Uint16 left_trigger_rumble; 98 Uint16 right_trigger_rumble; 99 Uint32 trigger_rumble_expiration; 100 101 Uint8 led_red; 102 Uint8 led_green; 103 Uint8 led_blue; 104 Uint32 led_expiration; 105 106 SDL_bool attached; 107 SDL_bool is_game_controller; 108 SDL_bool delayed_guide_button; /* SDL_TRUE if this device has the guide button event delayed */ 109 SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */ 110 111 struct _SDL_JoystickDriver *driver; 112 113 struct joystick_hwdata *hwdata; /* Driver dependent information */ 114 115 int ref_count; /* Reference count for multiple opens */ 116 117 struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */ 118 }; 119 120 /* Device bus definitions */ 121 #define SDL_HARDWARE_BUS_USB 0x03 122 #define SDL_HARDWARE_BUS_BLUETOOTH 0x05 123 124 /* Joystick capability flags for GetCapabilities() */ 125 #define SDL_JOYCAP_LED 0x01 126 #define SDL_JOYCAP_RUMBLE 0x02 127 #define SDL_JOYCAP_RUMBLE_TRIGGERS 0x04 128 129 /* Macro to combine a USB vendor ID and product ID into a single Uint32 value */ 130 #define MAKE_VIDPID(VID, PID) (((Uint32)(VID))<<16|(PID)) 131 132 typedef struct _SDL_JoystickDriver 133 { 134 /* Function to scan the system for joysticks. 135 * Joystick 0 should be the system default joystick. 136 * This function should return 0, or -1 on an unrecoverable error. 137 */ 138 int (*Init)(void); 139 140 /* Function to return the number of joystick devices plugged in right now */ 141 int (*GetCount)(void); 142 143 /* Function to cause any queued joystick insertions to be processed */ 144 void (*Detect)(void); 145 146 /* Function to get the device-dependent name of a joystick */ 147 const char *(*GetDeviceName)(int device_index); 148 149 /* Function to get the player index of a joystick */ 150 int (*GetDevicePlayerIndex)(int device_index); 151 152 /* Function to get the player index of a joystick */ 153 void (*SetDevicePlayerIndex)(int device_index, int player_index); 154 155 /* Function to return the stable GUID for a plugged in device */ 156 SDL_JoystickGUID (*GetDeviceGUID)(int device_index); 157 158 /* Function to get the current instance id of the joystick located at device_index */ 159 SDL_JoystickID (*GetDeviceInstanceID)(int device_index); 160 161 /* Function to open a joystick for use. 162 The joystick to open is specified by the device index. 163 This should fill the nbuttons and naxes fields of the joystick structure. 164 It returns 0, or -1 if there is an error. 165 */ 166 int (*Open)(SDL_Joystick *joystick, int device_index); 167 168 /* Rumble functionality */ 169 int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); 170 int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); 171 172 /* Capability detection */ 173 Uint32 (*GetCapabilities)(SDL_Joystick *joystick); 174 175 /* LED functionality */ 176 int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); 177 178 /* General effects */ 179 int (*SendEffect)(SDL_Joystick *joystick, const void *data, int size); 180 181 /* Sensor functionality */ 182 int (*SetSensorsEnabled)(SDL_Joystick *joystick, SDL_bool enabled); 183 184 /* Function to update the state of a joystick - called as a device poll. 185 * This function shouldn't update the joystick structure directly, 186 * but instead should call SDL_PrivateJoystick*() to deliver events 187 * and update joystick device state. 188 */ 189 void (*Update)(SDL_Joystick *joystick); 190 191 /* Function to close a joystick after use */ 192 void (*Close)(SDL_Joystick *joystick); 193 194 /* Function to perform any system-specific joystick related cleanup */ 195 void (*Quit)(void); 196 197 /* Function to get the autodetected controller mapping; returns false if there isn't any. */ 198 SDL_bool (*GetGamepadMapping)(int device_index, SDL_GamepadMapping * out); 199 200 } SDL_JoystickDriver; 201 202 /* Windows and Mac OSX has a limit of MAX_DWORD / 1000, Linux kernel has a limit of 0xFFFF */ 203 #define SDL_MAX_RUMBLE_DURATION_MS 0xFFFF 204 205 #define SDL_LED_MIN_REPEAT_MS 5000 206 207 /* The available joystick drivers */ 208 extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver; 209 extern SDL_JoystickDriver SDL_BSD_JoystickDriver; 210 extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver; 211 extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver; 212 extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver; 213 extern SDL_JoystickDriver SDL_HAIKU_JoystickDriver; 214 extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver; 215 extern SDL_JoystickDriver SDL_RAWINPUT_JoystickDriver; 216 extern SDL_JoystickDriver SDL_IOS_JoystickDriver; 217 extern SDL_JoystickDriver SDL_LINUX_JoystickDriver; 218 extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver; 219 extern SDL_JoystickDriver SDL_WGI_JoystickDriver; 220 extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver; 221 extern SDL_JoystickDriver SDL_WINMM_JoystickDriver; 222 extern SDL_JoystickDriver SDL_OS2_JoystickDriver; 223 extern SDL_JoystickDriver SDL_PSP_JoystickDriver; 224 extern SDL_JoystickDriver SDL_VITA_JoystickDriver; 225 226 #endif /* SDL_sysjoystick_h_ */ 227 228 /* vi: set ts=4 sw=4 expandtab: */ 229