Add hidapi lib
This commit is contained in:
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -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
|
||||
|
||||
20
externals/hidapi/CMakeLists.txt
vendored
Normal file
20
externals/hidapi/CMakeLists.txt
vendored
Normal file
@@ -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)
|
||||
1
externals/hidapi/hidapi
vendored
Submodule
1
externals/hidapi/hidapi
vendored
Submodule
Submodule externals/hidapi/hidapi added at ad27b46170
@@ -11,14 +11,12 @@
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <hidapi.h>
|
||||
#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 {
|
||||
|
||||
|
||||
@@ -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<Input::ButtonDevice> JCButtonFactory::Create(const Common::Param
|
||||
LOG_ERROR(Input, "Unknown direction {}", direction_name);
|
||||
}
|
||||
return std::make_unique<JCMotionButton>(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<u16>(pad.motion);
|
||||
if (analog_x_axis == -1) {
|
||||
@@ -376,8 +376,7 @@ public:
|
||||
|
||||
std::tuple<Common::Vec3<float>, Common::Vec3<float>, Common::Vec3<float>,
|
||||
std::array<Common::Vec3f, 3>>
|
||||
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<JCAdapter::Joycons> adapter_)
|
||||
* @param params contains parameters for creating the device:
|
||||
* - "port": the nth jcpad on the adapter
|
||||
*/
|
||||
std::unique_ptr<Input::MotionDevice> JCMotionFactory::Create(
|
||||
const Common::ParamPackage& params) {
|
||||
std::unique_ptr<Input::MotionDevice> JCMotionFactory::Create(const Common::ParamPackage& params) {
|
||||
const int port = params.Get("port", 0);
|
||||
|
||||
return std::make_unique<JCMotion>(port, adapter.get());
|
||||
@@ -442,4 +440,4 @@ Common::ParamPackage JCMotionFactory::GetNextInput() {
|
||||
return params;
|
||||
}
|
||||
|
||||
} // namespace InputCommon
|
||||
} // namespace InputCommon
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user