diff options
| author | 2020-07-06 21:58:31 -0400 | |
|---|---|---|
| committer | 2020-07-06 21:58:31 -0400 | |
| commit | 7ad423923dddb5e037d54e70cb066b03f8346dec (patch) | |
| tree | 5907a594637850d69e46fd26ae44da39264231d5 /src/input_common/gcadapter/gc_adapter.cpp | |
| parent | Merge pull request #4194 from ReinUsesLisp/fix-shader-cache (diff) | |
| download | yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.gz yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.tar.xz yuzu-7ad423923dddb5e037d54e70cb066b03f8346dec.zip | |
Save origin state of GC controller analog features, compare against origin for input detection
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index b39d2a3fb..8465309d0 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -25,19 +25,15 @@ Adapter::Adapter() { | |||
| 25 | 25 | ||
| 26 | current_status = NO_ADAPTER_DETECTED; | 26 | current_status = NO_ADAPTER_DETECTED; |
| 27 | libusb_init(&libusb_ctx); | 27 | libusb_init(&libusb_ctx); |
| 28 | get_origin.fill(true); | ||
| 28 | 29 | ||
| 29 | StartScanThread(); | 30 | StartScanThread(); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { | 33 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { |
| 33 | GCPadStatus pad = {}; | 34 | GCPadStatus pad = {}; |
| 34 | bool get_origin = false; | ||
| 35 | 35 | ||
| 36 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); | 36 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); |
| 37 | if (type != ControllerTypes::None) { | ||
| 38 | get_origin = true; | ||
| 39 | } | ||
| 40 | |||
| 41 | adapter_controllers_status[port] = type; | 37 | adapter_controllers_status[port] = type; |
| 42 | 38 | ||
| 43 | static constexpr std::array<PadButton, 8> b1_buttons{ | 39 | static constexpr std::array<PadButton, 8> b1_buttons{ |
| @@ -69,16 +65,22 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa | |||
| 69 | } | 65 | } |
| 70 | } | 66 | } |
| 71 | 67 | ||
| 72 | if (get_origin) { | ||
| 73 | pad.button |= PAD_GET_ORIGIN; | ||
| 74 | } | ||
| 75 | |||
| 76 | pad.stick_x = adapter_payload[1 + (9 * port) + 3]; | 68 | pad.stick_x = adapter_payload[1 + (9 * port) + 3]; |
| 77 | pad.stick_y = adapter_payload[1 + (9 * port) + 4]; | 69 | pad.stick_y = adapter_payload[1 + (9 * port) + 4]; |
| 78 | pad.substick_x = adapter_payload[1 + (9 * port) + 5]; | 70 | pad.substick_x = adapter_payload[1 + (9 * port) + 5]; |
| 79 | pad.substick_y = adapter_payload[1 + (9 * port) + 6]; | 71 | pad.substick_y = adapter_payload[1 + (9 * port) + 6]; |
| 80 | pad.trigger_left = adapter_payload[1 + (9 * port) + 7]; | 72 | pad.trigger_left = adapter_payload[1 + (9 * port) + 7]; |
| 81 | pad.trigger_right = adapter_payload[1 + (9 * port) + 8]; | 73 | pad.trigger_right = adapter_payload[1 + (9 * port) + 8]; |
| 74 | |||
| 75 | if (get_origin[port]) { | ||
| 76 | origin_status[port].stick_x = pad.stick_x; | ||
| 77 | origin_status[port].stick_y = pad.stick_y; | ||
| 78 | origin_status[port].substick_x = pad.substick_x; | ||
| 79 | origin_status[port].substick_y = pad.substick_y; | ||
| 80 | origin_status[port].trigger_left = pad.trigger_left; | ||
| 81 | origin_status[port].trigger_right = pad.trigger_right; | ||
| 82 | get_origin[port] = false; | ||
| 83 | } | ||
| 82 | } | 84 | } |
| 83 | return pad; | 85 | return pad; |
| 84 | } | 86 | } |
| @@ -127,31 +129,31 @@ void Adapter::Read() { | |||
| 127 | for (std::size_t port = 0; port < pads.size(); ++port) { | 129 | for (std::size_t port = 0; port < pads.size(); ++port) { |
| 128 | pads[port] = GetPadStatus(port, adapter_payload_copy); | 130 | pads[port] = GetPadStatus(port, adapter_payload_copy); |
| 129 | if (DeviceConnected(port) && configuring) { | 131 | if (DeviceConnected(port) && configuring) { |
| 130 | if (pads[port].button != PAD_GET_ORIGIN) { | 132 | if (pads[port].button != 0) { |
| 131 | pad_queue[port].Push(pads[port]); | 133 | pad_queue[port].Push(pads[port]); |
| 132 | } | 134 | } |
| 133 | 135 | ||
| 134 | // Accounting for a threshold here because of some controller variance | 136 | // Accounting for a threshold here because of some controller variance |
| 135 | if (pads[port].stick_x > pads[port].MAIN_STICK_CENTER_X + pads[port].THRESHOLD || | 137 | if (pads[port].stick_x > origin_status[port].stick_x + pads[port].THRESHOLD || |
| 136 | pads[port].stick_x < pads[port].MAIN_STICK_CENTER_X - pads[port].THRESHOLD) { | 138 | pads[port].stick_x < origin_status[port].stick_x - pads[port].THRESHOLD) { |
| 137 | pads[port].axis = GCAdapter::PadAxes::StickX; | 139 | pads[port].axis = GCAdapter::PadAxes::StickX; |
| 138 | pads[port].axis_value = pads[port].stick_x; | 140 | pads[port].axis_value = pads[port].stick_x; |
| 139 | pad_queue[port].Push(pads[port]); | 141 | pad_queue[port].Push(pads[port]); |
| 140 | } | 142 | } |
| 141 | if (pads[port].stick_y > pads[port].MAIN_STICK_CENTER_Y + pads[port].THRESHOLD || | 143 | if (pads[port].stick_y > origin_status[port].stick_y + pads[port].THRESHOLD || |
| 142 | pads[port].stick_y < pads[port].MAIN_STICK_CENTER_Y - pads[port].THRESHOLD) { | 144 | pads[port].stick_y < origin_status[port].stick_y - pads[port].THRESHOLD) { |
| 143 | pads[port].axis = GCAdapter::PadAxes::StickY; | 145 | pads[port].axis = GCAdapter::PadAxes::StickY; |
| 144 | pads[port].axis_value = pads[port].stick_y; | 146 | pads[port].axis_value = pads[port].stick_y; |
| 145 | pad_queue[port].Push(pads[port]); | 147 | pad_queue[port].Push(pads[port]); |
| 146 | } | 148 | } |
| 147 | if (pads[port].substick_x > pads[port].C_STICK_CENTER_X + pads[port].THRESHOLD || | 149 | if (pads[port].substick_x > origin_status[port].substick_x + pads[port].THRESHOLD || |
| 148 | pads[port].substick_x < pads[port].C_STICK_CENTER_X - pads[port].THRESHOLD) { | 150 | pads[port].substick_x < origin_status[port].substick_x - pads[port].THRESHOLD) { |
| 149 | pads[port].axis = GCAdapter::PadAxes::SubstickX; | 151 | pads[port].axis = GCAdapter::PadAxes::SubstickX; |
| 150 | pads[port].axis_value = pads[port].substick_x; | 152 | pads[port].axis_value = pads[port].substick_x; |
| 151 | pad_queue[port].Push(pads[port]); | 153 | pad_queue[port].Push(pads[port]); |
| 152 | } | 154 | } |
| 153 | if (pads[port].substick_y > pads[port].C_STICK_CENTER_Y + pads[port].THRESHOLD || | 155 | if (pads[port].substick_y > origin_status[port].substick_y + pads[port].THRESHOLD || |
| 154 | pads[port].substick_y < pads[port].C_STICK_CENTER_Y - pads[port].THRESHOLD) { | 156 | pads[port].substick_y < origin_status[port].substick_y - pads[port].THRESHOLD) { |
| 155 | pads[port].axis = GCAdapter::PadAxes::SubstickY; | 157 | pads[port].axis = GCAdapter::PadAxes::SubstickY; |
| 156 | pads[port].axis_value = pads[port].substick_y; | 158 | pads[port].axis_value = pads[port].substick_y; |
| 157 | pad_queue[port].Push(pads[port]); | 159 | pad_queue[port].Push(pads[port]); |
| @@ -325,6 +327,7 @@ void Adapter::Reset() { | |||
| 325 | adapter_input_thread.join(); | 327 | adapter_input_thread.join(); |
| 326 | 328 | ||
| 327 | adapter_controllers_status.fill(ControllerTypes::None); | 329 | adapter_controllers_status.fill(ControllerTypes::None); |
| 330 | get_origin.fill(true); | ||
| 328 | current_status = NO_ADAPTER_DETECTED; | 331 | current_status = NO_ADAPTER_DETECTED; |
| 329 | 332 | ||
| 330 | if (usb_adapter_handle) { | 333 | if (usb_adapter_handle) { |
| @@ -347,6 +350,7 @@ void Adapter::ResetDeviceType(int port) { | |||
| 347 | } | 350 | } |
| 348 | 351 | ||
| 349 | void Adapter::BeginConfiguration() { | 352 | void Adapter::BeginConfiguration() { |
| 353 | get_origin.fill(true); | ||
| 350 | for (auto& pq : pad_queue) { | 354 | for (auto& pq : pad_queue) { |
| 351 | pq.Clear(); | 355 | pq.Clear(); |
| 352 | } | 356 | } |
| @@ -376,4 +380,36 @@ const std::array<GCState, 4>& Adapter::GetPadState() const { | |||
| 376 | return state; | 380 | return state; |
| 377 | } | 381 | } |
| 378 | 382 | ||
| 383 | int Adapter::GetOriginValue(int port, int axis) { | ||
| 384 | const PadAxes padaxis = static_cast<PadAxes>(axis); | ||
| 385 | if (padaxis == PadAxes::StickX) | ||
| 386 | return origin_status[port].stick_x; | ||
| 387 | if (padaxis == PadAxes::StickY) | ||
| 388 | return origin_status[port].stick_y; | ||
| 389 | if (padaxis == PadAxes::SubstickX) | ||
| 390 | return origin_status[port].substick_x; | ||
| 391 | if (padaxis == PadAxes::SubstickY) | ||
| 392 | return origin_status[port].substick_x; | ||
| 393 | if (padaxis == PadAxes::TriggerLeft) | ||
| 394 | return origin_status[port].trigger_left; | ||
| 395 | if (padaxis == PadAxes::TriggerRight) | ||
| 396 | return origin_status[port].trigger_right; | ||
| 397 | } | ||
| 398 | |||
| 399 | const int Adapter::GetOriginValue(int port, int axis) const { | ||
| 400 | const PadAxes padaxis = static_cast<PadAxes>(axis); | ||
| 401 | if (padaxis == PadAxes::StickX) | ||
| 402 | return origin_status[port].stick_x; | ||
| 403 | if (padaxis == PadAxes::StickY) | ||
| 404 | return origin_status[port].stick_y; | ||
| 405 | if (padaxis == PadAxes::SubstickX) | ||
| 406 | return origin_status[port].substick_x; | ||
| 407 | if (padaxis == PadAxes::SubstickY) | ||
| 408 | return origin_status[port].substick_x; | ||
| 409 | if (padaxis == PadAxes::TriggerLeft) | ||
| 410 | return origin_status[port].trigger_left; | ||
| 411 | if (padaxis == PadAxes::TriggerRight) | ||
| 412 | return origin_status[port].trigger_right; | ||
| 413 | } | ||
| 414 | |||
| 379 | } // namespace GCAdapter | 415 | } // namespace GCAdapter |