diff --git a/.gitmodules b/.gitmodules index 732123b804..6d75029c3a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,9 +34,9 @@ [submodule "xbyak"] path = externals/xbyak url = https://github.com/herumi/xbyak.git -[submodule "externals/hidapi"] - path = externals/hidapi - url = https://github.com/german77/hidapi.git [submodule "opus"] path = externals/opus/opus url = https://github.com/xiph/opus.git +[submodule "externals/hidapi/hidapi"] + path = externals/hidapi/hidapi + url = https://github.com/libusb/hidapi.git diff --git a/externals/hidapi/CMakeLists.txt b/externals/hidapi/CMakeLists.txt new file mode 100644 index 0000000000..0a823921be --- /dev/null +++ b/externals/hidapi/CMakeLists.txt @@ -0,0 +1,20 @@ +project(hidapi) + +add_library(hidapi STATIC hidapi/hidapi/hidapi.h) +target_include_directories(hidapi PUBLIC hidapi/hidapi) + +if(APPLE) + target_sources(hidapi PRIVATE hidapi/mac/hid.c) +elseif(MSVC) + target_sources(hidapi PRIVATE hidapi/windows/hid.c) +else() + find_package(Libudev) + if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBUDEV_FOUND) + target_sources(hidapi PRIVATE hidapi/linux/hid.c) + target_link_libraries(hidapi PRIVATE hidapi/udev) + else() + target_sources(hidapi PRIVATE hidapi/libusb/hid.c) + endif() +endif() + +add_library(Hidapi::Hidapi ALIAS hidapi) diff --git a/externals/hidapi/hidapi b/externals/hidapi/hidapi new file mode 160000 index 0000000000..ad27b46170 --- /dev/null +++ b/externals/hidapi/hidapi @@ -0,0 +1 @@ +Subproject commit ad27b4617007cf2d824482e79193dc9557afeb1c diff --git a/src/input_common/joycon/jc_adapter.h b/src/input_common/joycon/jc_adapter.h index 478221b2d6..e0d1d4d948 100644 --- a/src/input_common/joycon/jc_adapter.h +++ b/src/input_common/joycon/jc_adapter.h @@ -11,14 +11,12 @@ #include #include #include -#include "common/quaternion.h" #include "common/param_package.h" #include "common/threadsafe_queue.h" #include "common/vector_math.h" +#include "input_common/main.h" #include "input_common/motion_input.h" #include "input_common/settings.h" -#include "input_common/main.h" - namespace JCAdapter { diff --git a/src/input_common/joycon/jc_poller.cpp b/src/input_common/joycon/jc_poller.cpp index edcc8bf739..1b437f7868 100644 --- a/src/input_common/joycon/jc_poller.cpp +++ b/src/input_common/joycon/jc_poller.cpp @@ -76,11 +76,11 @@ private: bool trigger_if_greater; JCAdapter::Joycons* jcadapter; }; -//Motion buttons are a temporary way to test motion +// Motion buttons are a temporary way to test motion class JCMotionButton final : public Input::ButtonDevice { public: explicit JCMotionButton(int port_, int axis_, float threshold_, bool trigger_if_greater_, - JCAdapter::Joycons* adapter) + JCAdapter::Joycons* adapter) : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_), jcadapter(adapter) {} @@ -163,7 +163,7 @@ std::unique_ptr JCButtonFactory::Create(const Common::Param LOG_ERROR(Input, "Unknown direction {}", direction_name); } return std::make_unique(port, axis, threshold, trigger_if_greater, - adapter.get()); + adapter.get()); } UNREACHABLE(); @@ -240,7 +240,7 @@ public: if (axis < 10) { return jcadapter->GetPadState(port).axes.at(axis); } else { - return jcadapter->GetPadState(port).motion.at(axis-10); + return jcadapter->GetPadState(port).motion.at(axis - 10); } } return 0.0f; @@ -343,7 +343,7 @@ Common::ParamPackage JCAnalogFactory::GetNextInput() { controller_number == port) { analog_y_axis = axis; } - }else if (pad.motion != JCAdapter::PadMotion::Undefined && + } else if (pad.motion != JCAdapter::PadMotion::Undefined && std::abs(pad.motion_value) > 1) { const u16 axis = 10 + static_cast(pad.motion); if (analog_x_axis == -1) { @@ -376,8 +376,7 @@ public: std::tuple, Common::Vec3, Common::Vec3, std::array> - GetStatus() - const override { + GetStatus() const override { auto motion = jcadapter->GetPadState(port).motion; if (motion.size() == 18) { auto gyroscope = Common::MakeVec(motion.at(0), motion.at(1), motion.at(2)); @@ -407,8 +406,7 @@ JCMotionFactory::JCMotionFactory(std::shared_ptr adapter_) * @param params contains parameters for creating the device: * - "port": the nth jcpad on the adapter */ -std::unique_ptr JCMotionFactory::Create( - const Common::ParamPackage& params) { +std::unique_ptr JCMotionFactory::Create(const Common::ParamPackage& params) { const int port = params.Get("port", 0); return std::make_unique(port, adapter.get()); @@ -442,4 +440,4 @@ Common::ParamPackage JCMotionFactory::GetNextInput() { return params; } -} // namespace InputCommon \ No newline at end of file +} // namespace InputCommon diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index d7986ccf35..7612b6aff0 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -139,7 +139,7 @@ struct InputSubsystem::Impl { } if (params.Get("class", "") == "gcpad") { return gcadapter->GetAnalogMappingForDevice(params); - } + } if (params.Get("class", "") == "jcpad") { return jcadapter->GetAnalogMappingForDevice(params); } @@ -158,7 +158,7 @@ struct InputSubsystem::Impl { } if (params.Get("class", "") == "gcpad") { return gcadapter->GetButtonMappingForDevice(params); - } + } if (params.Get("class", "") == "jcpad") { return jcadapter->GetButtonMappingForDevice(params); }