diff options
| author | 2020-06-21 15:31:57 -0400 | |
|---|---|---|
| committer | 2020-06-21 15:31:57 -0400 | |
| commit | c94583d867fd909d8731ba50e085352aae0e6885 (patch) | |
| tree | 9c691c1382d3317f45ad09cb43a93f9223fe379b /src/input_common | |
| parent | Cleanup after linter (diff) | |
| download | yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.gz yuzu-c94583d867fd909d8731ba50e085352aae0e6885.tar.xz yuzu-c94583d867fd909d8731ba50e085352aae0e6885.zip | |
Clang Formatting
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 90 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 16 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 56 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.h | 5 | ||||
| -rw-r--r-- | src/input_common/main.h | 3 | ||||
| -rw-r--r-- | src/input_common/udp/client.cpp | 6 |
6 files changed, 99 insertions, 77 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index d42261d61..dc04116ce 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | // Copyright 2014 Dolphin Emulator Project | 1 | // Copyright 2014 Dolphin Emulator Project |
| 2 | // Licensed under GPLv2+ | 2 | // Licensed under GPLv2+ |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | //* | 4 | |
| 5 | #include "common/logging/log.h" | 5 | #include "common/logging/log.h" |
| 6 | #include "common/threadsafe_queue.h" | 6 | #include "common/threadsafe_queue.h" |
| 7 | #include "input_common/gcadapter/gc_adapter.h" | 7 | #include "input_common/gcadapter/gc_adapter.h" |
| @@ -45,35 +45,48 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) { | |||
| 45 | u8 b1 = adapter_payload[1 + (9 * port) + 1]; | 45 | u8 b1 = adapter_payload[1 + (9 * port) + 1]; |
| 46 | u8 b2 = adapter_payload[1 + (9 * port) + 2]; | 46 | u8 b2 = adapter_payload[1 + (9 * port) + 2]; |
| 47 | 47 | ||
| 48 | if (b1 & (1 << 0)) | 48 | if (b1 & (1 << 0)) { |
| 49 | pad.button |= PAD_BUTTON_A; | 49 | pad.button |= PAD_BUTTON_A; |
| 50 | if (b1 & (1 << 1)) | 50 | } |
| 51 | if (b1 & (1 << 1)) { | ||
| 51 | pad.button |= PAD_BUTTON_B; | 52 | pad.button |= PAD_BUTTON_B; |
| 52 | if (b1 & (1 << 2)) | 53 | } |
| 54 | if (b1 & (1 << 2)) { | ||
| 53 | pad.button |= PAD_BUTTON_X; | 55 | pad.button |= PAD_BUTTON_X; |
| 54 | if (b1 & (1 << 3)) | 56 | } |
| 57 | if (b1 & (1 << 3)) { | ||
| 55 | pad.button |= PAD_BUTTON_Y; | 58 | pad.button |= PAD_BUTTON_Y; |
| 59 | } | ||
| 56 | 60 | ||
| 57 | if (b1 & (1 << 4)) | 61 | if (b1 & (1 << 4)) { |
| 58 | pad.button |= PAD_BUTTON_LEFT; | 62 | pad.button |= PAD_BUTTON_LEFT; |
| 59 | if (b1 & (1 << 5)) | 63 | } |
| 64 | if (b1 & (1 << 5)) { | ||
| 60 | pad.button |= PAD_BUTTON_RIGHT; | 65 | pad.button |= PAD_BUTTON_RIGHT; |
| 61 | if (b1 & (1 << 6)) | 66 | } |
| 67 | if (b1 & (1 << 6)) { | ||
| 62 | pad.button |= PAD_BUTTON_DOWN; | 68 | pad.button |= PAD_BUTTON_DOWN; |
| 63 | if (b1 & (1 << 7)) | 69 | } |
| 70 | if (b1 & (1 << 7)) { | ||
| 64 | pad.button |= PAD_BUTTON_UP; | 71 | pad.button |= PAD_BUTTON_UP; |
| 72 | } | ||
| 65 | 73 | ||
| 66 | if (b2 & (1 << 0)) | 74 | if (b2 & (1 << 0)) { |
| 67 | pad.button |= PAD_BUTTON_START; | 75 | pad.button |= PAD_BUTTON_START; |
| 68 | if (b2 & (1 << 1)) | 76 | } |
| 77 | if (b2 & (1 << 1)) { | ||
| 69 | pad.button |= PAD_TRIGGER_Z; | 78 | pad.button |= PAD_TRIGGER_Z; |
| 70 | if (b2 & (1 << 2)) | 79 | } |
| 80 | if (b2 & (1 << 2)) { | ||
| 71 | pad.button |= PAD_TRIGGER_R; | 81 | pad.button |= PAD_TRIGGER_R; |
| 72 | if (b2 & (1 << 3)) | 82 | } |
| 83 | if (b2 & (1 << 3)) { | ||
| 73 | pad.button |= PAD_TRIGGER_L; | 84 | pad.button |= PAD_TRIGGER_L; |
| 85 | } | ||
| 74 | 86 | ||
| 75 | if (get_origin) | 87 | if (get_origin) { |
| 76 | pad.button |= PAD_GET_ORIGIN; | 88 | pad.button |= PAD_GET_ORIGIN; |
| 89 | } | ||
| 77 | 90 | ||
| 78 | pad.stickX = adapter_payload[1 + (9 * port) + 3]; | 91 | pad.stickX = adapter_payload[1 + (9 * port) + 3]; |
| 79 | pad.stickY = adapter_payload[1 + (9 * port) + 4]; | 92 | pad.stickY = adapter_payload[1 + (9 * port) + 4]; |
| @@ -86,7 +99,7 @@ GCPadStatus CheckStatus(int port, u8 adapter_payload[37]) { | |||
| 86 | } | 99 | } |
| 87 | 100 | ||
| 88 | void PadToState(GCPadStatus pad, GCState& state) { | 101 | void PadToState(GCPadStatus pad, GCState& state) { |
| 89 | //std::lock_guard lock{s_mutex}; | 102 | // std::lock_guard lock{s_mutex}; |
| 90 | state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A); | 103 | state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A); |
| 91 | state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B); | 104 | state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B); |
| 92 | state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X); | 105 | state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X); |
| @@ -125,7 +138,7 @@ static void Read() { | |||
| 125 | std::begin(controller_payload_copy)); | 138 | std::begin(controller_payload_copy)); |
| 126 | payload_size = payload_size_in; | 139 | payload_size = payload_size_in; |
| 127 | } | 140 | } |
| 128 | 141 | ||
| 129 | GCPadStatus pad[4]; | 142 | GCPadStatus pad[4]; |
| 130 | if (payload_size != sizeof(controller_payload_copy) || | 143 | if (payload_size != sizeof(controller_payload_copy) || |
| 131 | controller_payload_copy[0] != LIBUSB_DT_HID) { | 144 | controller_payload_copy[0] != LIBUSB_DT_HID) { |
| @@ -137,8 +150,9 @@ static void Read() { | |||
| 137 | } | 150 | } |
| 138 | for (int port = 0; port < 4; port++) { | 151 | for (int port = 0; port < 4; port++) { |
| 139 | if (DeviceConnected(port) && configuring) { | 152 | if (DeviceConnected(port) && configuring) { |
| 140 | if (pad[port].button != PAD_GET_ORIGIN) | 153 | if (pad[port].button != PAD_GET_ORIGIN) { |
| 141 | pad_queue[port].Push(pad[port]); | 154 | pad_queue[port].Push(pad[port]); |
| 155 | } | ||
| 142 | 156 | ||
| 143 | // Accounting for a threshold here because of some controller variance | 157 | // Accounting for a threshold here because of some controller variance |
| 144 | if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD || | 158 | if (pad[port].stickX > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD || |
| @@ -186,8 +200,9 @@ static void ScanThreadFunc() { | |||
| 186 | 200 | ||
| 187 | void Init() { | 201 | void Init() { |
| 188 | 202 | ||
| 189 | if (usb_adapter_handle != nullptr) | 203 | if (usb_adapter_handle != nullptr) { |
| 190 | return; | 204 | return; |
| 205 | } | ||
| 191 | LOG_INFO(Input, "GC Adapter Initialization started"); | 206 | LOG_INFO(Input, "GC Adapter Initialization started"); |
| 192 | 207 | ||
| 193 | current_status = NO_ADAPTER_DETECTED; | 208 | current_status = NO_ADAPTER_DETECTED; |
| @@ -197,10 +212,12 @@ void Init() { | |||
| 197 | } | 212 | } |
| 198 | 213 | ||
| 199 | void StartScanThread() { | 214 | void StartScanThread() { |
| 200 | if (detect_thread_running) | 215 | if (detect_thread_running) { |
| 201 | return; | 216 | return; |
| 202 | if (!libusb_ctx) | 217 | } |
| 218 | if (!libusb_ctx) { | ||
| 203 | return; | 219 | return; |
| 220 | } | ||
| 204 | 221 | ||
| 205 | detect_thread_running = true; | 222 | detect_thread_running = true; |
| 206 | detect_thread = std::thread(ScanThreadFunc); | 223 | detect_thread = std::thread(ScanThreadFunc); |
| @@ -212,15 +229,17 @@ void StopScanThread() { | |||
| 212 | 229 | ||
| 213 | static void Setup() { | 230 | static void Setup() { |
| 214 | // Reset the error status in case the adapter gets unplugged | 231 | // Reset the error status in case the adapter gets unplugged |
| 215 | if (current_status < 0) | 232 | if (current_status < 0) { |
| 216 | current_status = NO_ADAPTER_DETECTED; | 233 | current_status = NO_ADAPTER_DETECTED; |
| 234 | } | ||
| 217 | 235 | ||
| 218 | for (int i = 0; i < 4; i++) | 236 | for (int i = 0; i < 4; i++) { |
| 219 | adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; | 237 | adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; |
| 220 | 238 | } | |
| 239 | |||
| 221 | libusb_device** devs; // pointer to list of connected usb devices | 240 | libusb_device** devs; // pointer to list of connected usb devices |
| 222 | 241 | ||
| 223 | int cnt = libusb_get_device_list(libusb_ctx, &devs); //get the list of devices | 242 | int cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices |
| 224 | 243 | ||
| 225 | for (int i = 0; i < cnt; i++) { | 244 | for (int i = 0; i < cnt; i++) { |
| 226 | if (CheckDeviceAccess(devs[i])) { | 245 | if (CheckDeviceAccess(devs[i])) { |
| @@ -247,9 +266,8 @@ static bool CheckDeviceAccess(libusb_device* device) { | |||
| 247 | ret = libusb_open(device, &usb_adapter_handle); | 266 | ret = libusb_open(device, &usb_adapter_handle); |
| 248 | 267 | ||
| 249 | if (ret == LIBUSB_ERROR_ACCESS) { | 268 | if (ret == LIBUSB_ERROR_ACCESS) { |
| 250 | LOG_ERROR(Input, | 269 | LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, |
| 251 | "Yuzu can not gain access to this device: ID %04X:%04X.", | 270 | desc.idProduct); |
| 252 | desc.idVendor, desc.idProduct); | ||
| 253 | return false; | 271 | return false; |
| 254 | } | 272 | } |
| 255 | if (ret) { | 273 | if (ret) { |
| @@ -260,8 +278,9 @@ static bool CheckDeviceAccess(libusb_device* device) { | |||
| 260 | ret = libusb_kernel_driver_active(usb_adapter_handle, 0); | 278 | ret = libusb_kernel_driver_active(usb_adapter_handle, 0); |
| 261 | if (ret == 1) { | 279 | if (ret == 1) { |
| 262 | ret = libusb_detach_kernel_driver(usb_adapter_handle, 0); | 280 | ret = libusb_detach_kernel_driver(usb_adapter_handle, 0); |
| 263 | if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) | 281 | if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { |
| 264 | LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", ret); | 282 | LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", ret); |
| 283 | } | ||
| 265 | } | 284 | } |
| 266 | 285 | ||
| 267 | if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { | 286 | if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { |
| @@ -290,8 +309,9 @@ static void GetGCEndpoint(libusb_device* device) { | |||
| 290 | const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; | 309 | const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; |
| 291 | for (u8 e = 0; e < interface->bNumEndpoints; e++) { | 310 | for (u8 e = 0; e < interface->bNumEndpoints; e++) { |
| 292 | const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; | 311 | const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; |
| 293 | if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) | 312 | if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) { |
| 294 | input_endpoint = endpoint->bEndpointAddress; | 313 | input_endpoint = endpoint->bEndpointAddress; |
| 314 | } | ||
| 295 | } | 315 | } |
| 296 | } | 316 | } |
| 297 | } | 317 | } |
| @@ -311,16 +331,20 @@ void Shutdown() { | |||
| 311 | 331 | ||
| 312 | static void Reset() { | 332 | static void Reset() { |
| 313 | std::unique_lock<std::mutex> lock(initialization_mutex, std::defer_lock); | 333 | std::unique_lock<std::mutex> lock(initialization_mutex, std::defer_lock); |
| 314 | if (!lock.try_lock()) | 334 | if (!lock.try_lock()) { |
| 315 | return; | 335 | return; |
| 316 | if (current_status != ADAPTER_DETECTED) | 336 | } |
| 337 | if (current_status != ADAPTER_DETECTED) { | ||
| 317 | return; | 338 | return; |
| 339 | } | ||
| 318 | 340 | ||
| 319 | if (adapter_thread_running) | 341 | if (adapter_thread_running) { |
| 320 | adapter_input_thread.join(); | 342 | adapter_input_thread.join(); |
| 343 | } | ||
| 321 | 344 | ||
| 322 | for (int i = 0; i < 4; i++) | 345 | for (int i = 0; i < 4; i++) { |
| 323 | adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; | 346 | adapter_controllers_status[i] = ControllerTypes::CONTROLLER_NONE; |
| 347 | } | ||
| 324 | 348 | ||
| 325 | current_status = NO_ADAPTER_DETECTED; | 349 | current_status = NO_ADAPTER_DETECTED; |
| 326 | 350 | ||
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 9b02d1382..05ee73c65 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -1,11 +1,14 @@ | |||
| 1 | // Copyright 2014 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2+ | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 1 | #pragma once | 5 | #pragma once |
| 2 | #include <algorithm> | 6 | #include <algorithm> |
| 3 | #include <libusb.h> | ||
| 4 | #include <mutex> | ||
| 5 | #include <functional> | 7 | #include <functional> |
| 8 | #include <mutex> | ||
| 9 | #include <libusb.h> | ||
| 6 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 7 | 11 | ||
| 8 | |||
| 9 | enum { | 12 | enum { |
| 10 | PAD_USE_ORIGIN = 0x0080, | 13 | PAD_USE_ORIGIN = 0x0080, |
| 11 | PAD_GET_ORIGIN = 0x2000, | 14 | PAD_GET_ORIGIN = 0x2000, |
| @@ -61,13 +64,8 @@ struct GCState { | |||
| 61 | std::unordered_map<int, u16> axes; | 64 | std::unordered_map<int, u16> axes; |
| 62 | }; | 65 | }; |
| 63 | 66 | ||
| 64 | |||
| 65 | namespace GCAdapter { | 67 | namespace GCAdapter { |
| 66 | enum ControllerTypes { | 68 | enum ControllerTypes { CONTROLLER_NONE = 0, CONTROLLER_WIRED = 1, CONTROLLER_WIRELESS = 2 }; |
| 67 | CONTROLLER_NONE = 0, | ||
| 68 | CONTROLLER_WIRED = 1, | ||
| 69 | CONTROLLER_WIRELESS = 2 | ||
| 70 | }; | ||
| 71 | 69 | ||
| 72 | enum { | 70 | enum { |
| 73 | NO_ADAPTER_DETECTED = 0, | 71 | NO_ADAPTER_DETECTED = 0, |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 772bd8890..51b3362d6 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -1,10 +1,14 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 1 | #include <atomic> | 5 | #include <atomic> |
| 2 | #include <list> | 6 | #include <list> |
| 3 | #include <mutex> | 7 | #include <mutex> |
| 4 | #include <utility> | 8 | #include <utility> |
| 5 | #include "input_common/gcadapter/gc_poller.h" | ||
| 6 | #include "input_common/gcadapter/gc_adapter.h" | ||
| 7 | #include "common/threadsafe_queue.h" | 9 | #include "common/threadsafe_queue.h" |
| 10 | #include "input_common/gcadapter/gc_adapter.h" | ||
| 11 | #include "input_common/gcadapter/gc_poller.h" | ||
| 8 | 12 | ||
| 9 | // Using extern as to avoid multply defined symbols. | 13 | // Using extern as to avoid multply defined symbols. |
| 10 | extern Common::SPSCQueue<GCPadStatus> pad_queue[4]; | 14 | extern Common::SPSCQueue<GCPadStatus> pad_queue[4]; |
| @@ -14,9 +18,7 @@ namespace InputCommon { | |||
| 14 | 18 | ||
| 15 | class GCButton final : public Input::ButtonDevice { | 19 | class GCButton final : public Input::ButtonDevice { |
| 16 | public: | 20 | public: |
| 17 | explicit GCButton(int port_, int button_, int axis_) | 21 | explicit GCButton(int port_, int button_, int axis_) : port(port_), button(button_) {} |
| 18 | : port(port_), button(button_) { | ||
| 19 | } | ||
| 20 | 22 | ||
| 21 | ~GCButton() override; | 23 | ~GCButton() override; |
| 22 | 24 | ||
| @@ -31,17 +33,14 @@ private: | |||
| 31 | 33 | ||
| 32 | class GCAxisButton final : public Input::ButtonDevice { | 34 | class GCAxisButton final : public Input::ButtonDevice { |
| 33 | public: | 35 | public: |
| 34 | explicit GCAxisButton(int port_, int axis_, float threshold_, | 36 | explicit GCAxisButton(int port_, int axis_, float threshold_, bool trigger_if_greater_) |
| 35 | bool trigger_if_greater_) | 37 | : port(port_), axis(axis_), threshold(threshold_), trigger_if_greater(trigger_if_greater_) { |
| 36 | : port(port_), axis(axis_), threshold(threshold_), | ||
| 37 | trigger_if_greater(trigger_if_greater_) { | ||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | |||
| 41 | bool GetStatus() const override { | 40 | bool GetStatus() const override { |
| 42 | const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; | 41 | const float axis_value = (state[port].axes.at(axis) - 128.0f) / 128.0f; |
| 43 | if (trigger_if_greater) { | 42 | if (trigger_if_greater) { |
| 44 | return axis_value > 0.10f; //TODO(ameerj) : Fix threshold. | 43 | return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. |
| 45 | } | 44 | } |
| 46 | return axis_value < -0.10f; | 45 | return axis_value < -0.10f; |
| 47 | } | 46 | } |
| @@ -164,29 +163,30 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { | |||
| 164 | 163 | ||
| 165 | void GCButtonFactory::BeginConfiguration() { | 164 | void GCButtonFactory::BeginConfiguration() { |
| 166 | polling = true; | 165 | polling = true; |
| 167 | for (int i = 0; i < 4; i++) | 166 | for (int i = 0; i < 4; i++) { |
| 168 | pad_queue[i].Clear(); | 167 | pad_queue[i].Clear(); |
| 168 | } | ||
| 169 | GCAdapter::BeginConfiguration(); | 169 | GCAdapter::BeginConfiguration(); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | void GCButtonFactory::EndConfiguration() { | 172 | void GCButtonFactory::EndConfiguration() { |
| 173 | polling = false; | 173 | polling = false; |
| 174 | 174 | for (int i = 0; i < 4; i++) { | |
| 175 | for (int i = 0; i < 4; i++) | ||
| 176 | pad_queue[i].Clear(); | 175 | pad_queue[i].Clear(); |
| 176 | } | ||
| 177 | GCAdapter::EndConfiguration(); | 177 | GCAdapter::EndConfiguration(); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | class GCAnalog final : public Input::AnalogDevice { | 180 | class GCAnalog final : public Input::AnalogDevice { |
| 181 | public: | 181 | public: |
| 182 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) | 182 | GCAnalog(int port_, int axis_x_, int axis_y_, float deadzone_) |
| 183 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) { | 183 | : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_) {} |
| 184 | } | ||
| 185 | 184 | ||
| 186 | float GetAxis(int axis) const { | 185 | float GetAxis(int axis) const { |
| 187 | std::lock_guard lock{mutex}; | 186 | std::lock_guard lock{mutex}; |
| 188 | // division is not by a perfect 128 to account for some variance in center location | 187 | // division is not by a perfect 128 to account for some variance in center location |
| 189 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range [20-230] | 188 | // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range |
| 189 | // [20-230] | ||
| 190 | return (state[port].axes.at(axis) - 128.0f) / 95.0f; | 190 | return (state[port].axes.at(axis) - 128.0f) / 95.0f; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| @@ -240,18 +240,16 @@ private: | |||
| 240 | mutable std::mutex mutex; | 240 | mutable std::mutex mutex; |
| 241 | }; | 241 | }; |
| 242 | 242 | ||
| 243 | |||
| 244 | /// An analog device factory that creates analog devices from GC Adapter | 243 | /// An analog device factory that creates analog devices from GC Adapter |
| 245 | GCAnalogFactory::GCAnalogFactory() {}; | 244 | GCAnalogFactory::GCAnalogFactory(){}; |
| 246 | |||
| 247 | 245 | ||
| 248 | /** | 246 | /** |
| 249 | * Creates analog device from joystick axes | 247 | * Creates analog device from joystick axes |
| 250 | * @param params contains parameters for creating the device: | 248 | * @param params contains parameters for creating the device: |
| 251 | * - "port": the nth gcpad on the adapter | 249 | * - "port": the nth gcpad on the adapter |
| 252 | * - "axis_x": the index of the axis to be bind as x-axis | 250 | * - "axis_x": the index of the axis to be bind as x-axis |
| 253 | * - "axis_y": the index of the axis to be bind as y-axis | 251 | * - "axis_y": the index of the axis to be bind as y-axis |
| 254 | */ | 252 | */ |
| 255 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { | 253 | std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::ParamPackage& params) { |
| 256 | const std::string guid = params.Get("guid", "0"); | 254 | const std::string guid = params.Get("guid", "0"); |
| 257 | const int port = params.Get("port", 0); | 255 | const int port = params.Get("port", 0); |
| @@ -264,15 +262,17 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param | |||
| 264 | 262 | ||
| 265 | void GCAnalogFactory::BeginConfiguration() { | 263 | void GCAnalogFactory::BeginConfiguration() { |
| 266 | polling = true; | 264 | polling = true; |
| 267 | for (int i = 0; i < 4; i++) | 265 | for (int i = 0; i < 4; i++) { |
| 268 | pad_queue[i].Clear(); | 266 | pad_queue[i].Clear(); |
| 267 | } | ||
| 269 | GCAdapter::BeginConfiguration(); | 268 | GCAdapter::BeginConfiguration(); |
| 270 | } | 269 | } |
| 271 | 270 | ||
| 272 | void GCAnalogFactory::EndConfiguration() { | 271 | void GCAnalogFactory::EndConfiguration() { |
| 273 | polling = false; | 272 | polling = false; |
| 274 | for (int i = 0; i < 4; i++) | 273 | for (int i = 0; i < 4; i++) { |
| 275 | pad_queue[i].Clear(); | 274 | pad_queue[i].Clear(); |
| 275 | } | ||
| 276 | GCAdapter::EndConfiguration(); | 276 | GCAdapter::EndConfiguration(); |
| 277 | } | 277 | } |
| 278 | 278 | ||
diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index d115b1d2a..43aa9e93a 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 1 | #pragma once | 5 | #pragma once |
| 2 | 6 | ||
| 3 | #include <memory> | 7 | #include <memory> |
| @@ -5,7 +9,6 @@ | |||
| 5 | 9 | ||
| 6 | namespace InputCommon { | 10 | namespace InputCommon { |
| 7 | 11 | ||
| 8 | |||
| 9 | /** | 12 | /** |
| 10 | * A button device factory representing a gcpad. It receives gcpad events and forward them | 13 | * A button device factory representing a gcpad. It receives gcpad events and forward them |
| 11 | * to all button devices it created. | 14 | * to all button devices it created. |
diff --git a/src/input_common/main.h b/src/input_common/main.h index be2e7a6c4..9e1528c88 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | #include "input_common/gcadapter/gc_poller.h" | ||
| 11 | #include "input_common/gcadapter/gc_adapter.h" | 10 | #include "input_common/gcadapter/gc_adapter.h" |
| 11 | #include "input_common/gcadapter/gc_poller.h" | ||
| 12 | 12 | ||
| 13 | namespace Common { | 13 | namespace Common { |
| 14 | class ParamPackage; | 14 | class ParamPackage; |
| @@ -38,7 +38,6 @@ class GCAnalogFactory; | |||
| 38 | GCButtonFactory* GetGCButtons(); | 38 | GCButtonFactory* GetGCButtons(); |
| 39 | GCAnalogFactory* GetGCAnalogs(); | 39 | GCAnalogFactory* GetGCAnalogs(); |
| 40 | 40 | ||
| 41 | |||
| 42 | /// Generates a serialized param package for creating a keyboard button device | 41 | /// Generates a serialized param package for creating a keyboard button device |
| 43 | std::string GenerateKeyboardParam(int key_code); | 42 | std::string GenerateKeyboardParam(int key_code); |
| 44 | 43 | ||
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index da5227058..4c9794ce2 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -225,8 +225,7 @@ void TestCommunication(const std::string& host, u16 port, u8 pad_index, u32 clie | |||
| 225 | } else { | 225 | } else { |
| 226 | failure_callback(); | 226 | failure_callback(); |
| 227 | } | 227 | } |
| 228 | }) | 228 | }).detach(); |
| 229 | .detach(); | ||
| 230 | } | 229 | } |
| 231 | 230 | ||
| 232 | CalibrationConfigurationJob::CalibrationConfigurationJob( | 231 | CalibrationConfigurationJob::CalibrationConfigurationJob( |
| @@ -280,8 +279,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( | |||
| 280 | complete_event.Wait(); | 279 | complete_event.Wait(); |
| 281 | socket.Stop(); | 280 | socket.Stop(); |
| 282 | worker_thread.join(); | 281 | worker_thread.join(); |
| 283 | }) | 282 | }).detach(); |
| 284 | .detach(); | ||
| 285 | } | 283 | } |
| 286 | 284 | ||
| 287 | CalibrationConfigurationJob::~CalibrationConfigurationJob() { | 285 | CalibrationConfigurationJob::~CalibrationConfigurationJob() { |