2016-11-11 00:33:52 +00:00
|
|
|
// Copyright 2017 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2016-11-11 00:33:52 +00:00
|
|
|
|
2019-11-24 00:15:52 +00:00
|
|
|
#include "UICommon/USBUtils.h"
|
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
2016-11-11 00:33:52 +00:00
|
|
|
#ifdef __LIBUSB__
|
|
|
|
#include <libusb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
2019-05-12 18:19:31 +00:00
|
|
|
#include "Core/LibusbUtils.h"
|
2016-11-11 00:33:52 +00:00
|
|
|
|
|
|
|
// Because opening and getting the device name from devices is slow, especially on Windows
|
|
|
|
// with usbdk, we cannot do that for every single device. We should however still show
|
|
|
|
// device names for known Wii peripherals.
|
2019-11-24 00:15:52 +00:00
|
|
|
static const std::map<std::pair<u16, u16>, std::string_view> s_wii_peripherals{{
|
2016-11-11 00:33:52 +00:00
|
|
|
{{0x046d, 0x0a03}, "Logitech Microphone"},
|
|
|
|
{{0x057e, 0x0308}, "Wii Speak"},
|
|
|
|
{{0x057e, 0x0309}, "Nintendo USB Microphone"},
|
|
|
|
{{0x057e, 0x030a}, "Ubisoft Motion Tracking Camera"},
|
|
|
|
{{0x0e6f, 0x0129}, "Disney Infinity Reader (Portal Device)"},
|
|
|
|
{{0x1430, 0x0100}, "Tony Hawk Ride Skateboard"},
|
|
|
|
{{0x1430, 0x0150}, "Skylanders Portal"},
|
|
|
|
{{0x1bad, 0x0004}, "Harmonix Guitar Controller"},
|
2022-01-06 08:46:05 +00:00
|
|
|
{{0x1bad, 0x3110}, "Rock Band Drum Set"},
|
2020-11-24 13:25:19 +00:00
|
|
|
{{0x1bad, 0x3138}, "Harmonix Drum Controller for Nintendo Wii"},
|
2022-01-06 08:42:19 +00:00
|
|
|
{{0x1bad, 0x3330}, "Harmonix RB3 Keyboard for Nintendo Wii"},
|
2020-11-24 13:25:19 +00:00
|
|
|
{{0x1bad, 0x3338}, "Harmonix RB3 MIDI Keyboard Interface for Nintendo Wii"},
|
2022-01-06 08:46:05 +00:00
|
|
|
{{0x1bad, 0x3430}, "Harmonix RB3 Mustang Guitar for Nintendo Wii"},
|
2020-11-24 13:25:19 +00:00
|
|
|
{{0x1bad, 0x3538}, "Harmonix RB3 MIDI Guitar Interface for Nintendo Wii"},
|
2016-11-11 00:33:52 +00:00
|
|
|
{{0x21a4, 0xac40}, "EA Active NFL"},
|
|
|
|
}};
|
|
|
|
|
|
|
|
namespace USBUtils
|
|
|
|
{
|
|
|
|
std::map<std::pair<u16, u16>, std::string> GetInsertedDevices()
|
|
|
|
{
|
|
|
|
std::map<std::pair<u16, u16>, std::string> devices;
|
|
|
|
|
|
|
|
#ifdef __LIBUSB__
|
2019-06-25 15:31:35 +00:00
|
|
|
LibusbUtils::Context context;
|
2019-05-12 18:19:31 +00:00
|
|
|
if (!context.IsValid())
|
2016-11-11 00:33:52 +00:00
|
|
|
return devices;
|
|
|
|
|
2019-05-12 18:19:31 +00:00
|
|
|
context.GetDeviceList([&](libusb_device* device) {
|
2016-11-11 00:33:52 +00:00
|
|
|
libusb_device_descriptor descr;
|
2019-05-12 18:19:31 +00:00
|
|
|
libusb_get_device_descriptor(device, &descr);
|
2016-11-11 00:33:52 +00:00
|
|
|
const std::pair<u16, u16> vid_pid{descr.idVendor, descr.idProduct};
|
|
|
|
devices[vid_pid] = GetDeviceName(vid_pid);
|
2019-05-12 18:19:31 +00:00
|
|
|
return true;
|
|
|
|
});
|
2016-11-11 00:33:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetDeviceName(const std::pair<u16, u16> vid_pid)
|
|
|
|
{
|
|
|
|
const auto iter = s_wii_peripherals.find(vid_pid);
|
2019-11-24 00:15:52 +00:00
|
|
|
const std::string_view device_name = iter == s_wii_peripherals.cend() ? "Unknown" : iter->second;
|
|
|
|
return fmt::format("{:04x}:{:04x} - {}", vid_pid.first, vid_pid.second, device_name);
|
2016-11-11 00:33:52 +00:00
|
|
|
}
|
|
|
|
} // namespace USBUtils
|