WiimoteReal/IOAndroid: Only "find" DolphinBar remotes which are actually connected.

This commit is contained in:
Jordan Woyak 2025-09-30 22:07:08 -05:00
parent c84d30c782
commit 99cc5e7bb7
2 changed files with 20 additions and 2 deletions

View File

@ -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;

View File

@ -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;