From 8845fbdb7e84f4707e7b664b01e381419d7deadb Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Fri, 3 Oct 2025 23:08:05 -0500 Subject: [PATCH] WiimoteReal: Detect already connected Wii remotes on Windows without having to use the Refresh button. --- Source/Core/Core/HW/WiimoteReal/IOWin.cpp | 14 ++++++++---- Source/Core/Core/HW/WiimoteReal/IOWin.h | 1 + .../Core/Core/HW/WiimoteReal/WiimoteReal.cpp | 22 +++++++++++-------- Source/Core/Core/HW/WiimoteReal/WiimoteReal.h | 4 ++++ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp index 1f2e76b1616..6f037019e72 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp @@ -675,13 +675,19 @@ void WiimoteScannerWindows::FindWiimoteHIDDevices(std::vector& found_w } } -void WiimoteScannerWindows::FindWiimotes(std::vector& found_wiimotes, - Wiimote*& found_board) +void WiimoteScannerWindows::FindWiimotes(std::vector&, 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& found_wiimotes, + Wiimote*& found_board) +{ FindWiimoteHIDDevices(found_wiimotes, found_board); } diff --git a/Source/Core/Core/HW/WiimoteReal/IOWin.h b/Source/Core/Core/HW/WiimoteReal/IOWin.h index 16bdeba0fd3..12c577f950e 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOWin.h +++ b/Source/Core/Core/HW/WiimoteReal/IOWin.h @@ -53,6 +53,7 @@ public: WiimoteScannerWindows(); bool IsReady() const override; void FindWiimotes(std::vector&, Wiimote*&) override; + void FindAttachedDevices(std::vector&, Wiimote*&) override; void Update() override; void RequestStopSearching() override {} diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp index 36fda0bc8ac..7451c5d02b6 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.cpp @@ -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 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); } { diff --git a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h index 168d9a61001..dd0f699aed9 100644 --- a/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h +++ b/Source/Core/Core/HW/WiimoteReal/WiimoteReal.h @@ -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*&) {} }; enum class WiimoteScanMode