Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ControllerInterface: Unbreak DirectInput POV Hats having bad values on init. #7913

Merged
merged 1 commit into from Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -153,8 +153,10 @@ Joystick::Joystick(/*const LPCDIDEVICEINSTANCE lpddi, */ const LPDIRECTINPUTDEVI

// Zero inputs:
m_state_in = {};

// 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()
Expand Down Expand Up @@ -269,9 +271,11 @@ ControlState Joystick::Button::GetState() const

ControlState Joystick::Hat::GetState() const
{
// can this func be simplified ?
// hat centered code from MSDN
if (0xFFFF == LOWORD(m_hat))
// "Some drivers report the centered position of the POV indicator as 65,535.
// Determine whether the indicator is centered as follows" -MSDN
const bool is_centered = (0xffff == LOWORD(m_hat));

if (is_centered)
return 0;

return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
Expand Down