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