From 48ff15602e89ee2b7946310dd343859d56795a67 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Thu, 9 Jul 2020 14:56:56 +0000 Subject: cmake: pass libusb include directory as well In file included from src/input_common/gcadapter/gc_adapter.cpp:8: src/./input_common/gcadapter/gc_adapter.h:11:10: fatal error: 'libusb.h' file not found #include ^~~~~~~~~~ --- src/input_common/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'src/input_common') diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 3bd76dd23..1d7e19a66 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -30,6 +30,7 @@ if(SDL2_FOUND) target_compile_definitions(input_common PRIVATE HAVE_SDL2) endif() +target_include_directories(input_common SYSTEM PUBLIC ${LIBUSB_INCLUDE_DIR}) target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) create_target_directory_groups(input_common) -- cgit v1.2.3 From 9ce6ea648f7cb51f5411d3e0753ef9a3439381c5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:36:27 -0400 Subject: gc_adapter: Silence sign conversion warnings --- src/input_common/gcadapter/gc_adapter.cpp | 8 ++++---- src/input_common/gcadapter/gc_adapter.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 6d9f4d9eb..9fa170711 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -33,7 +33,7 @@ Adapter::Adapter() { } } -GCPadStatus Adapter::GetPadStatus(int port, const std::array& adapter_payload) { +GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array& adapter_payload) { GCPadStatus pad = {}; bool get_origin = false; @@ -227,7 +227,7 @@ void Adapter::Setup() { } if (devices != nullptr) { - for (std::size_t index = 0; index < device_count; ++index) { + for (std::size_t index = 0; index < static_cast(device_count); ++index) { if (CheckDeviceAccess(devices[index])) { // GC Adapter found and accessible, registering it GetGCEndpoint(devices[index]); @@ -357,11 +357,11 @@ void Adapter::Reset() { } } -bool Adapter::DeviceConnected(int port) { +bool Adapter::DeviceConnected(std::size_t port) { return adapter_controllers_status[port] != ControllerTypes::None; } -void Adapter::ResetDeviceType(int port) { +void Adapter::ResetDeviceType(std::size_t port) { adapter_controllers_status[port] = ControllerTypes::None; } diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index b1c2a1958..250c2275a 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -104,7 +104,7 @@ public: const std::array& GetPadState() const; private: - GCPadStatus GetPadStatus(int port, const std::array& adapter_payload); + GCPadStatus GetPadStatus(std::size_t port, const std::array& adapter_payload); void PadToState(const GCPadStatus& pad, GCState& state); @@ -117,10 +117,10 @@ private: void StopScanThread(); /// Returns true if there is a device connected to port - bool DeviceConnected(int port); + bool DeviceConnected(std::size_t port); /// Resets status of device connected to port - void ResetDeviceType(int port); + void ResetDeviceType(std::size_t port); /// Returns true if we successfully gain access to GC Adapter bool CheckDeviceAccess(libusb_device* device); -- cgit v1.2.3 From 32b6fc40622a838d4785d5e2dbea4ee17447c362 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:38:16 -0400 Subject: gc_adapter: Remove deprecated usage of = in lambda captures It's deprecated in C++20 to use = to capture the this pointer. Instead, we can simply pass this as an argument to the thread constructor. --- src/input_common/gcadapter/gc_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input_common') diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 9fa170711..70d382bcf 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -198,7 +198,7 @@ void Adapter::StartScanThread() { } detect_thread_running = true; - detect_thread = std::thread([=] { ScanThreadFunc(); }); + detect_thread = std::thread(&Adapter::ScanThreadFunc, this); } void Adapter::StopScanThread() { -- cgit v1.2.3 From a8ba6dc3c9f876835d706d90b27249e2984d526e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:40:22 -0400 Subject: gc_poller: Silence sign conversion warnings --- src/input_common/gcadapter/gc_poller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input_common') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 385ce8430..ead1a1b0e 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -249,7 +249,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { const u8 axis = static_cast(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; - controller_number = port; + controller_number = static_cast(port); } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { analog_y_axis = axis; } -- cgit v1.2.3 From 839c91cd14d65d0d62a946078aa62657530fd55a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:41:32 -0400 Subject: gc_poller: Get rid of undefined behavior in Create() Ensures that the function always has returns in all control paths. --- src/input_common/gcadapter/gc_poller.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/input_common') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index ead1a1b0e..d9296c496 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "common/assert.h" #include "common/threadsafe_queue.h" #include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" @@ -94,6 +95,9 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param return std::make_unique(port, axis, threshold, trigger_if_greater, adapter.get()); } + + UNREACHABLE(); + return nullptr; } Common::ParamPackage GCButtonFactory::GetNextInput() { -- cgit v1.2.3 From a1dddca4ab83cb63463134db11ed3585d8bd91f1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:43:05 -0400 Subject: gc_poller: Mark GCButtonFactory::GetNextInput() as const This doesn't modify class instance state. --- src/input_common/gcadapter/gc_poller.cpp | 2 +- src/input_common/gcadapter/gc_poller.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index d9296c496..bddfa102f 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -100,7 +100,7 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param return nullptr; } -Common::ParamPackage GCButtonFactory::GetNextInput() { +Common::ParamPackage GCButtonFactory::GetNextInput() const { Common::ParamPackage params; GCAdapter::GCPadStatus pad; auto& queue = adapter->GetPadQueue(); diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index e96af7d51..0527f328f 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h @@ -25,7 +25,7 @@ public: */ std::unique_ptr Create(const Common::ParamPackage& params) override; - Common::ParamPackage GetNextInput(); + Common::ParamPackage GetNextInput() const; /// For device input configuration/polling void BeginConfiguration(); -- cgit v1.2.3 From 8df93132cd0d0c3129e27a0e86edbfba7caa7196 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:49:40 -0400 Subject: udp: Silence a C++20 deprecation warning C++20 deprecates using the = lambda capture to implicitly capture the this pointer. Instead, we must specify it explicitly. --- src/input_common/udp/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input_common') diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index da5227058..e63c73c4f 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -234,7 +234,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( std::function status_callback, std::function data_callback) { - std::thread([=] { + std::thread([=, this] { constexpr u16 CALIBRATION_THRESHOLD = 100; u16 min_x{UINT16_MAX}; -- cgit v1.2.3 From 883fab2fff5ff9bdad38eee4e55bacc520ce0cc9 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 13 Jul 2020 18:48:19 +0000 Subject: input_common: make libusb private to gc_adapter --- src/input_common/CMakeLists.txt | 4 ++-- src/input_common/gcadapter/gc_adapter.cpp | 1 + src/input_common/gcadapter/gc_adapter.h | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 1d7e19a66..317c25bad 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -30,8 +30,8 @@ if(SDL2_FOUND) target_compile_definitions(input_common PRIVATE HAVE_SDL2) endif() -target_include_directories(input_common SYSTEM PUBLIC ${LIBUSB_INCLUDE_DIR}) -target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) +target_include_directories(input_common SYSTEM PRIVATE ${LIBUSB_INCLUDE_DIR}) +target_link_libraries(input_common PRIVATE ${LIBUSB_LIBRARIES}) create_target_directory_groups(input_common) target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost) diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 6d9f4d9eb..c031fc22a 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "common/logging/log.h" #include "input_common/gcadapter/gc_adapter.h" diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index b1c2a1958..1337c260e 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -8,10 +8,13 @@ #include #include #include -#include #include "common/common_types.h" #include "common/threadsafe_queue.h" +struct libusb_context; +struct libusb_device; +struct libusb_device_handle; + namespace GCAdapter { enum { -- cgit v1.2.3 From b284c433850053dca46d2e2381b16b17d38cd048 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 14 Jul 2020 01:46:54 +0000 Subject: input_common: drop unused libusb.h include Remnant of an early implementation. --- src/input_common/main.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/input_common') diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index fd0af1019..b9d5d0ec3 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "common/param_package.h" #include "input_common/analog_from_button.h" #include "input_common/gcadapter/gc_adapter.h" -- cgit v1.2.3 From ab65de2f96984415cbeb3fee392b930c61f0d8b4 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 14 Jul 2020 11:23:10 -0400 Subject: Fix crash if gc configured but adapter not connected --- src/input_common/gcadapter/gc_adapter.h | 6 +++--- src/input_common/gcadapter/gc_poller.cpp | 34 +++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 120ce4c02..e2cdd6255 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -100,6 +100,9 @@ public: void BeginConfiguration(); void EndConfiguration(); + /// Returns true if there is a device connected to port + bool DeviceConnected(std::size_t port); + std::array, 4>& GetPadQueue(); const std::array, 4>& GetPadQueue() const; @@ -119,9 +122,6 @@ private: /// Stop scanning for the adapter void StopScanThread(); - /// Returns true if there is a device connected to port - bool DeviceConnected(std::size_t port); - /// Resets status of device connected to port void ResetDeviceType(std::size_t port); diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index bddfa102f..b20419ec3 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -21,7 +21,10 @@ public: ~GCButton() override; bool GetStatus() const override { - return gcadapter->GetPadState()[port].buttons.at(button); + if (gcadapter->DeviceConnected(port)) { + return gcadapter->GetPadState()[port].buttons.at(button); + } + return false; } private: @@ -44,13 +47,17 @@ public: } bool GetStatus() const override { - const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; - if (trigger_if_greater) { - // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently - // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick - return axis_value > threshold; + if (gcadapter->DeviceConnected(port)) { + const float axis_value = + (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; + if (trigger_if_greater) { + // TODO: Might be worthwile to set a slider for the trigger threshold. It is + // currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick + return axis_value > threshold; + } + return axis_value < -threshold; } - return axis_value < -threshold; + return false; } private: @@ -151,11 +158,14 @@ public: : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} float GetAxis(int axis) const { - std::lock_guard lock{mutex}; - // division is not by a perfect 128 to account for some variance in center location - // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range - // [20-230] - return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; + if (gcadapter->DeviceConnected(port)) { + std::lock_guard lock{mutex}; + // division is not by a perfect 128 to account for some variance in center location + // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range + // [20-230] + return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; + } + return 0.0f; } std::pair GetAnalog(int axis_x, int axis_y) const { -- cgit v1.2.3