diff --git a/Source/Core/Core/HW/WiimoteReal/IONix.cpp b/Source/Core/Core/HW/WiimoteReal/IONix.cpp index 3c4bc19d6b..6d4a9f8145 100644 --- a/Source/Core/Core/HW/WiimoteReal/IONix.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IONix.cpp @@ -12,7 +12,6 @@ #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" -#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteReal/WiimoteReal.h" namespace WiimoteReal @@ -22,6 +21,7 @@ class WiimoteLinux final : public Wiimote public: WiimoteLinux(bdaddr_t bdaddr); ~WiimoteLinux() override; + const bdaddr_t& Address() const; protected: bool ConnectInternal() override; @@ -82,10 +82,13 @@ void WiimoteScanner::FindWiimotes(std::vector& found_wiimotes, Wiimote inquiry_info scan_infos[max_infos] = {}; auto* scan_infos_ptr = scan_infos; found_board = nullptr; + // Use Limited Dedicated Inquiry Access Code (LIAC) to query, since third-party Wiimotes + // cannot be discovered without it. + const u8 lap[3] = {0x00, 0x8b, 0x9e}; // Scan for Bluetooth devices int const found_devices = - hci_inquiry(device_id, wait_len, max_infos, nullptr, &scan_infos_ptr, IREQ_CACHE_FLUSH); + hci_inquiry(device_id, wait_len, max_infos, lap, &scan_infos_ptr, IREQ_CACHE_FLUSH); if (found_devices < 0) { ERROR_LOG(WIIMOTE, "Error searching for Bluetooth devices."); @@ -112,14 +115,16 @@ void WiimoteScanner::FindWiimotes(std::vector& found_wiimotes, Wiimote { bool new_wiimote = true; - // TODO: do this - // Determine if this Wiimote has already been found. - // for (int j = 0; j < MAX_WIIMOTES && new_wiimote; ++j) - //{ - // if (wm[j] && bacmp(&scan_infos[i].bdaddr,&wm[j]->bdaddr) == 0) - // new_wiimote = false; - //} + for (int j = 0; j < MAX_BBMOTES && new_wiimote; ++j) + { + // compare this address with the stored addresses in our global array + // static_cast is OK here, since we're only ever going to have this subclass in g_wiimotes + // on Linux (and likewise, only WiimoteWindows on Windows, etc) + auto connected_wiimote = static_cast(g_wiimotes[j]); + if (connected_wiimote && bacmp(&scan_infos[i].bdaddr, &connected_wiimote->Address()) == 0) + new_wiimote = false; + } if (new_wiimote) { @@ -165,6 +170,11 @@ WiimoteLinux::~WiimoteLinux() close(m_wakeup_pipe_r); } +const bdaddr_t& WiimoteLinux::Address() const +{ + return m_bdaddr; +} + // Connect to a Wiimote with a known address. bool WiimoteLinux::ConnectInternal() {