summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-09-30 22:07:08 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2025-10-19 22:36:39 -0500
commit99cc5e7bb7ed72ffae4f70bc76c4f2e77ce634ca (patch)
tree3c95c6ac9b088be9709f9267eddfbd9603523e85
parentc84d30c782107c5f462e3dcda568b76627b2b12d (diff)
WiimoteReal/IOAndroid: Only "find" DolphinBar remotes which are actually connected.
-rw-r--r--Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp16
-rw-r--r--Source/Core/Core/HW/WiimoteReal/IOAndroid.h6
2 files changed, 20 insertions, 2 deletions
diff --git a/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp b/Source/Core/Core/HW/WiimoteReal/IOAndroid.cpp
index e4697176ec..e5e511c694 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<Wiimote*>& found_wiimotes,
if (!IsNewWiimote(WiimoteAndroid::GetIdFromDolphinBarIndex(i)))
continue;
- found_wiimotes.emplace_back(new WiimoteAndroid(i));
+ auto wiimote = std::make_unique<WiimoteAndroid>(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 ada33fa69d..506c9ae5c1 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;