From 018282c2b9f2c0f128b0ae6ce9157ae01de5c4d5 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Mon, 8 Apr 2013 18:44:59 -0500 Subject: [PATCH] Track the real wiimote rumble state to drop outgoing rumble reports with no effect. This eliminates constant streams of reports in various games that constantly send audio reports. (Just Dance 2, DKCR, etc.) (Speaker data reports are converted to rumble reports when speaker data is disabled.) --- .../Core/Src/HW/WiimoteReal/WiimoteReal.cpp | 28 +++++++++++++++++-- .../Core/Src/HW/WiimoteReal/WiimoteReal.h | 3 ++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp index 095d5f4161..0b5583edaa 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp @@ -58,7 +58,9 @@ Wiimote::Wiimote() , dev_handle(0), stack(MSBT_STACK_UNKNOWN) #endif , m_last_input_report() - , m_channel(0), m_run_thread(false) + , m_channel(0) + , m_rumble_state() + , m_run_thread(false) { #if defined(__linux__) && HAVE_BLUEZ bdaddr = (bdaddr_t){{0, 0, 0, 0, 0, 0}}; @@ -76,6 +78,26 @@ Wiimote::~Wiimote() m_write_reports.Clear(); } +// to be called from CPU thread +void Wiimote::WriteReport(Report rpt) +{ + if (rpt.size() >= 3) + { + bool const new_rumble_state = (rpt[2] & 0x1) != 0; + + if (WM_RUMBLE == rpt[1] && new_rumble_state == m_rumble_state) + { + // If this is a rumble report and the rumble state didn't change, ignore + //ERROR_LOG(WIIMOTE, "Ignoring rumble report."); + return; + } + + m_rumble_state = new_rumble_state; + } + + m_write_reports.Push(std::move(rpt)); +} + // to be called from CPU thread void Wiimote::QueueReport(u8 rpt_id, const void* _data, unsigned int size) { @@ -85,7 +107,7 @@ void Wiimote::QueueReport(u8 rpt_id, const void* _data, unsigned int size) rpt[0] = WM_SET_REPORT | WM_BT_OUTPUT; rpt[1] = rpt_id; std::copy_n(data, size, rpt.begin() + 2); - m_write_reports.Push(std::move(rpt)); + WriteReport(std::move(rpt)); } void Wiimote::DisableDataReporting() @@ -171,7 +193,7 @@ void Wiimote::InterruptChannel(const u16 channel, const void* const _data, const rpt.resize(3); } - m_write_reports.Push(std::move(rpt)); + WriteReport(std::move(rpt)); } bool Wiimote::Read() diff --git a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h index 771cf7498d..a64f2c24b5 100644 --- a/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h @@ -103,12 +103,15 @@ protected: private: void ClearReadQueue(); + void WriteReport(Report rpt); int IORead(u8* buf); int IOWrite(u8 const* buf, int len); void ThreadFunc(); + bool m_rumble_state; + bool m_run_thread; std::thread m_wiimote_thread;