From d9a9e3499483e53a2aa3bf6f73b7713f3cbdff46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 4 Aug 2016 15:38:43 +0200 Subject: [PATCH] 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. --- Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 15 +++++++++++---- Source/Core/Core/HW/WiimoteReal/WiimoteReal.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index 266e67f3e1..d2ddd283c8 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -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()) - return; + return true; Report const& rpt = m_write_reports.Front(); @@ -231,12 +232,14 @@ void Wiimote::Write() Socket.send((char*)rpt.data(), rpt.size(), sf::IpAddress::LocalHost, SConfig::GetInstance().iBBDumpPort); } - IOWrite(rpt.data(), rpt.size()); + int ret = IOWrite(rpt.data(), rpt.size()); m_write_reports.Pop(); if (!m_write_reports.Empty()) IOWakeup(); + + return ret != 0; } static bool IsDataReport(const Report& rpt) @@ -577,7 +580,11 @@ void Wiimote::ThreadFunc() m_index + 1); break; } - Write(); + if (!Write()) + { + ERROR_LOG(WIIMOTE, "Wiimote::Write failed. Disconnecting Wiimote %d.", m_index + 1); + break; + } Read(); } diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h index 54039ab2b2..bd322543af 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h @@ -39,7 +39,7 @@ public: const Report& ProcessReadQueue(); void Read(); - void Write(); + bool Write(); void StartThread(); void StopThread();