src/joystick/hidapi/SDL_hidapijoystick_c.h
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Tue, 12 Mar 2019 20:27:54 -0400
changeset 12641 64597a7e8771
parent 12503 806492103856
child 12787 0411f841b035
permissions -rw-r--r--
hidapi: Add support for Wii U/Switch USB GameCube controller adapter.

Note that a single USB device is responsible for all 4 joysticks, so a large
rewrite of the DeviceDriver functions was necessary to allow a single device to
produce multiple joysticks.
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2019 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_JOYSTICK_HIDAPI_H
    24 #define SDL_JOYSTICK_HIDAPI_H
    25 
    26 #include "../../hidapi/hidapi/hidapi.h"
    27 
    28 /* This is the full set of HIDAPI drivers available */
    29 #define SDL_JOYSTICK_HIDAPI_PS4
    30 #define SDL_JOYSTICK_HIDAPI_SWITCH
    31 #define SDL_JOYSTICK_HIDAPI_XBOX360
    32 #define SDL_JOYSTICK_HIDAPI_XBOXONE
    33 #define SDL_JOYSTICK_HIDAPI_GAMECUBE
    34 
    35 #ifdef __WINDOWS__
    36 /* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
    37 #undef SDL_JOYSTICK_HIDAPI_XBOXONE
    38 /* It turns out HIDAPI for Xbox controllers doesn't allow background input */
    39 #undef SDL_JOYSTICK_HIDAPI_XBOX360
    40 #endif
    41 
    42 #ifdef __MACOSX__
    43 /* On Mac OS X, Xbox One controllers are handled by the Xbox 360 driver */
    44 #undef SDL_JOYSTICK_HIDAPI_XBOXONE
    45 #endif
    46 
    47 typedef struct _SDL_HIDAPI_DriverData
    48 {
    49     hid_device *device;
    50     void *context;
    51 } SDL_HIDAPI_DriverData;
    52 
    53 typedef struct _SDL_HIDAPI_DeviceDriver
    54 {
    55     const char *hint;
    56     SDL_bool enabled;
    57     SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number);
    58     const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
    59 
    60     SDL_bool       (*InitDriver)(SDL_HIDAPI_DriverData *context,
    61                                  Uint16 vendor_id, Uint16 product_id, int *num_joysticks);
    62     void           (*QuitDriver)(SDL_HIDAPI_DriverData *context,
    63                                  SDL_bool send_event,
    64                                  int *num_joysticks);
    65     SDL_bool       (*UpdateDriver)(SDL_HIDAPI_DriverData *context,
    66                                    int *num_joysticks);
    67     int            (*NumJoysticks)(SDL_HIDAPI_DriverData *context);
    68     SDL_JoystickID (*InstanceIDForIndex)(SDL_HIDAPI_DriverData *context,
    69                                          int index);
    70     SDL_bool       (*OpenJoystick)(SDL_HIDAPI_DriverData *context,
    71                                    SDL_Joystick *joystick);
    72     int            (*Rumble)(SDL_HIDAPI_DriverData *context,
    73                              SDL_Joystick *joystick,
    74                              Uint16 low_frequency_rumble,
    75                              Uint16 high_frequency_rumble,
    76                              Uint32 duration_ms);
    77 
    78 } SDL_HIDAPI_DeviceDriver;
    79 
    80 /* HIDAPI device support */
    81 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
    82 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
    83 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
    84 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
    85 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
    86 extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
    87 
    88 /* Return true if a HID device is present and supported as a joystick */
    89 extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version);
    90 
    91 /* Return the name of an Xbox 360 or Xbox One controller */
    92 extern const char *HIDAPI_XboxControllerName(Uint16 vendor_id, Uint16 product_id);
    93 
    94 #endif /* SDL_JOYSTICK_HIDAPI_H */
    95 
    96 /* vi: set ts=4 sw=4 expandtab: */