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.
slouken@12088
     1
/*
slouken@12088
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@12088
     4
slouken@12088
     5
  This software is provided 'as-is', without any express or implied
slouken@12088
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@12088
     7
  arising from the use of this software.
slouken@12088
     8
slouken@12088
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@12088
    10
  including commercial applications, and to alter it and redistribute it
slouken@12088
    11
  freely, subject to the following restrictions:
slouken@12088
    12
slouken@12088
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@12088
    14
     claim that you wrote the original software. If you use this software
slouken@12088
    15
     in a product, an acknowledgment in the product documentation would be
slouken@12088
    16
     appreciated but is not required.
slouken@12088
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@12088
    18
     misrepresented as being the original software.
slouken@12088
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@12088
    20
*/
slouken@12088
    21
#include "../../SDL_internal.h"
slouken@12088
    22
slouken@12088
    23
#ifndef SDL_JOYSTICK_HIDAPI_H
slouken@12088
    24
#define SDL_JOYSTICK_HIDAPI_H
slouken@12088
    25
slouken@12088
    26
#include "../../hidapi/hidapi/hidapi.h"
slouken@12088
    27
slouken@12088
    28
/* This is the full set of HIDAPI drivers available */
slouken@12088
    29
#define SDL_JOYSTICK_HIDAPI_PS4
slouken@12088
    30
#define SDL_JOYSTICK_HIDAPI_SWITCH
slouken@12088
    31
#define SDL_JOYSTICK_HIDAPI_XBOX360
slouken@12088
    32
#define SDL_JOYSTICK_HIDAPI_XBOXONE
flibitijibibo@12641
    33
#define SDL_JOYSTICK_HIDAPI_GAMECUBE
slouken@12088
    34
slouken@12088
    35
#ifdef __WINDOWS__
slouken@12118
    36
/* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
slouken@12088
    37
#undef SDL_JOYSTICK_HIDAPI_XBOXONE
slouken@12296
    38
/* It turns out HIDAPI for Xbox controllers doesn't allow background input */
slouken@12296
    39
#undef SDL_JOYSTICK_HIDAPI_XBOX360
slouken@12088
    40
#endif
slouken@12088
    41
slouken@12088
    42
#ifdef __MACOSX__
slouken@12088
    43
/* On Mac OS X, Xbox One controllers are handled by the Xbox 360 driver */
slouken@12088
    44
#undef SDL_JOYSTICK_HIDAPI_XBOXONE
slouken@12088
    45
#endif
slouken@12088
    46
flibitijibibo@12641
    47
typedef struct _SDL_HIDAPI_DriverData
flibitijibibo@12641
    48
{
flibitijibibo@12641
    49
    hid_device *device;
flibitijibibo@12641
    50
    void *context;
flibitijibibo@12641
    51
} SDL_HIDAPI_DriverData;
flibitijibibo@12641
    52
slouken@12088
    53
typedef struct _SDL_HIDAPI_DeviceDriver
slouken@12088
    54
{
slouken@12088
    55
    const char *hint;
slouken@12088
    56
    SDL_bool enabled;
slouken@12168
    57
    SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number);
slouken@12088
    58
    const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
flibitijibibo@12641
    59
flibitijibibo@12641
    60
    SDL_bool       (*InitDriver)(SDL_HIDAPI_DriverData *context,
flibitijibibo@12641
    61
                                 Uint16 vendor_id, Uint16 product_id, int *num_joysticks);
flibitijibibo@12641
    62
    void           (*QuitDriver)(SDL_HIDAPI_DriverData *context,
flibitijibibo@12641
    63
                                 SDL_bool send_event,
flibitijibibo@12641
    64
                                 int *num_joysticks);
flibitijibibo@12641
    65
    SDL_bool       (*UpdateDriver)(SDL_HIDAPI_DriverData *context,
flibitijibibo@12641
    66
                                   int *num_joysticks);
flibitijibibo@12641
    67
    int            (*NumJoysticks)(SDL_HIDAPI_DriverData *context);
flibitijibibo@12641
    68
    SDL_JoystickID (*InstanceIDForIndex)(SDL_HIDAPI_DriverData *context,
flibitijibibo@12641
    69
                                         int index);
flibitijibibo@12641
    70
    SDL_bool       (*OpenJoystick)(SDL_HIDAPI_DriverData *context,
flibitijibibo@12641
    71
                                   SDL_Joystick *joystick);
flibitijibibo@12641
    72
    int            (*Rumble)(SDL_HIDAPI_DriverData *context,
flibitijibibo@12641
    73
                             SDL_Joystick *joystick,
flibitijibibo@12641
    74
                             Uint16 low_frequency_rumble,
flibitijibibo@12641
    75
                             Uint16 high_frequency_rumble,
flibitijibibo@12641
    76
                             Uint32 duration_ms);
slouken@12088
    77
slouken@12088
    78
} SDL_HIDAPI_DeviceDriver;
slouken@12088
    79
slouken@12088
    80
/* HIDAPI device support */
slouken@12088
    81
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
slouken@12088
    82
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
slouken@12088
    83
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
slouken@12088
    84
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
slouken@12088
    85
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
flibitijibibo@12641
    86
extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
slouken@12088
    87
slouken@12088
    88
/* Return true if a HID device is present and supported as a joystick */
slouken@12115
    89
extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version);
slouken@12088
    90
slouken@12117
    91
/* Return the name of an Xbox 360 or Xbox One controller */
slouken@12117
    92
extern const char *HIDAPI_XboxControllerName(Uint16 vendor_id, Uint16 product_id);
slouken@12117
    93
slouken@12088
    94
#endif /* SDL_JOYSTICK_HIDAPI_H */
slouken@12088
    95
slouken@12088
    96
/* vi: set ts=4 sw=4 expandtab: */