diff --git a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp index e4697176eca..e5e511c6945 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp @@ -43,7 +43,12 @@ void WiimoteScannerAndroid::FindWiimotes(std::vector& found_wiimotes, if (!IsNewWiimote(WiimoteAndroid::GetIdFromDolphinBarIndex(i))) continue; - found_wiimotes.emplace_back(new WiimoteAndroid(i)); + auto wiimote = std::make_unique(i); + + if (!wiimote->ConnectInternal()) + continue; + + found_wiimotes.emplace_back(wiimote.release()); } } } @@ -70,6 +75,9 @@ std::string WiimoteAndroid::GetIdFromDolphinBarIndex(int index) // Connect to a Wiimote with a known address. bool WiimoteAndroid::ConnectInternal() { + if (IsConnected()) + return true; + auto* const env = IDCache::GetEnvForThread(); jfieldID payload_field = env->GetStaticFieldID(s_adapter_class, "wiimotePayload", "[[B"); @@ -81,6 +89,12 @@ bool WiimoteAndroid::ConnectInternal() m_input_func = env->GetStaticMethodID(s_adapter_class, "input", "(I)I"); m_output_func = env->GetStaticMethodID(s_adapter_class, "output", "(I[BI)I"); + // Test a write to see if a remote is actually connected to the DolphinBar. + constexpr u8 report[] = {WR_SET_REPORT | BT_OUTPUT, + u8(WiimoteCommon::OutputReportID::RequestStatus), 0}; + if (IOWrite(report, sizeof(report)) <= 0) + return false; + is_connected = true; return true; diff --git a/Source/Core/Core/HW/WiimoteReal/IOAndroid.h b/Source/Core/Core/HW/WiimoteReal/IOAndroid.h index ada33fa69d8..506c9ae5c1e 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOAndroid.h +++ b/Source/Core/Core/HW/WiimoteReal/IOAndroid.h @@ -12,8 +12,12 @@ namespace WiimoteReal { +class WiimoteScannerAndroid; + class WiimoteAndroid final : public Wiimote { + friend WiimoteScannerAndroid; + public: WiimoteAndroid(int index); ~WiimoteAndroid() override; @@ -31,7 +35,7 @@ protected: private: int m_mayflash_index; - bool is_connected = true; + bool is_connected = false; jmethodID m_input_func; jmethodID m_output_func;