WiimoteEmu: Update accelerometer status from DesiredWiimoteState.

This commit is contained in:
Admiral H. Curtiss 2022-09-17 14:08:54 +02:00
parent a39f82cb1f
commit 9669722dfc
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
3 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -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:

View File

@ -192,7 +192,7 @@ private:
void HandleExtensionSwap();
bool ProcessExtensionPortEvent();
void SendDataReport();
void SendDataReport(const DesiredWiimoteState& target_state);
bool ProcessReadDataRequest();
void SetRumble(bool on);