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

WIP: WiimoteReal: Attempt to fix M+ detection problems. #8626

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <queue>
#include <unordered_set>

#include "Common/BitUtils.h"
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
Expand All @@ -24,6 +25,7 @@
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteCommon/DataReport.h"
#include "Core/HW/WiimoteCommon/WiimoteHid.h"
#include "Core/HW/WiimoteEmu/MotionPlus.h"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing is that now this include looks out of place, perhaps a comment would be good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree.

#include "Core/HW/WiimoteReal/IOAndroid.h"
#include "Core/HW/WiimoteReal/IOLinux.h"
#include "Core/HW/WiimoteReal/IOWin.h"
Expand Down Expand Up @@ -292,6 +294,24 @@ void Wiimote::InterruptDataOutput(const u8* data, const u32 size)
// Keep only the rumble bit.
rpt[2] &= 0x1;
}
else if (rpt[1] == u8(OutputReportID::WriteData) &&
rpt.size() >= sizeof(OutputReportWriteData) + 2)
{
OutputReportWriteData write_data = Common::BitCastPtr<OutputReportWriteData>(rpt.data() + 2);
if (write_data.space == u8(AddressSpace::I2CBus) &&
Common::swap16(write_data.address) == WiimoteEmu::MotionPlus::PASSTHROUGH_MODE_OFFSET)
{
// TODO: check activation value.
INFO_LOG_FMT(WIIMOTE, "Noticed M+ activation signal.");

// Request two status reports.
Report status_report = {WR_SET_REPORT | BT_OUTPUT, u8(OutputReportID::RequestStatus), 0};
WriteReport(status_report);
WriteReport(std::move(status_report));

m_is_performing_mplus_detection_fix = true;
}
}

WriteReport(std::move(rpt));
}
Expand Down Expand Up @@ -486,11 +506,25 @@ void Wiimote::Update(const WiimoteEmu::DesiredWiimoteState& target_state)
const bool repeat_reports_to_maintain_200hz =
Config::Get(Config::MAIN_REAL_WII_REMOTE_REPEAT_REPORTS);

const Report& rpt = ProcessReadQueue(repeat_reports_to_maintain_200hz);
Report& rpt = ProcessReadQueue(repeat_reports_to_maintain_200hz);

if (rpt.empty())
return;

if (m_is_performing_mplus_detection_fix && InputReportID(rpt[1]) == InputReportID::Status)
{
m_is_performing_mplus_detection_fix = false;

InputReportStatus status = Common::BitCastPtr<InputReportStatus>(rpt.data() + 2);

const bool was_needed = status.extension;
status.extension = 0;

Common::BitCastPtr<InputReportStatus>(rpt.data() + 2) = status;

INFO_LOG_FMT(WIIMOTE, "Performed M+ detection fix: {}", was_needed);
}

InterruptCallback(rpt.front(), rpt.data() + REPORT_HID_HEADER_SIZE,
u32(rpt.size() - REPORT_HID_HEADER_SIZE));
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteReal/WiimoteReal.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class Wiimote : public WiimoteCommon::HIDWiimote
// And we track the rumble state to drop unnecessary rumble reports.
bool m_rumble_state = false;

bool m_is_performing_mplus_detection_fix = false;

std::thread m_wiimote_thread;
// Whether to keep running the thread.
Common::Flag m_run_thread;
Expand Down