diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 11 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 15 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 45 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.h | 2 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 1 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 2 |
7 files changed, 48 insertions, 31 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 3bd76dd23..317c25bad 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -30,7 +30,8 @@ if(SDL2_FOUND) | |||
| 30 | target_compile_definitions(input_common PRIVATE HAVE_SDL2) | 30 | target_compile_definitions(input_common PRIVATE HAVE_SDL2) |
| 31 | endif() | 31 | endif() |
| 32 | 32 | ||
| 33 | target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) | 33 | target_include_directories(input_common SYSTEM PRIVATE ${LIBUSB_INCLUDE_DIR}) |
| 34 | target_link_libraries(input_common PRIVATE ${LIBUSB_LIBRARIES}) | ||
| 34 | 35 | ||
| 35 | create_target_directory_groups(input_common) | 36 | create_target_directory_groups(input_common) |
| 36 | target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost) | 37 | 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 05607e033..898a278a9 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <chrono> | 5 | #include <chrono> |
| 6 | #include <thread> | 6 | #include <thread> |
| 7 | #include <libusb.h> | ||
| 7 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 8 | #include "input_common/gcadapter/gc_adapter.h" | 9 | #include "input_common/gcadapter/gc_adapter.h" |
| 9 | 10 | ||
| @@ -34,7 +35,7 @@ Adapter::Adapter() { | |||
| 34 | } | 35 | } |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { | 38 | GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& adapter_payload) { |
| 38 | GCPadStatus pad = {}; | 39 | GCPadStatus pad = {}; |
| 39 | 40 | ||
| 40 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); | 41 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); |
| @@ -205,7 +206,7 @@ void Adapter::StartScanThread() { | |||
| 205 | } | 206 | } |
| 206 | 207 | ||
| 207 | detect_thread_running = true; | 208 | detect_thread_running = true; |
| 208 | detect_thread = std::thread([=] { ScanThreadFunc(); }); | 209 | detect_thread = std::thread(&Adapter::ScanThreadFunc, this); |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | void Adapter::StopScanThread() { | 212 | void Adapter::StopScanThread() { |
| @@ -234,7 +235,7 @@ void Adapter::Setup() { | |||
| 234 | } | 235 | } |
| 235 | 236 | ||
| 236 | if (devices != nullptr) { | 237 | if (devices != nullptr) { |
| 237 | for (std::size_t index = 0; index < device_count; ++index) { | 238 | for (std::size_t index = 0; index < static_cast<std::size_t>(device_count); ++index) { |
| 238 | if (CheckDeviceAccess(devices[index])) { | 239 | if (CheckDeviceAccess(devices[index])) { |
| 239 | // GC Adapter found and accessible, registering it | 240 | // GC Adapter found and accessible, registering it |
| 240 | GetGCEndpoint(devices[index]); | 241 | GetGCEndpoint(devices[index]); |
| @@ -368,11 +369,11 @@ void Adapter::Reset() { | |||
| 368 | } | 369 | } |
| 369 | } | 370 | } |
| 370 | 371 | ||
| 371 | bool Adapter::DeviceConnected(int port) { | 372 | bool Adapter::DeviceConnected(std::size_t port) { |
| 372 | return adapter_controllers_status[port] != ControllerTypes::None; | 373 | return adapter_controllers_status[port] != ControllerTypes::None; |
| 373 | } | 374 | } |
| 374 | 375 | ||
| 375 | void Adapter::ResetDeviceType(int port) { | 376 | void Adapter::ResetDeviceType(std::size_t port) { |
| 376 | adapter_controllers_status[port] = ControllerTypes::None; | 377 | adapter_controllers_status[port] = ControllerTypes::None; |
| 377 | } | 378 | } |
| 378 | 379 | ||
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index a67485586..3586c8bda 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -8,10 +8,13 @@ | |||
| 8 | #include <mutex> | 8 | #include <mutex> |
| 9 | #include <thread> | 9 | #include <thread> |
| 10 | #include <unordered_map> | 10 | #include <unordered_map> |
| 11 | #include <libusb.h> | ||
| 12 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 13 | #include "common/threadsafe_queue.h" | 12 | #include "common/threadsafe_queue.h" |
| 14 | 13 | ||
| 14 | struct libusb_context; | ||
| 15 | struct libusb_device; | ||
| 16 | struct libusb_device_handle; | ||
| 17 | |||
| 15 | namespace GCAdapter { | 18 | namespace GCAdapter { |
| 16 | 19 | ||
| 17 | enum class PadButton { | 20 | enum class PadButton { |
| @@ -91,6 +94,9 @@ public: | |||
| 91 | void BeginConfiguration(); | 94 | void BeginConfiguration(); |
| 92 | void EndConfiguration(); | 95 | void EndConfiguration(); |
| 93 | 96 | ||
| 97 | /// Returns true if there is a device connected to port | ||
| 98 | bool DeviceConnected(std::size_t port); | ||
| 99 | |||
| 94 | std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue(); | 100 | std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue(); |
| 95 | const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const; | 101 | const std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const; |
| 96 | 102 | ||
| @@ -100,7 +106,7 @@ public: | |||
| 100 | int GetOriginValue(int port, int axis) const; | 106 | int GetOriginValue(int port, int axis) const; |
| 101 | 107 | ||
| 102 | private: | 108 | private: |
| 103 | GCPadStatus GetPadStatus(int port, const std::array<u8, 37>& adapter_payload); | 109 | GCPadStatus GetPadStatus(std::size_t port, const std::array<u8, 37>& adapter_payload); |
| 104 | 110 | ||
| 105 | void PadToState(const GCPadStatus& pad, GCState& state); | 111 | void PadToState(const GCPadStatus& pad, GCState& state); |
| 106 | 112 | ||
| @@ -112,11 +118,8 @@ private: | |||
| 112 | /// Stop scanning for the adapter | 118 | /// Stop scanning for the adapter |
| 113 | void StopScanThread(); | 119 | void StopScanThread(); |
| 114 | 120 | ||
| 115 | /// Returns true if there is a device connected to port | ||
| 116 | bool DeviceConnected(int port); | ||
| 117 | |||
| 118 | /// Resets status of device connected to port | 121 | /// Resets status of device connected to port |
| 119 | void ResetDeviceType(int port); | 122 | void ResetDeviceType(std::size_t port); |
| 120 | 123 | ||
| 121 | /// Returns true if we successfully gain access to GC Adapter | 124 | /// Returns true if we successfully gain access to GC Adapter |
| 122 | bool CheckDeviceAccess(libusb_device* device); | 125 | bool CheckDeviceAccess(libusb_device* device); |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index ad321e933..96e22d3ad 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <list> | 6 | #include <list> |
| 7 | #include <mutex> | 7 | #include <mutex> |
| 8 | #include <utility> | 8 | #include <utility> |
| 9 | #include "common/assert.h" | ||
| 9 | #include "common/threadsafe_queue.h" | 10 | #include "common/threadsafe_queue.h" |
| 10 | #include "input_common/gcadapter/gc_adapter.h" | 11 | #include "input_common/gcadapter/gc_adapter.h" |
| 11 | #include "input_common/gcadapter/gc_poller.h" | 12 | #include "input_common/gcadapter/gc_poller.h" |
| @@ -20,7 +21,10 @@ public: | |||
| 20 | ~GCButton() override; | 21 | ~GCButton() override; |
| 21 | 22 | ||
| 22 | bool GetStatus() const override { | 23 | bool GetStatus() const override { |
| 23 | return gcadapter->GetPadState()[port].buttons.at(button); | 24 | if (gcadapter->DeviceConnected(port)) { |
| 25 | return gcadapter->GetPadState()[port].buttons.at(button); | ||
| 26 | } | ||
| 27 | return false; | ||
| 24 | } | 28 | } |
| 25 | 29 | ||
| 26 | private: | 30 | private: |
| @@ -37,14 +41,17 @@ public: | |||
| 37 | gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {} | 41 | gcadapter(adapter), origin_value(adapter->GetOriginValue(port_, axis_)) {} |
| 38 | 42 | ||
| 39 | bool GetStatus() const override { | 43 | bool GetStatus() const override { |
| 40 | const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis); | 44 | if (gcadapter->DeviceConnected(port)) { |
| 41 | const float axis_value = (current_axis_value - origin_value) / 128.0f; | 45 | const float current_axis_value = gcadapter->GetPadState()[port].axes.at(axis); |
| 42 | if (trigger_if_greater) { | 46 | const float axis_value = (current_axis_value - origin_value) / 128.0f; |
| 43 | // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently | 47 | if (trigger_if_greater) { |
| 44 | // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick | 48 | // TODO: Might be worthwile to set a slider for the trigger threshold. It is |
| 45 | return axis_value > threshold; | 49 | // currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick |
| 50 | return axis_value > threshold; | ||
| 51 | } | ||
| 52 | return axis_value < -threshold; | ||
| 46 | } | 53 | } |
| 47 | return axis_value < -threshold; | 54 | return false; |
| 48 | } | 55 | } |
| 49 | 56 | ||
| 50 | private: | 57 | private: |
| @@ -90,9 +97,12 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 90 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, | 97 | return std::make_unique<GCAxisButton>(port, axis, threshold, trigger_if_greater, |
| 91 | adapter.get()); | 98 | adapter.get()); |
| 92 | } | 99 | } |
| 100 | |||
| 101 | UNREACHABLE(); | ||
| 102 | return nullptr; | ||
| 93 | } | 103 | } |
| 94 | 104 | ||
| 95 | Common::ParamPackage GCButtonFactory::GetNextInput() { | 105 | Common::ParamPackage GCButtonFactory::GetNextInput() const { |
| 96 | Common::ParamPackage params; | 106 | Common::ParamPackage params; |
| 97 | GCAdapter::GCPadStatus pad; | 107 | GCAdapter::GCPadStatus pad; |
| 98 | auto& queue = adapter->GetPadQueue(); | 108 | auto& queue = adapter->GetPadQueue(); |
| @@ -145,12 +155,15 @@ public: | |||
| 145 | origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {} | 155 | origin_value_y(adapter->GetOriginValue(port_, axis_y_)) {} |
| 146 | 156 | ||
| 147 | float GetAxis(int axis) const { | 157 | float GetAxis(int axis) const { |
| 148 | std::lock_guard lock{mutex}; | 158 | if (gcadapter->DeviceConnected(port)) { |
| 149 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; | 159 | std::lock_guard lock{mutex}; |
| 150 | // division is not by a perfect 128 to account for some variance in center location | 160 | const auto origin_value = axis % 2 == 0 ? origin_value_x : origin_value_y; |
| 151 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range | 161 | // division is not by a perfect 128 to account for some variance in center location |
| 152 | // [20-230] | 162 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range |
| 153 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f; | 163 | // [20-230] |
| 164 | return (gcadapter->GetPadState()[port].axes.at(axis) - origin_value) / 95.0f; | ||
| 165 | } | ||
| 166 | return 0.0f; | ||
| 154 | } | 167 | } |
| 155 | 168 | ||
| 156 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { | 169 | std::pair<float, float> GetAnalog(int axis_x, int axis_y) const { |
| @@ -250,7 +263,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 250 | const u8 axis = static_cast<u8>(pad.axis); | 263 | const u8 axis = static_cast<u8>(pad.axis); |
| 251 | if (analog_x_axis == -1) { | 264 | if (analog_x_axis == -1) { |
| 252 | analog_x_axis = axis; | 265 | analog_x_axis = axis; |
| 253 | controller_number = port; | 266 | controller_number = static_cast<int>(port); |
| 254 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { | 267 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { |
| 255 | analog_y_axis = axis; | 268 | analog_y_axis = axis; |
| 256 | } | 269 | } |
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: | |||
| 25 | */ | 25 | */ |
| 26 | std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override; | 26 | std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override; |
| 27 | 27 | ||
| 28 | Common::ParamPackage GetNextInput(); | 28 | Common::ParamPackage GetNextInput() const; |
| 29 | 29 | ||
| 30 | /// For device input configuration/polling | 30 | /// For device input configuration/polling |
| 31 | void BeginConfiguration(); | 31 | void BeginConfiguration(); |
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 @@ | |||
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include <thread> | 6 | #include <thread> |
| 7 | #include <libusb.h> | ||
| 8 | #include "common/param_package.h" | 7 | #include "common/param_package.h" |
| 9 | #include "input_common/analog_from_button.h" | 8 | #include "input_common/analog_from_button.h" |
| 10 | #include "input_common/gcadapter/gc_adapter.h" | 9 | #include "input_common/gcadapter/gc_adapter.h" |
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( | |||
| 234 | std::function<void(Status)> status_callback, | 234 | std::function<void(Status)> status_callback, |
| 235 | std::function<void(u16, u16, u16, u16)> data_callback) { | 235 | std::function<void(u16, u16, u16, u16)> data_callback) { |
| 236 | 236 | ||
| 237 | std::thread([=] { | 237 | std::thread([=, this] { |
| 238 | constexpr u16 CALIBRATION_THRESHOLD = 100; | 238 | constexpr u16 CALIBRATION_THRESHOLD = 100; |
| 239 | 239 | ||
| 240 | u16 min_x{UINT16_MAX}; | 240 | u16 min_x{UINT16_MAX}; |