src/joystick/SDL_sysjoystick.h
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Tue, 12 Mar 2019 20:27:54 -0400
changeset 12641 64597a7e8771
parent 12503 806492103856
child 12896 b91647e1a977
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@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
slouken@0
    22
slouken@10638
    23
#ifndef SDL_sysjoystick_h_
slouken@10638
    24
#define SDL_sysjoystick_h_
slouken@8972
    25
slouken@0
    26
/* This is the system specific header for the SDL joystick API */
slouken@0
    27
slouken@0
    28
#include "SDL_joystick.h"
slouken@6690
    29
#include "SDL_joystick_c.h"
slouken@0
    30
slouken@0
    31
/* The SDL joystick structure */
slouken@10713
    32
typedef struct _SDL_JoystickAxisInfo
slouken@10713
    33
{
slouken@10752
    34
    Sint16 initial_value;       /* Initial axis state */
slouken@10752
    35
    Sint16 value;               /* Current axis state */
slouken@10745
    36
    Sint16 zero;                /* Zero point on the axis (-32768 for triggers) */
slouken@10745
    37
    SDL_bool has_initial_value; /* Whether we've seen a value on the axis yet */
slouken@10745
    38
    SDL_bool sent_initial_value; /* Whether we've sent the initial axis value */
slouken@10713
    39
} SDL_JoystickAxisInfo;
slouken@10713
    40
slouken@1895
    41
struct _SDL_Joystick
slouken@1895
    42
{
slouken@6949
    43
    SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
slouken@6949
    44
    char *name;                 /* Joystick name - system dependent */
slouken@12359
    45
    int player_index;           /* Joystick player index, or -1 if unavailable */
slouken@12088
    46
    SDL_JoystickGUID guid;      /* Joystick guid */
slouken@0
    47
slouken@1895
    48
    int naxes;                  /* Number of axis controls on the joystick */
slouken@10713
    49
    SDL_JoystickAxisInfo *axes;
slouken@0
    50
slouken@1895
    51
    int nhats;                  /* Number of hats on the joystick */
slouken@1895
    52
    Uint8 *hats;                /* Current hat states */
slouken@0
    53
slouken@1895
    54
    int nballs;                 /* Number of trackballs on the joystick */
slouken@6949
    55
    struct balldelta {
slouken@1895
    56
        int dx;
slouken@1895
    57
        int dy;
slouken@1895
    58
    } *balls;                   /* Current ball motion deltas */
slouken@1895
    59
slouken@1895
    60
    int nbuttons;               /* Number of buttons on the joystick */
slouken@1895
    61
    Uint8 *buttons;             /* Current button states */
slouken@1895
    62
slouken@12090
    63
    SDL_bool attached;
slouken@12088
    64
    SDL_bool is_game_controller;
slouken@12088
    65
    SDL_bool delayed_guide_button; /* SDL_TRUE if this device has the guide button event delayed */
slouken@12088
    66
    SDL_bool force_recentering; /* SDL_TRUE if this device needs to have its state reset to 0 */
slouken@12088
    67
    SDL_JoystickPowerLevel epowerlevel; /* power level of this joystick, SDL_JOYSTICK_POWER_UNKNOWN if not supported */
slouken@12088
    68
    struct _SDL_JoystickDriver *driver;
slouken@12088
    69
slouken@1895
    70
    struct joystick_hwdata *hwdata;     /* Driver dependent information */
slouken@1895
    71
slouken@1895
    72
    int ref_count;              /* Reference count for multiple opens */
slouken@6949
    73
slouken@6949
    74
    struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
slouken@0
    75
};
slouken@0
    76
slouken@12088
    77
#if defined(__IPHONEOS__) || defined(__ANDROID__)
slouken@12088
    78
#define HAVE_STEAMCONTROLLERS
slouken@12088
    79
#define USE_STEAMCONTROLLER_HIDAPI
slouken@12088
    80
#elif defined(__LINUX__)
slouken@12088
    81
#define HAVE_STEAMCONTROLLERS
slouken@12088
    82
#define USE_STEAMCONTROLLER_LINUX
slouken@12088
    83
#endif
slouken@12088
    84
slouken@12088
    85
/* Device bus definitions */
slouken@12088
    86
#define SDL_HARDWARE_BUS_USB        0x03
slouken@12088
    87
#define SDL_HARDWARE_BUS_BLUETOOTH  0x05
slouken@12088
    88
slouken@10966
    89
/* Macro to combine a USB vendor ID and product ID into a single Uint32 value */
slouken@10966
    90
#define MAKE_VIDPID(VID, PID)   (((Uint32)(VID))<<16|(PID))
slouken@10966
    91
slouken@12088
    92
typedef struct _SDL_JoystickDriver
slouken@12088
    93
{
slouken@12088
    94
    /* Function to scan the system for joysticks.
slouken@12088
    95
     * Joystick 0 should be the system default joystick.
slouken@12088
    96
     * This function should return 0, or -1 on an unrecoverable error.
slouken@12088
    97
     */
slouken@12088
    98
    int (*Init)(void);
slouken@0
    99
slouken@12088
   100
    /* Function to return the number of joystick devices plugged in right now */
slouken@12088
   101
    int (*GetCount)(void);
slouken@6707
   102
slouken@12088
   103
    /* Function to cause any queued joystick insertions to be processed */
slouken@12088
   104
    void (*Detect)(void);
slouken@6707
   105
slouken@12088
   106
    /* Function to get the device-dependent name of a joystick */
slouken@12088
   107
    const char *(*GetDeviceName)(int device_index);
slouken@6690
   108
slouken@12359
   109
    /* Function to get the player index of a joystick */
slouken@12359
   110
    int (*GetDevicePlayerIndex)(int device_index);
slouken@12359
   111
slouken@12088
   112
    /* Function to return the stable GUID for a plugged in device */
slouken@12088
   113
    SDL_JoystickGUID (*GetDeviceGUID)(int device_index);
slouken@0
   114
slouken@12088
   115
    /* Function to get the current instance id of the joystick located at device_index */
slouken@12088
   116
    SDL_JoystickID (*GetDeviceInstanceID)(int device_index);
slouken@6707
   117
slouken@12088
   118
    /* Function to open a joystick for use.
slouken@12088
   119
       The joystick to open is specified by the device index.
slouken@12088
   120
       This should fill the nbuttons and naxes fields of the joystick structure.
slouken@12088
   121
       It returns 0, or -1 if there is an error.
slouken@12088
   122
     */
slouken@12088
   123
    int (*Open)(SDL_Joystick * joystick, int device_index);
slouken@0
   124
slouken@12088
   125
    /* Rumble functionality */
slouken@12088
   126
    int (*Rumble)(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
slouken@0
   127
slouken@12088
   128
    /* Function to update the state of a joystick - called as a device poll.
slouken@12088
   129
     * This function shouldn't update the joystick structure directly,
slouken@12088
   130
     * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@12088
   131
     * and update joystick device state.
slouken@12088
   132
     */
slouken@12088
   133
    void (*Update)(SDL_Joystick * joystick);
slouken@1978
   134
slouken@12088
   135
    /* Function to close a joystick after use */
slouken@12088
   136
    void (*Close)(SDL_Joystick * joystick);
slouken@6690
   137
slouken@12088
   138
    /* Function to perform any system-specific joystick related cleanup */
slouken@12088
   139
    void (*Quit)(void);
slouken@12088
   140
slouken@12088
   141
} SDL_JoystickDriver;
slouken@12088
   142
slouken@12088
   143
/* The available joystick drivers */
slouken@12088
   144
extern SDL_JoystickDriver SDL_ANDROID_JoystickDriver;
icculus@12105
   145
extern SDL_JoystickDriver SDL_BSD_JoystickDriver;
slouken@12088
   146
extern SDL_JoystickDriver SDL_DARWIN_JoystickDriver;
slouken@12088
   147
extern SDL_JoystickDriver SDL_DUMMY_JoystickDriver;
icculus@12104
   148
extern SDL_JoystickDriver SDL_EMSCRIPTEN_JoystickDriver;
icculus@12107
   149
extern SDL_JoystickDriver SDL_HAIKU_JoystickDriver;
slouken@12088
   150
extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver;
slouken@12088
   151
extern SDL_JoystickDriver SDL_IOS_JoystickDriver;
slouken@12088
   152
extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
slouken@12088
   153
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
slouken@6690
   154
flibitijibibo@12641
   155
/* Special function to update HIDAPI devices */
flibitijibibo@12641
   156
extern void SDL_HIDAPI_UpdateDevices(void);
flibitijibibo@12641
   157
slouken@10638
   158
#endif /* SDL_sysjoystick_h_ */
slouken@6707
   159
slouken@1895
   160
/* vi: set ts=4 sw=4 expandtab: */