Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Track the real wiimote rumble state to drop outgoing rumble reports w…
…ith 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.)
  • Loading branch information
jordan-woyak committed Apr 8, 2013
1 parent 4c40e70 commit 018282c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.cpp
Expand Up @@ -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}};
Expand All @@ -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)
{
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h
Expand Up @@ -103,12 +103,15 @@ friend class WiimoteEmu::Wiimote;

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;

Expand Down

0 comments on commit 018282c

Please sign in to comment.