diff --git a/src/input/api/Wiimote/hidapi/HidapiWiimote.cpp b/src/input/api/Wiimote/hidapi/HidapiWiimote.cpp index 148f8ce33..26949e86b 100644 --- a/src/input/api/Wiimote/hidapi/HidapiWiimote.cpp +++ b/src/input/api/Wiimote/hidapi/HidapiWiimote.cpp @@ -4,8 +4,8 @@ static constexpr uint16 WIIMOTE_VENDOR_ID = 0x057e; static constexpr uint16 WIIMOTE_PRODUCT_ID = 0x0306; static constexpr uint16 WIIMOTE_MAX_INPUT_REPROT_LENGTH = 21; -HidapiWiimote::HidapiWiimote(fs::path const& device_path, uint64_t identifier) - : m_handle(hid_open_path(_pathToUtf8(device_path).c_str())), m_identifier(identifier) { +HidapiWiimote::HidapiWiimote(hid_device* dev, uint64_t identifier) + : m_handle(dev), m_identifier(identifier) { } @@ -27,11 +27,17 @@ std::vector HidapiWiimote::get_devices() { const auto device_enumeration = hid_enumerate(WIIMOTE_VENDOR_ID, WIIMOTE_PRODUCT_ID); auto it = device_enumeration; while (it){ - // Enough to have a unique id for each device within a session - uint64_t id = (static_cast(it->interface_number) << 32) | - (static_cast(it->usage_page) << 16) | - (it->usage); - wiimote_devices.push_back(std::make_shared(it->path, id)); + auto dev = hid_open_path(it->path); + if (!dev){ + cemuLog_logDebug(LogType::Force, "Unable to open Wiimote device at {}: {}", it->path, boost::nowide::narrow(hid_error(nullptr))); + } + else { + // Enough to have a unique id for each device within a session + uint64_t id = (static_cast(it->interface_number) << 32) | + (static_cast(it->usage_page) << 16) | + (it->usage); + wiimote_devices.push_back(std::make_shared(dev, id)); + } it = it->next; } hid_free_enumeration(device_enumeration); diff --git a/src/input/api/Wiimote/hidapi/HidapiWiimote.h b/src/input/api/Wiimote/hidapi/HidapiWiimote.h index 298556d65..6bd90dac7 100644 --- a/src/input/api/Wiimote/hidapi/HidapiWiimote.h +++ b/src/input/api/Wiimote/hidapi/HidapiWiimote.h @@ -5,7 +5,7 @@ class HidapiWiimote : public WiimoteDevice { public: - HidapiWiimote(fs::path const& device_path, uint64_t identifier); + HidapiWiimote(hid_device* dev, uint64_t identifier); ~HidapiWiimote() override; bool write_data(const std::vector &data) override;