WiimoteReal: Disconnect the Wiimote if IOWrite fails

This is intended to make reconnecting Wiimotes easier with a DolphinBar.
Unfortunately, this change isn't enough as it doesn't always catch
disconnections for Wiimotes connected with a DolphinBar.

But it's better than nothing and eventually a disconnection will be
detected when something tries to write to the Wiimote, instead of never.

There is no other solution as the DolphinBar always exposes 4 HIDs even
when the associated Wiimotes are not connected.

We could try to detect this using the fake input reports sent by the
DolphinBar, but this only works for the first HID (probably because of
a bug in the firmware?), so this method is not an option.
This commit is contained in:
Léo Lam 2016-08-04 15:38:43 +02:00
parent 53d553d2b0
commit d9a9e34994
2 changed files with 12 additions and 5 deletions

View File

@ -218,10 +218,11 @@ void Wiimote::Read()
} }
} }
void Wiimote::Write() bool Wiimote::Write()
{ {
// nothing written, but this is not an error
if (m_write_reports.Empty()) if (m_write_reports.Empty())
return; return true;
Report const& rpt = m_write_reports.Front(); Report const& rpt = m_write_reports.Front();
@ -231,12 +232,14 @@ void Wiimote::Write()
Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost, Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost,
SConfig::GetInstance().iBBDumpPort); SConfig::GetInstance().iBBDumpPort);
} }
IOWrite(rpt.data(), rpt.size()); int ret = IOWrite(rpt.data(), rpt.size());
m_write_reports.Pop(); m_write_reports.Pop();
if (!m_write_reports.Empty()) if (!m_write_reports.Empty())
IOWakeup(); IOWakeup();
return ret != 0;
} }
static bool IsDataReport(const Report& rpt) static bool IsDataReport(const Report& rpt)
@ -577,7 +580,11 @@ void Wiimote::ThreadFunc()
m_index + 1); m_index + 1);
break; break;
} }
Write(); if (!Write())
{
ERROR_LOG(WIIMOTE, "Wiimote::Write failed. Disconnecting Wiimote %d.", m_index + 1);
break;
}
Read(); Read();
} }

View File

@ -39,7 +39,7 @@ public:
const Report& ProcessReadQueue(); const Report& ProcessReadQueue();
void Read(); void Read();
void Write(); bool Write();
void StartThread(); void StartThread();
void StopThread(); void StopThread();