Merge pull request #7913 from jordan-woyak/dinput-hat-fix

ControllerInterface: Unbreak DirectInput POV Hats having bad values on init.
This commit is contained in:
JMC47 2019-03-19 17:24:02 -04:00 committed by GitHub
commit 96fec2eb70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -153,8 +153,10 @@ Joystick::Joystick(/*const LPCDIDEVICEINSTANCE lpddi, */ const LPDIRECTINPUTDEVI
// Zero inputs: // Zero inputs:
m_state_in = {}; m_state_in = {};
// Set hats to center: // Set hats to center:
std::fill(std::begin(m_state_in.rgdwPOV), std::end(m_state_in.rgdwPOV), 0xFF); // "The center position is normally reported as -1" -MSDN
std::fill(std::begin(m_state_in.rgdwPOV), std::end(m_state_in.rgdwPOV), -1);
} }
Joystick::~Joystick() Joystick::~Joystick()
@ -269,9 +271,11 @@ ControlState Joystick::Button::GetState() const
ControlState Joystick::Hat::GetState() const ControlState Joystick::Hat::GetState() const
{ {
// can this func be simplified ? // "Some drivers report the centered position of the POV indicator as 65,535.
// hat centered code from MSDN // Determine whether the indicator is centered as follows" -MSDN
if (0xFFFF == LOWORD(m_hat)) const bool is_centered = (0xffff == LOWORD(m_hat));
if (is_centered)
return 0; return 0;
return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2); return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);