diff options
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 89c148aba..c95feb0d7 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | namespace GCAdapter { | 22 | namespace GCAdapter { |
| 23 | 23 | ||
| 24 | /// Used to loop through and assign button in poller | 24 | // Used to loop through and assign button in poller |
| 25 | constexpr std::array<PadButton, 12> PadButtonArray{ | 25 | constexpr std::array<PadButton, 12> PadButtonArray{ |
| 26 | PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, | 26 | PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, |
| 27 | PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, | 27 | PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, |
| @@ -29,6 +29,18 @@ constexpr std::array<PadButton, 12> PadButtonArray{ | |||
| 29 | PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START, | 29 | PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START, |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | static void PadToState(const GCPadStatus& pad, GCState& out_state) { | ||
| 33 | for (const auto& button : PadButtonArray) { | ||
| 34 | const auto button_key = static_cast<u16>(button); | ||
| 35 | const auto button_value = (pad.button & button_key) != 0; | ||
| 36 | out_state.buttons.insert_or_assign(static_cast<s32>(button_key), button_value); | ||
| 37 | } | ||
| 38 | |||
| 39 | for (std::size_t i = 0; i < pad.axis_values.size(); ++i) { | ||
| 40 | out_state.axes.insert_or_assign(static_cast<u32>(i), pad.axis_values[i]); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 32 | Adapter::Adapter() { | 44 | Adapter::Adapter() { |
| 33 | if (usb_adapter_handle != nullptr) { | 45 | if (usb_adapter_handle != nullptr) { |
| 34 | return; | 46 | return; |
| @@ -78,17 +90,17 @@ GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& ad | |||
| 78 | 90 | ||
| 79 | for (std::size_t i = 0; i < b1_buttons.size(); ++i) { | 91 | for (std::size_t i = 0; i < b1_buttons.size(); ++i) { |
| 80 | if ((b1 & (1U << i)) != 0) { | 92 | if ((b1 & (1U << i)) != 0) { |
| 81 | pad.button |= static_cast<u16>(b1_buttons[i]); | 93 | pad.button = static_cast<u16>(pad.button | static_cast<u16>(b1_buttons[i])); |
| 82 | } | 94 | } |
| 83 | } | 95 | } |
| 84 | 96 | ||
| 85 | for (std::size_t j = 0; j < b2_buttons.size(); ++j) { | 97 | for (std::size_t j = 0; j < b2_buttons.size(); ++j) { |
| 86 | if ((b2 & (1U << j)) != 0) { | 98 | if ((b2 & (1U << j)) != 0) { |
| 87 | pad.button |= static_cast<u16>(b2_buttons[j]); | 99 | pad.button = static_cast<u16>(pad.button | static_cast<u16>(b2_buttons[j])); |
| 88 | } | 100 | } |
| 89 | } | 101 | } |
| 90 | for (PadAxes axis : axes) { | 102 | for (PadAxes axis : axes) { |
| 91 | const std::size_t index = static_cast<std::size_t>(axis); | 103 | const auto index = static_cast<std::size_t>(axis); |
| 92 | pad.axis_values[index] = adapter_payload[offset + 3 + index]; | 104 | pad.axis_values[index] = adapter_payload[offset + 3 + index]; |
| 93 | } | 105 | } |
| 94 | 106 | ||
| @@ -100,17 +112,6 @@ GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array<u8, 37>& ad | |||
| 100 | return pad; | 112 | return pad; |
| 101 | } | 113 | } |
| 102 | 114 | ||
| 103 | void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { | ||
| 104 | for (const auto& button : PadButtonArray) { | ||
| 105 | const u16 button_value = static_cast<u16>(button); | ||
| 106 | state.buttons.insert_or_assign(button_value, pad.button & button_value); | ||
| 107 | } | ||
| 108 | |||
| 109 | for (size_t i = 0; i < pad.axis_values.size(); ++i) { | ||
| 110 | state.axes.insert_or_assign(static_cast<u8>(i), pad.axis_values[i]); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void Adapter::Read() { | 115 | void Adapter::Read() { |
| 115 | LOG_DEBUG(Input, "GC Adapter Read() thread started"); | 116 | LOG_DEBUG(Input, "GC Adapter Read() thread started"); |
| 116 | 117 | ||
| @@ -250,7 +251,7 @@ void Adapter::GetGCEndpoint(libusb_device* device) { | |||
| 250 | const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; | 251 | const libusb_interface_descriptor* interface = &interfaceContainer->altsetting[i]; |
| 251 | for (u8 e = 0; e < interface->bNumEndpoints; e++) { | 252 | for (u8 e = 0; e < interface->bNumEndpoints; e++) { |
| 252 | const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; | 253 | const libusb_endpoint_descriptor* endpoint = &interface->endpoint[e]; |
| 253 | if (endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) { | 254 | if ((endpoint->bEndpointAddress & LIBUSB_ENDPOINT_IN) != 0) { |
| 254 | input_endpoint = endpoint->bEndpointAddress; | 255 | input_endpoint = endpoint->bEndpointAddress; |
| 255 | } else { | 256 | } else { |
| 256 | output_endpoint = endpoint->bEndpointAddress; | 257 | output_endpoint = endpoint->bEndpointAddress; |
| @@ -419,7 +420,7 @@ const std::array<GCState, 4>& Adapter::GetPadState() const { | |||
| 419 | return state; | 420 | return state; |
| 420 | } | 421 | } |
| 421 | 422 | ||
| 422 | int Adapter::GetOriginValue(int port, int axis) const { | 423 | int Adapter::GetOriginValue(u32 port, u32 axis) const { |
| 423 | return origin_status[port].axis_values[axis]; | 424 | return origin_status[port].axis_values[axis]; |
| 424 | } | 425 | } |
| 425 | 426 | ||