1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2020 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_joystick_c_h_
23 #define SDL_joystick_c_h_
24 
25 #include "../SDL_internal.h"
26 
27 /* Useful functions and variables from SDL_joystick.c */
28 #include "SDL_gamecontroller.h"
29 #include "SDL_joystick.h"
30 
31 struct _SDL_JoystickDriver;
32 
33 /* Initialization and shutdown functions */
34 extern int SDL_JoystickInit(void);
35 extern void SDL_JoystickQuit(void);
36 
37 /* Function to get the next available joystick instance ID */
38 extern SDL_JoystickID SDL_GetNextJoystickInstanceID(void);
39 
40 /* Initialization and shutdown functions */
41 extern int SDL_GameControllerInitMappings(void);
42 extern void SDL_GameControllerQuitMappings(void);
43 extern int SDL_GameControllerInit(void);
44 extern void SDL_GameControllerQuit(void);
45 
46 /* Function to get the joystick driver and device index for an API device index */
47 extern SDL_bool SDL_GetDriverAndJoystickIndex(int device_index, struct _SDL_JoystickDriver **driver, int *driver_index);
48 
49 /* Function to return the device index for a joystick ID, or -1 if not found */
50 extern int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id);
51 
52 /* Function to extract information from an SDL joystick GUID */
53 extern void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version);
54 
55 /* Function to standardize the name for a controller
56    This should be freed with SDL_free() when no longer needed
57  */
58 extern char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name);
59 
60 /* Function to return the type of a controller */
61 extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name);
62 extern SDL_GameControllerType SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 product, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
63 
64 /* Function to return whether a joystick is a Nintendo Switch Pro controller */
65 extern SDL_bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id);
66 
67 /* Function to return whether a joystick is a Steam Controller */
68 extern SDL_bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
69 
70 /* Function to return whether a joystick guid comes from the XInput driver */
71 extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid);
72 
73 /* Function to return whether a joystick guid comes from the WGI driver */
74 extern SDL_bool SDL_IsJoystickWGI(SDL_JoystickGUID guid);
75 
76 /* Function to return whether a joystick guid comes from the HIDAPI driver */
77 extern SDL_bool SDL_IsJoystickHIDAPI(SDL_JoystickGUID guid);
78 
79 /* Function to return whether a joystick guid comes from the RAWINPUT driver */
80 extern SDL_bool SDL_IsJoystickRAWINPUT(SDL_JoystickGUID guid);
81 
82 /* Function to return whether a joystick guid comes from the Virtual driver */
83 extern SDL_bool SDL_IsJoystickVirtual(SDL_JoystickGUID guid);
84 
85 /* Function to return whether a joystick should be ignored */
86 extern SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid);
87 
88 /* Function to return whether a joystick name and GUID is a game controller  */
89 extern SDL_bool SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid);
90 
91 /* Function to return whether a game controller should be ignored */
92 extern SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid);
93 
94 /* Handle delayed guide button on a game controller */
95 extern void SDL_GameControllerHandleDelayedGuideButton(SDL_Joystick *joystick);
96 
97 /* Internal event queueing functions */
98 extern void SDL_PrivateJoystickAdded(SDL_JoystickID device_instance);
99 extern void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance);
100 extern int SDL_PrivateJoystickAxis(SDL_Joystick * joystick,
101                                    Uint8 axis, Sint16 value);
102 extern int SDL_PrivateJoystickBall(SDL_Joystick * joystick,
103                                    Uint8 ball, Sint16 xrel, Sint16 yrel);
104 extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
105                                   Uint8 hat, Uint8 value);
106 extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
107                                      Uint8 button, Uint8 state);
108 extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick * joystick,
109                                             SDL_JoystickPowerLevel ePowerLevel);
110 
111 /* Internal sanity checking functions */
112 extern SDL_bool SDL_PrivateJoystickValid(SDL_Joystick * joystick);
113 
114 typedef enum
115 {
116     EMappingKind_None = 0,
117     EMappingKind_Button = 1,
118     EMappingKind_Axis = 2,
119     EMappingKind_Hat = 3
120 } EMappingKind;
121 
122 typedef struct _SDL_InputMapping
123 {
124     EMappingKind kind;
125     Uint8 target;
126 } SDL_InputMapping;
127 
128 typedef struct _SDL_GamepadMapping
129 {
130     SDL_InputMapping a;
131     SDL_InputMapping b;
132     SDL_InputMapping x;
133     SDL_InputMapping y;
134     SDL_InputMapping back;
135     SDL_InputMapping guide;
136     SDL_InputMapping start;
137     SDL_InputMapping leftstick;
138     SDL_InputMapping rightstick;
139     SDL_InputMapping leftshoulder;
140     SDL_InputMapping rightshoulder;
141     SDL_InputMapping dpup;
142     SDL_InputMapping dpdown;
143     SDL_InputMapping dpleft;
144     SDL_InputMapping dpright;
145     SDL_InputMapping leftx;
146     SDL_InputMapping lefty;
147     SDL_InputMapping rightx;
148     SDL_InputMapping righty;
149     SDL_InputMapping lefttrigger;
150     SDL_InputMapping righttrigger;
151 } SDL_GamepadMapping;
152 
153 /* Function to get autodetected gamepad controller mapping from the driver */
154 extern SDL_bool SDL_PrivateJoystickGetAutoGamepadMapping(int device_index,
155                                                          SDL_GamepadMapping *out);
156 
157 #endif /* SDL_joystick_c_h_ */
158 
159 /* vi: set ts=4 sw=4 expandtab: */
160