| 1 | /* |
| 2 | Simple DirectMedia Layer |
| 3 | Copyright (C) 1997-2025 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 | |
| 22 | #ifndef SDL_sysjoystick_c_h_ |
| 23 | #define SDL_sysjoystick_c_h_ |
| 24 | |
| 25 | #include <linux/input.h> |
| 26 | |
| 27 | struct SDL_joylist_item; |
| 28 | struct SDL_sensorlist_item; |
| 29 | |
| 30 | // The private structure used to keep track of a joystick |
| 31 | struct joystick_hwdata |
| 32 | { |
| 33 | int fd; |
| 34 | // linux driver creates a separate device for gyro/accelerometer |
| 35 | int fd_sensor; |
| 36 | struct SDL_joylist_item *item; |
| 37 | struct SDL_sensorlist_item *item_sensor; |
| 38 | SDL_GUID guid; |
| 39 | char *fname; // Used in haptic subsystem |
| 40 | |
| 41 | bool ff_rumble; |
| 42 | bool ff_sine; |
| 43 | struct ff_effect effect; |
| 44 | Uint32 effect_expiration; |
| 45 | |
| 46 | // The current Linux joystick driver maps balls to two axes |
| 47 | struct hwdata_ball |
| 48 | { |
| 49 | int axis[2]; |
| 50 | } *balls; |
| 51 | |
| 52 | // The current Linux joystick driver maps hats to two axes |
| 53 | struct hwdata_hat |
| 54 | { |
| 55 | int axis[2]; |
| 56 | } *hats; |
| 57 | |
| 58 | // Support for the Linux 2.4 unified input interface |
| 59 | Uint8 key_map[KEY_MAX]; |
| 60 | Uint8 abs_map[ABS_MAX]; |
| 61 | bool has_key[KEY_MAX]; |
| 62 | bool has_abs[ABS_MAX]; |
| 63 | bool has_accelerometer; |
| 64 | bool has_gyro; |
| 65 | |
| 66 | // Support for the classic joystick interface |
| 67 | bool classic; |
| 68 | Uint16 *key_pam; |
| 69 | Uint8 *abs_pam; |
| 70 | |
| 71 | struct axis_correct |
| 72 | { |
| 73 | bool use_deadzones; |
| 74 | |
| 75 | // Deadzone coefficients |
| 76 | int coef[3]; |
| 77 | |
| 78 | // Raw coordinate scale |
| 79 | int minimum; |
| 80 | int maximum; |
| 81 | float scale; |
| 82 | } abs_correct[ABS_MAX]; |
| 83 | |
| 84 | float accelerometer_scale[3]; |
| 85 | float gyro_scale[3]; |
| 86 | |
| 87 | /* Each axis is read independently, if we don't get all axis this call to |
| 88 | * LINUX_JoystickUpdateupdate(), store them for the next one */ |
| 89 | float gyro_data[3]; |
| 90 | float accel_data[3]; |
| 91 | Uint64 sensor_tick; |
| 92 | Sint32 last_tick; |
| 93 | |
| 94 | bool report_sensor; |
| 95 | bool fresh; |
| 96 | bool recovering_from_dropped; |
| 97 | bool recovering_from_dropped_sensor; |
| 98 | |
| 99 | // Steam Controller support |
| 100 | bool m_bSteamController; |
| 101 | |
| 102 | // 4 = (ABS_HAT3X-ABS_HAT0X)/2 (see input-event-codes.h in kernel) |
| 103 | int hats_indices[4]; |
| 104 | bool has_hat[4]; |
| 105 | struct hat_axis_correct |
| 106 | { |
| 107 | bool use_deadzones; |
| 108 | int minimum[2]; |
| 109 | int maximum[2]; |
| 110 | } hat_correct[4]; |
| 111 | |
| 112 | // Set when gamepad is pending removal due to ENODEV read error |
| 113 | bool gone; |
| 114 | bool sensor_gone; |
| 115 | }; |
| 116 | |
| 117 | #endif // SDL_sysjoystick_c_h_ |
| 118 | |