src/joystick/windows/SDL_xinputjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 30 Sep 2015 15:39:30 -0700
changeset 9884 26b595dea221
parent 9660 b7188b6a6f2a
child 9918 31b7adf67756
permissions -rw-r--r--
SDL - added new SDL_JoystickCurrentPowerLevel() API that returns the battery level of the selected joystick. Currently only implemented for XInput devices, other platforms are a TODO.

CR: Sam
slouken@8972
     1
/*
slouken@8972
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
slouken@8972
     4
slouken@8972
     5
  This software is provided 'as-is', without any express or implied
slouken@8972
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@8972
     7
  arising from the use of this software.
slouken@8972
     8
slouken@8972
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@8972
    10
  including commercial applications, and to alter it and redistribute it
slouken@8972
    11
  freely, subject to the following restrictions:
slouken@8972
    12
slouken@8972
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@8972
    14
     claim that you wrote the original software. If you use this software
slouken@8972
    15
     in a product, an acknowledgment in the product documentation would be
slouken@8972
    16
     appreciated but is not required.
slouken@8972
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@8972
    18
     misrepresented as being the original software.
slouken@8972
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@8972
    20
*/
slouken@8972
    21
#include "../../SDL_internal.h"
slouken@8972
    22
icculus@9659
    23
#include "../SDL_sysjoystick.h"
icculus@9659
    24
icculus@9658
    25
#if SDL_JOYSTICK_XINPUT
icculus@9658
    26
slouken@8972
    27
#include "SDL_assert.h"
slouken@8972
    28
#include "SDL_hints.h"
slouken@8972
    29
#include "SDL_windowsjoystick_c.h"
slouken@8972
    30
#include "SDL_xinputjoystick_c.h"
slouken@8972
    31
slouken@8972
    32
/*
slouken@8972
    33
 * Internal stuff.
slouken@8972
    34
 */
slouken@8972
    35
static SDL_bool s_bXInputEnabled = SDL_TRUE;
slouken@8972
    36
slouken@8972
    37
slouken@8972
    38
static SDL_bool
slouken@8972
    39
SDL_XInputUseOldJoystickMapping()
slouken@8972
    40
{
slouken@8972
    41
    static int s_XInputUseOldJoystickMapping = -1;
slouken@8972
    42
    if (s_XInputUseOldJoystickMapping < 0) {
slouken@8972
    43
        const char *hint = SDL_GetHint(SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING);
slouken@8972
    44
        s_XInputUseOldJoystickMapping = (hint && *hint == '1') ? 1 : 0;
slouken@8972
    45
    }
slouken@8972
    46
    return (s_XInputUseOldJoystickMapping > 0);
slouken@8972
    47
}
slouken@8972
    48
slouken@8972
    49
SDL_bool SDL_XINPUT_Enabled(void)
slouken@8972
    50
{
slouken@8972
    51
    return s_bXInputEnabled;
slouken@8972
    52
}
slouken@8972
    53
slouken@8972
    54
int
slouken@8972
    55
SDL_XINPUT_JoystickInit(void)
slouken@8972
    56
{
slouken@8972
    57
    const char *env = SDL_GetHint(SDL_HINT_XINPUT_ENABLED);
slouken@8972
    58
    if (env && !SDL_atoi(env)) {
slouken@8972
    59
        s_bXInputEnabled = SDL_FALSE;
slouken@8972
    60
    }
slouken@8972
    61
slouken@8972
    62
    if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) {
slouken@8972
    63
        s_bXInputEnabled = SDL_FALSE;  /* oh well. */
slouken@8972
    64
    }
slouken@8972
    65
    return 0;
slouken@8972
    66
}
slouken@8972
    67
slouken@8972
    68
static char *
slouken@8972
    69
GetXInputName(const Uint8 userid, BYTE SubType)
slouken@8972
    70
{
slouken@8972
    71
    char name[32];
slouken@8972
    72
slouken@8972
    73
    if (SDL_XInputUseOldJoystickMapping()) {
slouken@8972
    74
        SDL_snprintf(name, sizeof(name), "X360 Controller #%u", 1 + userid);
slouken@8972
    75
    } else {
slouken@8972
    76
        switch (SubType) {
slouken@8972
    77
        case XINPUT_DEVSUBTYPE_GAMEPAD:
slouken@8972
    78
            SDL_snprintf(name, sizeof(name), "XInput Controller #%u", 1 + userid);
slouken@8972
    79
            break;
slouken@8972
    80
        case XINPUT_DEVSUBTYPE_WHEEL:
slouken@8972
    81
            SDL_snprintf(name, sizeof(name), "XInput Wheel #%u", 1 + userid);
slouken@8972
    82
            break;
slouken@8972
    83
        case XINPUT_DEVSUBTYPE_ARCADE_STICK:
slouken@8972
    84
            SDL_snprintf(name, sizeof(name), "XInput ArcadeStick #%u", 1 + userid);
slouken@8972
    85
            break;
slouken@8972
    86
        case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
slouken@8972
    87
            SDL_snprintf(name, sizeof(name), "XInput FlightStick #%u", 1 + userid);
slouken@8972
    88
            break;
slouken@8972
    89
        case XINPUT_DEVSUBTYPE_DANCE_PAD:
slouken@8972
    90
            SDL_snprintf(name, sizeof(name), "XInput DancePad #%u", 1 + userid);
slouken@8972
    91
            break;
slouken@8972
    92
        case XINPUT_DEVSUBTYPE_GUITAR:
slouken@8972
    93
        case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
slouken@8972
    94
        case XINPUT_DEVSUBTYPE_GUITAR_BASS:
slouken@8972
    95
            SDL_snprintf(name, sizeof(name), "XInput Guitar #%u", 1 + userid);
slouken@8972
    96
            break;
slouken@8972
    97
        case XINPUT_DEVSUBTYPE_DRUM_KIT:
slouken@8972
    98
            SDL_snprintf(name, sizeof(name), "XInput DrumKit #%u", 1 + userid);
slouken@8972
    99
            break;
slouken@8972
   100
        case XINPUT_DEVSUBTYPE_ARCADE_PAD:
slouken@8972
   101
            SDL_snprintf(name, sizeof(name), "XInput ArcadePad #%u", 1 + userid);
slouken@8972
   102
            break;
slouken@8972
   103
        default:
slouken@8972
   104
            SDL_snprintf(name, sizeof(name), "XInput Device #%u", 1 + userid);
slouken@8972
   105
            break;
slouken@8972
   106
        }
slouken@8972
   107
    }
slouken@8972
   108
    return SDL_strdup(name);
slouken@8972
   109
}
slouken@8972
   110
slouken@8972
   111
static void
slouken@8972
   112
AddXInputDevice(const Uint8 userid, BYTE SubType, JoyStick_DeviceData **pContext)
slouken@8972
   113
{
slouken@8972
   114
    JoyStick_DeviceData *pPrevJoystick = NULL;
slouken@8972
   115
    JoyStick_DeviceData *pNewJoystick = *pContext;
slouken@8972
   116
slouken@8972
   117
    if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
slouken@8972
   118
        return;
slouken@8972
   119
slouken@8972
   120
    if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN)
slouken@8972
   121
        return;
slouken@8972
   122
slouken@8972
   123
    while (pNewJoystick) {
slouken@8972
   124
        if (pNewJoystick->bXInputDevice && (pNewJoystick->XInputUserId == userid) && (pNewJoystick->SubType == SubType)) {
slouken@8972
   125
            /* if we are replacing the front of the list then update it */
slouken@8972
   126
            if (pNewJoystick == *pContext) {
slouken@8972
   127
                *pContext = pNewJoystick->pNext;
slouken@8972
   128
            } else if (pPrevJoystick) {
slouken@8972
   129
                pPrevJoystick->pNext = pNewJoystick->pNext;
slouken@8972
   130
            }
slouken@8972
   131
slouken@8972
   132
            pNewJoystick->pNext = SYS_Joystick;
slouken@8972
   133
            SYS_Joystick = pNewJoystick;
slouken@8972
   134
            return;   /* already in the list. */
slouken@8972
   135
        }
slouken@8972
   136
slouken@8972
   137
        pPrevJoystick = pNewJoystick;
slouken@8972
   138
        pNewJoystick = pNewJoystick->pNext;
slouken@8972
   139
    }
slouken@8972
   140
slouken@8972
   141
    pNewJoystick = (JoyStick_DeviceData *)SDL_malloc(sizeof(JoyStick_DeviceData));
slouken@8972
   142
    if (!pNewJoystick) {
slouken@8972
   143
        return; /* better luck next time? */
slouken@8972
   144
    }
slouken@8972
   145
    SDL_zerop(pNewJoystick);
slouken@8972
   146
slouken@8972
   147
    pNewJoystick->joystickname = GetXInputName(userid, SubType);
slouken@8972
   148
    if (!pNewJoystick->joystickname) {
slouken@8972
   149
        SDL_free(pNewJoystick);
slouken@8972
   150
        return; /* better luck next time? */
slouken@8972
   151
    }
slouken@8972
   152
slouken@8972
   153
    pNewJoystick->bXInputDevice = SDL_TRUE;
slouken@8972
   154
    if (SDL_XInputUseOldJoystickMapping()) {
slouken@8972
   155
        SDL_zero(pNewJoystick->guid);
slouken@8972
   156
    } else {
slouken@8972
   157
        pNewJoystick->guid.data[0] = 'x';
slouken@8972
   158
        pNewJoystick->guid.data[1] = 'i';
slouken@8972
   159
        pNewJoystick->guid.data[2] = 'n';
slouken@8972
   160
        pNewJoystick->guid.data[3] = 'p';
slouken@8972
   161
        pNewJoystick->guid.data[4] = 'u';
slouken@8972
   162
        pNewJoystick->guid.data[5] = 't';
slouken@8972
   163
        pNewJoystick->guid.data[6] = SubType;
slouken@8972
   164
    }
slouken@8972
   165
    pNewJoystick->SubType = SubType;
slouken@8972
   166
    pNewJoystick->XInputUserId = userid;
slouken@8972
   167
    SDL_SYS_AddJoystickDevice(pNewJoystick);
slouken@8972
   168
}
slouken@8972
   169
slouken@8972
   170
void
slouken@8972
   171
SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
slouken@8972
   172
{
slouken@8972
   173
    int iuserid;
slouken@8972
   174
slouken@8972
   175
    if (!s_bXInputEnabled) {
slouken@8972
   176
        return;
slouken@8972
   177
    }
slouken@8972
   178
slouken@8972
   179
    /* iterate in reverse, so these are in the final list in ascending numeric order. */
slouken@8972
   180
    for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
slouken@8972
   181
        const Uint8 userid = (Uint8)iuserid;
slouken@8972
   182
        XINPUT_CAPABILITIES capabilities;
slouken@8972
   183
        if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
slouken@8972
   184
            AddXInputDevice(userid, capabilities.SubType, pContext);
slouken@8972
   185
        }
slouken@8972
   186
    }
slouken@8972
   187
}
slouken@8972
   188
slouken@8972
   189
int
slouken@8972
   190
SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
slouken@8972
   191
{
slouken@8972
   192
    const Uint8 userId = joystickdevice->XInputUserId;
slouken@8972
   193
    XINPUT_CAPABILITIES capabilities;
slouken@8972
   194
    XINPUT_VIBRATION state;
slouken@8972
   195
slouken@8972
   196
    SDL_assert(s_bXInputEnabled);
slouken@8972
   197
    SDL_assert(XINPUTGETCAPABILITIES);
slouken@8972
   198
    SDL_assert(XINPUTSETSTATE);
slouken@8972
   199
    SDL_assert(userId < XUSER_MAX_COUNT);
slouken@8972
   200
slouken@8972
   201
    joystick->hwdata->bXInputDevice = SDL_TRUE;
slouken@8972
   202
slouken@8972
   203
    if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
slouken@8972
   204
        SDL_free(joystick->hwdata);
slouken@8972
   205
        joystick->hwdata = NULL;
slouken@8972
   206
        return SDL_SetError("Failed to obtain XInput device capabilities. Device disconnected?");
slouken@8972
   207
    }
slouken@8972
   208
    SDL_zero(state);
slouken@8972
   209
    joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &state) == ERROR_SUCCESS);
slouken@8972
   210
    joystick->hwdata->userid = userId;
slouken@8972
   211
slouken@8972
   212
    /* The XInput API has a hard coded button/axis mapping, so we just match it */
slouken@8972
   213
    if (SDL_XInputUseOldJoystickMapping()) {
slouken@8972
   214
        joystick->naxes = 6;
slouken@8972
   215
        joystick->nbuttons = 15;
slouken@8972
   216
    } else {
slouken@8972
   217
        joystick->naxes = 6;
slouken@8972
   218
        joystick->nbuttons = 11;
slouken@8972
   219
        joystick->nhats = 1;
slouken@8972
   220
    }
slouken@8972
   221
    return 0;
slouken@8972
   222
}
slouken@8972
   223
slouken@9884
   224
static void 
slouken@9884
   225
UpdateXInputJoystickBatteryInformation(SDL_Joystick * joystick, XINPUT_BATTERY_INFORMATION *pBatteryInformation)
slouken@9884
   226
{
slouken@9884
   227
    if ( pBatteryInformation->BatteryType != BATTERY_TYPE_UNKNOWN )
slouken@9884
   228
    {
slouken@9884
   229
        SDL_JoystickPowerLevel ePowerLevel = SDL_JOYSTICK_POWER_UNKNOWN;
slouken@9884
   230
        if (pBatteryInformation->BatteryType == BATTERY_TYPE_WIRED) {
slouken@9884
   231
            ePowerLevel = SDL_JOYSTICK_POWER_WIRED;
slouken@9884
   232
        } else {
slouken@9884
   233
            switch ( pBatteryInformation->BatteryLevel )
slouken@9884
   234
            {
slouken@9884
   235
            case BATTERY_LEVEL_EMPTY:
slouken@9884
   236
                ePowerLevel = SDL_JOYSTICK_POWER_EMPTY;
slouken@9884
   237
                break;
slouken@9884
   238
            case BATTERY_LEVEL_LOW:
slouken@9884
   239
                ePowerLevel = SDL_JOYSTICK_POWER_LOW;
slouken@9884
   240
                break;
slouken@9884
   241
            case BATTERY_LEVEL_MEDIUM:
slouken@9884
   242
                ePowerLevel = SDL_JOYSTICK_POWER_MEDIUM;
slouken@9884
   243
                break;
slouken@9884
   244
            default:
slouken@9884
   245
            case BATTERY_LEVEL_FULL:
slouken@9884
   246
                ePowerLevel = SDL_JOYSTICK_POWER_FULL;
slouken@9884
   247
                break;
slouken@9884
   248
            }
slouken@9884
   249
        }
slouken@9884
   250
slouken@9884
   251
        SDL_PrivateJoystickBatteryLevel( joystick, ePowerLevel );
slouken@9884
   252
    }
slouken@9884
   253
}
slouken@9884
   254
slouken@8972
   255
static void
slouken@9884
   256
UpdateXInputJoystickState_OLD(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION *pBatteryInformation)
slouken@8972
   257
{
slouken@8972
   258
    static WORD s_XInputButtons[] = {
slouken@8972
   259
        XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_RIGHT,
slouken@8972
   260
        XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
slouken@8972
   261
        XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER,
slouken@8972
   262
        XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
slouken@8972
   263
        XINPUT_GAMEPAD_GUIDE
slouken@8972
   264
    };
slouken@8972
   265
    WORD wButtons = pXInputState->Gamepad.wButtons;
slouken@8972
   266
    Uint8 button;
slouken@8972
   267
slouken@8972
   268
    SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
slouken@8972
   269
    SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
slouken@8972
   270
    SDL_PrivateJoystickAxis(joystick, 2, (Sint16)pXInputState->Gamepad.sThumbRX);
slouken@8972
   271
    SDL_PrivateJoystickAxis(joystick, 3, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
slouken@8972
   272
    SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
slouken@8972
   273
    SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
slouken@8972
   274
slouken@8972
   275
    for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
slouken@8972
   276
        SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
slouken@8972
   277
    }
slouken@9884
   278
slouken@9884
   279
    UpdateXInputJoystickBatteryInformation( joystick, pBatteryInformation );
slouken@8972
   280
}
slouken@8972
   281
slouken@8972
   282
static void
slouken@9884
   283
UpdateXInputJoystickState(SDL_Joystick * joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION *pBatteryInformation)
slouken@8972
   284
{
slouken@8972
   285
    static WORD s_XInputButtons[] = {
slouken@8972
   286
        XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
slouken@8972
   287
        XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_START,
slouken@8972
   288
        XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
slouken@8972
   289
        XINPUT_GAMEPAD_GUIDE
slouken@8972
   290
    };
slouken@8972
   291
    WORD wButtons = pXInputState->Gamepad.wButtons;
slouken@8972
   292
    Uint8 button;
slouken@8972
   293
    Uint8 hat = SDL_HAT_CENTERED;
slouken@8972
   294
slouken@8972
   295
    SDL_PrivateJoystickAxis(joystick, 0, (Sint16)pXInputState->Gamepad.sThumbLX);
slouken@8972
   296
    SDL_PrivateJoystickAxis(joystick, 1, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbLY)));
slouken@8972
   297
    SDL_PrivateJoystickAxis(joystick, 2, (Sint16)(((int)pXInputState->Gamepad.bLeftTrigger * 65535 / 255) - 32768));
slouken@8972
   298
    SDL_PrivateJoystickAxis(joystick, 3, (Sint16)pXInputState->Gamepad.sThumbRX);
slouken@8972
   299
    SDL_PrivateJoystickAxis(joystick, 4, (Sint16)(-SDL_max(-32767, pXInputState->Gamepad.sThumbRY)));
slouken@8972
   300
    SDL_PrivateJoystickAxis(joystick, 5, (Sint16)(((int)pXInputState->Gamepad.bRightTrigger * 65535 / 255) - 32768));
slouken@8972
   301
slouken@8972
   302
    for (button = 0; button < SDL_arraysize(s_XInputButtons); ++button) {
slouken@8972
   303
        SDL_PrivateJoystickButton(joystick, button, (wButtons & s_XInputButtons[button]) ? SDL_PRESSED : SDL_RELEASED);
slouken@8972
   304
    }
slouken@8972
   305
slouken@8972
   306
    if (wButtons & XINPUT_GAMEPAD_DPAD_UP) {
slouken@8972
   307
        hat |= SDL_HAT_UP;
slouken@8972
   308
    }
slouken@8972
   309
    if (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) {
slouken@8972
   310
        hat |= SDL_HAT_DOWN;
slouken@8972
   311
    }
slouken@8972
   312
    if (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) {
slouken@8972
   313
        hat |= SDL_HAT_LEFT;
slouken@8972
   314
    }
slouken@8972
   315
    if (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) {
slouken@8972
   316
        hat |= SDL_HAT_RIGHT;
slouken@8972
   317
    }
slouken@8972
   318
    SDL_PrivateJoystickHat(joystick, 0, hat);
slouken@9884
   319
slouken@9884
   320
    UpdateXInputJoystickBatteryInformation( joystick, pBatteryInformation );
slouken@8972
   321
}
slouken@8972
   322
slouken@8972
   323
void
slouken@8972
   324
SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
slouken@8972
   325
{
slouken@8972
   326
    HRESULT result;
slouken@8972
   327
    XINPUT_STATE_EX XInputState;
slouken@9884
   328
    XINPUT_BATTERY_INFORMATION XBatteryInformation;
slouken@8972
   329
slouken@8972
   330
    if (!XINPUTGETSTATE)
slouken@8972
   331
        return;
slouken@8972
   332
slouken@8972
   333
    result = XINPUTGETSTATE(joystick->hwdata->userid, &XInputState);
slouken@8972
   334
    if (result == ERROR_DEVICE_NOT_CONNECTED) {
slouken@8972
   335
        joystick->hwdata->send_remove_event = SDL_TRUE;
slouken@8972
   336
        joystick->hwdata->removed = SDL_TRUE;
slouken@8972
   337
        return;
slouken@8972
   338
    }
slouken@8972
   339
slouken@9884
   340
    SDL_zero( XBatteryInformation );
slouken@9884
   341
    if ( XINPUTGETBATTERYINFORMATION )
slouken@9884
   342
    {
slouken@9884
   343
        result = XINPUTGETBATTERYINFORMATION( joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation );
slouken@9884
   344
    }
slouken@9884
   345
slouken@8972
   346
    /* only fire events if the data changed from last time */
slouken@8972
   347
    if (XInputState.dwPacketNumber && XInputState.dwPacketNumber != joystick->hwdata->dwPacketNumber) {
slouken@8972
   348
        if (SDL_XInputUseOldJoystickMapping()) {
slouken@9884
   349
            UpdateXInputJoystickState_OLD(joystick, &XInputState, &XBatteryInformation);
slouken@8972
   350
        } else {
slouken@9884
   351
            UpdateXInputJoystickState(joystick, &XInputState, &XBatteryInformation);
slouken@8972
   352
        }
slouken@8972
   353
        joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
slouken@8972
   354
    }
slouken@8972
   355
}
slouken@8972
   356
slouken@8972
   357
void
slouken@8972
   358
SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
slouken@8972
   359
{
slouken@8972
   360
}
slouken@8972
   361
slouken@8972
   362
void
slouken@8972
   363
SDL_XINPUT_JoystickQuit(void)
slouken@8972
   364
{
slouken@8972
   365
    if (s_bXInputEnabled) {
slouken@8972
   366
        WIN_UnloadXInputDLL();
slouken@8972
   367
    }
slouken@8972
   368
}
slouken@8972
   369
slouken@8972
   370
SDL_bool
slouken@8972
   371
SDL_SYS_IsXInputGamepad_DeviceIndex(int device_index)
slouken@8972
   372
{
slouken@8972
   373
    JoyStick_DeviceData *device = SYS_Joystick;
slouken@8972
   374
    int index;
slouken@8972
   375
slouken@8972
   376
    for (index = device_index; index > 0; index--)
slouken@8972
   377
        device = device->pNext;
slouken@8972
   378
slouken@8972
   379
    return (device->SubType == XINPUT_DEVSUBTYPE_GAMEPAD);
slouken@8972
   380
}
slouken@8972
   381
slouken@8972
   382
#else /* !SDL_JOYSTICK_XINPUT */
slouken@8972
   383
icculus@9660
   384
typedef struct JoyStick_DeviceData JoyStick_DeviceData;
slouken@8972
   385
slouken@8972
   386
SDL_bool SDL_XINPUT_Enabled(void)
slouken@8972
   387
{
slouken@8972
   388
    return SDL_FALSE;
slouken@8972
   389
}
slouken@8972
   390
slouken@8972
   391
int
slouken@8972
   392
SDL_XINPUT_JoystickInit(void)
slouken@8972
   393
{
slouken@8972
   394
    return 0;
slouken@8972
   395
}
slouken@8972
   396
slouken@8972
   397
void
slouken@8972
   398
SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext)
slouken@8972
   399
{
slouken@8972
   400
}
slouken@8972
   401
slouken@8972
   402
int
slouken@8972
   403
SDL_XINPUT_JoystickOpen(SDL_Joystick * joystick, JoyStick_DeviceData *joystickdevice)
slouken@8972
   404
{
slouken@8972
   405
    return SDL_Unsupported();
slouken@8972
   406
}
slouken@8972
   407
slouken@8972
   408
void
slouken@8972
   409
SDL_XINPUT_JoystickUpdate(SDL_Joystick * joystick)
slouken@8972
   410
{
slouken@8972
   411
}
slouken@8972
   412
slouken@8972
   413
void
slouken@8972
   414
SDL_XINPUT_JoystickClose(SDL_Joystick * joystick)
slouken@8972
   415
{
slouken@8972
   416
}
slouken@8972
   417
slouken@8972
   418
void
slouken@8972
   419
SDL_XINPUT_JoystickQuit(void)
slouken@8972
   420
{
slouken@8972
   421
}
slouken@8972
   422
slouken@8972
   423
#endif /* SDL_JOYSTICK_XINPUT */
slouken@8972
   424
slouken@8972
   425
/* vi: set ts=4 sw=4 expandtab: */