WiimoteReal/IOhidapi: Move VID/PID check to a helper function that other backends can use in the future.

This commit is contained in:
Jordan Woyak 2025-10-03 04:44:36 -05:00
parent 6c91e30a0d
commit 4a39ca249c
3 changed files with 9 additions and 2 deletions

View File

@ -70,8 +70,7 @@ void WiimoteScannerHidapi::FindWiimotes(std::vector<Wiimote*>& wiimotes, Wiimote
{ {
const std::string name = device->product_string ? WStringToUTF8(device->product_string) : ""; const std::string name = device->product_string ? WStringToUTF8(device->product_string) : "";
const bool is_wiimote = const bool is_wiimote =
IsValidDeviceName(name) || (device->vendor_id == 0x057e && IsValidDeviceName(name) || IsKnownDeviceId({device->vendor_id, device->product_id});
(device->product_id == 0x0306 || device->product_id == 0x0330));
if (!is_wiimote || !IsNewWiimote(device->path) || !IsDeviceUsable(device->path)) if (!is_wiimote || !IsNewWiimote(device->path) || !IsDeviceUsable(device->path))
continue; continue;

View File

@ -983,6 +983,11 @@ bool IsNewWiimote(const std::string& identifier)
return !s_known_ids.contains(identifier); return !s_known_ids.contains(identifier);
} }
bool IsKnownDeviceId(const USBUtils::DeviceInfo& device_info)
{
return device_info.vid == 0x057e && (device_info.pid == 0x0306 || device_info.pid == 0x0330);
}
void HandleWiimoteSourceChange(unsigned int index) void HandleWiimoteSourceChange(unsigned int index)
{ {
std::lock_guard wm_lk(g_wiimotes_mutex); std::lock_guard wm_lk(g_wiimotes_mutex);

View File

@ -20,6 +20,7 @@
#include "Core/HW/WiimoteCommon/WiimoteConstants.h" #include "Core/HW/WiimoteCommon/WiimoteConstants.h"
#include "Core/HW/WiimoteCommon/WiimoteHid.h" #include "Core/HW/WiimoteCommon/WiimoteHid.h"
#include "Core/HW/WiimoteCommon/WiimoteReport.h" #include "Core/HW/WiimoteCommon/WiimoteReport.h"
#include "Core/USBUtils.h"
class PointerWrap; class PointerWrap;
@ -222,6 +223,8 @@ bool IsValidDeviceName(const std::string& name);
bool IsBalanceBoardName(const std::string& name); bool IsBalanceBoardName(const std::string& name);
bool IsNewWiimote(const std::string& identifier); bool IsNewWiimote(const std::string& identifier);
bool IsKnownDeviceId(const USBUtils::DeviceInfo&);
void HandleWiimoteSourceChange(unsigned int wiimote_number); void HandleWiimoteSourceChange(unsigned int wiimote_number);
#ifdef ANDROID #ifdef ANDROID