mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-12-16 04:09:39 +00:00
WiimoteReal: Detect already connected Wii remotes on Windows without having to use the Refresh button.
This commit is contained in:
parent
e0c40025a9
commit
8845fbdb7e
@ -675,13 +675,19 @@ void WiimoteScannerWindows::FindWiimoteHIDDevices(std::vector<Wiimote*>& found_w
|
||||
}
|
||||
}
|
||||
|
||||
void WiimoteScannerWindows::FindWiimotes(std::vector<Wiimote*>& found_wiimotes,
|
||||
Wiimote*& found_board)
|
||||
void WiimoteScannerWindows::FindWiimotes(std::vector<Wiimote*>&, Wiimote*&)
|
||||
{
|
||||
// Ideally we'd only enumerate the radios once.
|
||||
RemoveUnusableWiimoteBluetoothDevices();
|
||||
DiscoverAndPairWiimotes(DEFAULT_INQUIRY_LENGTH);
|
||||
// TODO: This sleep is hacky. We should run FindWiimoteHIDDevices when a new device is created.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
// Kinda odd that we never return any remotes here. The scanner interface is odd.
|
||||
// We return all the results in FindAlreadyConnectedWiimote.
|
||||
}
|
||||
|
||||
void WiimoteScannerWindows::FindAttachedDevices(std::vector<Wiimote*>& found_wiimotes,
|
||||
Wiimote*& found_board)
|
||||
{
|
||||
FindWiimoteHIDDevices(found_wiimotes, found_board);
|
||||
}
|
||||
|
||||
|
||||
@ -53,6 +53,7 @@ public:
|
||||
WiimoteScannerWindows();
|
||||
bool IsReady() const override;
|
||||
void FindWiimotes(std::vector<Wiimote*>&, Wiimote*&) override;
|
||||
void FindAttachedDevices(std::vector<Wiimote*>&, Wiimote*&) override;
|
||||
void Update() override;
|
||||
void RequestStopSearching() override {}
|
||||
|
||||
|
||||
@ -689,15 +689,12 @@ void WiimoteScanner::ThreadFunc()
|
||||
g_controller_interface.PlatformPopulateDevices([] { ProcessWiimotePool(); });
|
||||
}
|
||||
|
||||
// Does stuff needed to detect disconnects on Windows
|
||||
// Currently does nothing. To be removed.
|
||||
for (const auto& backend : m_backends)
|
||||
backend->Update();
|
||||
|
||||
CheckForDisconnectedWiimotes();
|
||||
|
||||
if (m_scan_mode.load() == WiimoteScanMode::DO_NOT_SCAN)
|
||||
continue;
|
||||
|
||||
// If we don't want Wiimotes in ControllerInterface, we may not need them at all.
|
||||
if (!Config::Get(Config::MAIN_CONNECT_WIIMOTES_FOR_CONTROLLER_INTERFACE))
|
||||
{
|
||||
@ -715,11 +712,22 @@ void WiimoteScanner::ThreadFunc()
|
||||
continue;
|
||||
}
|
||||
|
||||
// Stop scanning if not in continuous mode.
|
||||
auto scan_mode = WiimoteScanMode::SCAN_ONCE;
|
||||
m_scan_mode.compare_exchange_strong(scan_mode, WiimoteScanMode::DO_NOT_SCAN);
|
||||
|
||||
for (const auto& backend : m_backends)
|
||||
{
|
||||
std::vector<Wiimote*> found_wiimotes;
|
||||
Wiimote* found_board = nullptr;
|
||||
backend->FindWiimotes(found_wiimotes, found_board);
|
||||
|
||||
// When not scanning we still look for already attached devices.
|
||||
// This allows Windows and DolphinBar remotes to be quickly discovered.
|
||||
if (scan_mode == WiimoteScanMode::DO_NOT_SCAN)
|
||||
backend->FindAttachedDevices(found_wiimotes, found_board);
|
||||
else
|
||||
backend->FindWiimotes(found_wiimotes, found_board);
|
||||
|
||||
{
|
||||
std::unique_lock wm_lk(g_wiimotes_mutex);
|
||||
|
||||
@ -745,10 +753,6 @@ void WiimoteScanner::ThreadFunc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop scanning if not in continuous mode.
|
||||
auto scan_mode = WiimoteScanMode::SCAN_ONCE;
|
||||
m_scan_mode.compare_exchange_strong(scan_mode, WiimoteScanMode::DO_NOT_SCAN);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@ -189,6 +189,10 @@ public:
|
||||
virtual void Update() = 0;
|
||||
// requests the backend to stop scanning if FindWiimotes is blocking
|
||||
virtual void RequestStopSearching() = 0;
|
||||
|
||||
// Used by Windows to search for HID interfaces of already connected Wii remotes.
|
||||
// hidapi should probably implement the equivalent.
|
||||
virtual void FindAttachedDevices(std::vector<Wiimote*>&, Wiimote*&) {}
|
||||
};
|
||||
|
||||
enum class WiimoteScanMode
|
||||
|
||||
Loading…
Reference in New Issue
Block a user