diff --git a/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h b/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h index 7a3e493603..699ed05045 100644 --- a/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h +++ b/Source/Core/Core/HW/WiimoteEmu/DesiredWiimoteState.h @@ -4,11 +4,17 @@ #pragma once #include "Core/HW/WiimoteCommon/WiimoteReport.h" +#include "Core/HW/WiimoteEmu/WiimoteEmu.h" namespace WiimoteEmu { struct DesiredWiimoteState { + // 1g in Z direction, which is the default returned by an unmoving emulated Wiimote. + static constexpr WiimoteCommon::AccelData DEFAULT_ACCELERATION = WiimoteCommon::AccelData( + {Wiimote::ACCEL_ZERO_G << 2, Wiimote::ACCEL_ZERO_G << 2, Wiimote::ACCEL_ONE_G << 2}); + WiimoteCommon::ButtonData buttons{}; // non-button state in this is ignored + WiimoteCommon::AccelData acceleration = DEFAULT_ACCELERATION; }; } // namespace WiimoteEmu diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index c30163017f..e279f8a38e 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -449,6 +449,11 @@ DesiredWiimoteState Wiimote::BuildDesiredWiimoteState() m_dpad->GetState(&wiimote_state.buttons.hex, IsSideways() ? dpad_sideways_bitmasks : dpad_bitmasks); + // Calculate accelerometer state. + // Calibration values are 8-bit but we want 10-bit precision, so << 2. + wiimote_state.acceleration = + ConvertAccelData(GetTotalAcceleration(), ACCEL_ZERO_G << 2, ACCEL_ONE_G << 2); + return wiimote_state; } @@ -493,10 +498,10 @@ void Wiimote::Update() return; } - SendDataReport(); + SendDataReport(target_state); } -void Wiimote::SendDataReport() +void Wiimote::SendDataReport(const DesiredWiimoteState& target_state) { Movie::SetPolledDevice(); @@ -532,10 +537,7 @@ void Wiimote::SendDataReport() // Acceleration: if (rpt_builder.HasAccel()) { - // Calibration values are 8-bit but we want 10-bit precision, so << 2. - AccelData accel = - ConvertAccelData(GetTotalAcceleration(), ACCEL_ZERO_G << 2, ACCEL_ONE_G << 2); - rpt_builder.SetAccelData(accel); + rpt_builder.SetAccelData(target_state.acceleration); } // IR Camera: diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 5a54b66b40..cf78d3c0ca 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -192,7 +192,7 @@ private: void HandleExtensionSwap(); bool ProcessExtensionPortEvent(); - void SendDataReport(); + void SendDataReport(const DesiredWiimoteState& target_state); bool ProcessReadDataRequest(); void SetRumble(bool on);