Use SDL3 built-in hidapi instead of libhidapi

This commit is contained in:
lijunyu-cn 2026-03-27 17:37:27 +08:00
parent ab0cec200e
commit 602726b1dd
5 changed files with 13 additions and 19 deletions

View File

@ -201,7 +201,6 @@ if (ENABLE_DISCORD_RPC)
endif()
if (ENABLE_HIDAPI)
find_package(hidapi REQUIRED)
set(SUPPORTS_WIIMOTE ON)
add_compile_definitions(HAS_HIDAPI)
endif ()

View File

@ -92,10 +92,6 @@ target_link_libraries(CemuInput PRIVATE
CemuGui
)
if (ENABLE_HIDAPI)
target_link_libraries(CemuInput PRIVATE hidapi::hidapi)
endif()
if (ENABLE_BLUEZ)
target_link_libraries(CemuInput PRIVATE bluez::bluez)
endif ()

View File

@ -7,18 +7,18 @@ static constexpr uint16 WIIMOTE_MP_PRODUCT_ID = 0x0330;
static constexpr uint16 WIIMOTE_MAX_INPUT_REPORT_LENGTH = 22;
static constexpr auto PRO_CONTROLLER_NAME = L"Nintendo RVL-CNT-01-UC";
HidapiWiimote::HidapiWiimote(hid_device* dev, std::string_view path)
HidapiWiimote::HidapiWiimote(SDL_hid_device* dev, std::string_view path)
: m_handle(dev), m_path(path) {
}
bool HidapiWiimote::write_data(const std::vector<uint8> &data) {
return hid_write(m_handle, data.data(), data.size()) >= 0;
return SDL_hid_write(m_handle, data.data(), data.size()) >= 0;
}
std::optional<std::vector<uint8>> HidapiWiimote::read_data() {
std::array<uint8, WIIMOTE_MAX_INPUT_REPORT_LENGTH> read_data{};
const auto result = hid_read(m_handle, read_data.data(), WIIMOTE_MAX_INPUT_REPORT_LENGTH);
const auto result = SDL_hid_read(m_handle, read_data.data(), WIIMOTE_MAX_INPUT_REPORT_LENGTH);
if (result < 0)
return {};
return {{read_data.cbegin(), read_data.cbegin() + result}};
@ -26,24 +26,24 @@ std::optional<std::vector<uint8>> HidapiWiimote::read_data() {
std::vector<WiimoteDevicePtr> HidapiWiimote::get_devices() {
std::vector<WiimoteDevicePtr> wiimote_devices;
hid_init();
const auto device_enumeration = hid_enumerate(WIIMOTE_VENDOR_ID, 0x0);
SDL_hid_init();
const auto device_enumeration = SDL_hid_enumerate(WIIMOTE_VENDOR_ID, 0x0);
for (auto it = device_enumeration; it != nullptr; it = it->next){
if (it->product_id != WIIMOTE_PRODUCT_ID && it->product_id != WIIMOTE_MP_PRODUCT_ID)
continue;
if (std::wcscmp(it->product_string, PRO_CONTROLLER_NAME) == 0)
continue;
auto dev = hid_open_path(it->path);
auto dev = SDL_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)));
cemuLog_logDebug(LogType::Force, "Unable to open Wiimote device at {}: {}", it->path, SDL_GetError());
}
else {
hid_set_nonblocking(dev, true);
SDL_hid_set_nonblocking(dev, true);
wiimote_devices.push_back(std::make_shared<HidapiWiimote>(dev, it->path));
}
}
hid_free_enumeration(device_enumeration);
SDL_hid_free_enumeration(device_enumeration);
return wiimote_devices;
}
@ -55,5 +55,5 @@ bool HidapiWiimote::operator==(const WiimoteDevice& rhs) const {
}
HidapiWiimote::~HidapiWiimote() {
hid_close(m_handle);
SDL_hid_close(m_handle);
}

View File

@ -1,11 +1,11 @@
#pragma once
#include <api/Wiimote/WiimoteDevice.h>
#include <hidapi.h>
#include <SDL3/SDL.h>
class HidapiWiimote : public WiimoteDevice {
public:
HidapiWiimote(hid_device* dev, std::string_view path);
HidapiWiimote(SDL_hid_device* dev, std::string_view path);
~HidapiWiimote() override;
bool write_data(const std::vector<uint8> &data) override;
@ -15,7 +15,7 @@ public:
static std::vector<WiimoteDevicePtr> get_devices();
private:
hid_device* m_handle;
SDL_hid_device* m_handle;
const std::string m_path;
};

View File

@ -32,7 +32,6 @@
"name": "fmt",
"version>=": "12.1.0"
},
"hidapi",
"libpng",
"glm",
{