Skip to content

Commit

Permalink
Merge pull request #7640 from jordan-woyak/input-fixes
Browse files Browse the repository at this point in the history
ControllerInterface: Output/Rumble fixes
  • Loading branch information
JMC47 committed Jan 5, 2019
2 parents d75e9b2 + a995e2f commit 0ca9acc
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 125 deletions.
2 changes: 0 additions & 2 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,10 @@ static void ResetRumble()
#if defined(__LIBUSB__)
GCAdapter::ResetRumble();
#endif
#if defined(CIFACE_USE_XINPUT) || defined(CIFACE_USE_DINPUT)
if (!Pad::IsInitialized())
return;
for (int i = 0; i < 4; ++i)
Pad::ResetRumble(i);
#endif
}

// Called from GUI thread
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace MappingCommon
{
constexpr int INPUT_DETECT_TIME = 3000;
constexpr int OUTPUT_DETECT_TIME = 2000;

QString GetExpressionForControl(const QString& control_name,
const ciface::Core::DeviceQualifier& control_device,
const ciface::Core::DeviceQualifier& default_device, Quote quote)
Expand Down Expand Up @@ -41,7 +44,9 @@ QString GetExpressionForControl(const QString& control_name,
QString DetectExpression(ControlReference* reference, ciface::Core::Device* device,
const ciface::Core::DeviceQualifier& default_device, Quote quote)
{
ciface::Core::Device::Control* const ctrl = reference->Detect(5000, device);
const int ms = reference->IsInput() ? INPUT_DETECT_TIME : OUTPUT_DETECT_TIME;

ciface::Core::Device::Control* const ctrl = reference->Detect(ms, device);

if (ctrl)
{
Expand Down
10 changes: 3 additions & 7 deletions Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,7 @@ class CoalesceExpression : public Expression
}

ControlState GetValue() const override { return GetActiveChild()->GetValue(); }
void SetValue(ControlState value) override
{
m_lhs->SetValue(GetActiveChild() == m_lhs ? value : 0.0);
m_rhs->SetValue(GetActiveChild() == m_rhs ? value : 0.0);
}
void SetValue(ControlState value) override { GetActiveChild()->SetValue(value); }

int CountNumControls() const override { return GetActiveChild()->CountNumControls(); }
operator std::string() const override
Expand Down Expand Up @@ -549,5 +545,5 @@ std::pair<ParseStatus, std::unique_ptr<Expression>> ParseExpression(const std::s
std::move(complex_result.expr));
return std::make_pair(complex_result.status, std::move(combined_expr));
}
}
}
} // namespace ExpressionParser
} // namespace ciface
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <map>
#include <sstream>

#include "Common/Logging/Log.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/ControllerInterface/DInput/DInput.h"
#include "InputCommon/ControllerInterface/DInput/DInputJoystick.h"
Expand Down Expand Up @@ -40,8 +41,10 @@ void InitJoystick(IDirectInput8* const idi8, HWND hwnd)
if (FAILED(js_device->SetCooperativeLevel(GetAncestor(hwnd, GA_ROOT),
DISCL_BACKGROUND | DISCL_EXCLUSIVE)))
{
// PanicAlert("SetCooperativeLevel(DISCL_EXCLUSIVE) failed!");
// fall back to non-exclusive mode, with no rumble
WARN_LOG(
PAD,
"DInput: Failed to acquire device exclusively. Force feedback will be unavailable.");
// Fall back to non-exclusive mode, with no rumble
if (FAILED(
js_device->SetCooperativeLevel(nullptr, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
Expand Down Expand Up @@ -136,20 +139,27 @@ Joystick::Joystick(/*const LPCDIDEVICEINSTANCE lpddi, */ const LPDIRECTINPUTDEVI
}
}

// force feedback
// Force feedback:
std::list<DIDEVICEOBJECTINSTANCE> objects;
if (SUCCEEDED(m_device->EnumObjects(DIEnumDeviceObjectsCallback, (LPVOID)&objects, DIDFT_AXIS)))
{
InitForceFeedback(m_device, (int)objects.size());
const int num_ff_axes =
std::count_if(std::begin(objects), std::end(objects), [](DIDEVICEOBJECTINSTANCE& pdidoi) {
return pdidoi.dwFlags && DIDOI_FFACTUATOR;
});
InitForceFeedback(m_device, num_ff_axes);
}

ZeroMemory(&m_state_in, sizeof(m_state_in));
// set hats to center
memset(m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV));
// Zero inputs:
m_state_in = {};
// Set hats to center:
std::fill(std::begin(m_state_in.rgdwPOV), std::end(m_state_in.rgdwPOV), 0xFF);
}

Joystick::~Joystick()
{
DeInitForceFeedback();

m_device->Unacquire();
m_device->Release();
}
Expand Down Expand Up @@ -265,5 +275,5 @@ ControlState Joystick::Hat::GetState() const

return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
}
}
}
} // namespace DInput
} // namespace ciface
Loading

0 comments on commit 0ca9acc

Please sign in to comment.