Skip to content

Commit

Permalink
Ignore capabilities reported by an XInput device
Browse files Browse the repository at this point in the history
  • Loading branch information
ToadKing committed Aug 10, 2017
1 parent 0f9ae6d commit 4fb2d1e
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,46 +109,37 @@ void DeInit()

Device::Device(const XINPUT_CAPABILITIES& caps, u8 index) : m_subtype(caps.SubType), m_index(index)
{
// XInputGetCaps seems to always claim all capabilities are supported
// but I will leave all this stuff in, incase m$ fixes xinput up a bit
// XInputGetCaps can be broken on some devices, so we'll just ignore it
// and assume all gamepad + vibration capabilities are supported

// get supported buttons
for (int i = 0; i != sizeof(named_buttons) / sizeof(*named_buttons); ++i)
{
// Guide button is never reported in caps
if ((named_buttons[i].bitmask & caps.Gamepad.wButtons) ||
((named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) && haveGuideButton))
// Only add guide button if we have the 100 ordinal XInputGetState
if (!(named_buttons[i].bitmask & XINPUT_GAMEPAD_GUIDE) || haveGuideButton)
AddInput(new Button(i, m_state_in.Gamepad.wButtons));
}

// get supported triggers
for (int i = 0; i != sizeof(named_triggers) / sizeof(*named_triggers); ++i)
{
// BYTE val = (&caps.Gamepad.bLeftTrigger)[i]; // should be max value / MSDN lies
if ((&caps.Gamepad.bLeftTrigger)[i])
AddInput(new Trigger(i, (&m_state_in.Gamepad.bLeftTrigger)[i], 255));
AddInput(new Trigger(i, (&m_state_in.Gamepad.bLeftTrigger)[i], 255));
}

// get supported axes
for (int i = 0; i != sizeof(named_axes) / sizeof(*named_axes); ++i)
{
// SHORT val = (&caps.Gamepad.sThumbLX)[i]; // xinput doesn't give the range / MSDN is a liar
if ((&caps.Gamepad.sThumbLX)[i])
{
const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i];
const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i];

// each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(i, ax, -32768));
AddInput(new Axis(i, ax, 32767));
}
// each axis gets a negative and a positive input instance associated with it
AddInput(new Axis(i, ax, -32768));
AddInput(new Axis(i, ax, 32767));
}

// get supported motors
for (int i = 0; i != sizeof(named_motors) / sizeof(*named_motors); ++i)
{
// WORD val = (&caps.Vibration.wLeftMotorSpeed)[i]; // should be max value / nope, more lies
if ((&caps.Vibration.wLeftMotorSpeed)[i])
AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535));
AddOutput(new Motor(i, this, (&m_state_out.wLeftMotorSpeed)[i], 65535));
}

ZeroMemory(&m_state_in, sizeof(m_state_in));
Expand Down

0 comments on commit 4fb2d1e

Please sign in to comment.