diff options
| author | 2020-06-23 17:37:15 -0400 | |
|---|---|---|
| committer | 2020-06-23 17:37:15 -0400 | |
| commit | 743e1f02a06187164d55f4208b8e85742abd4498 (patch) | |
| tree | 6eeeaddbc7cc3dac770c1d2efada1f4e68394939 | |
| parent | Fix deallocation of GC Adapter (diff) | |
| download | yuzu-743e1f02a06187164d55f4208b8e85742abd4498.tar.gz yuzu-743e1f02a06187164d55f4208b8e85742abd4498.tar.xz yuzu-743e1f02a06187164d55f4208b8e85742abd4498.zip | |
cleanup check access, read, and factory GetNextInput funcs. Use size rather than magic number
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 169 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 8 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 74 | ||||
| -rw-r--r-- | src/input_common/keyboard.cpp | 1 |
4 files changed, 101 insertions, 151 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 887cde263..9437d628f 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -21,57 +21,38 @@ Adapter::Adapter() { | |||
| 21 | StartScanThread(); | 21 | StartScanThread(); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | GCPadStatus Adapter::CheckStatus(int port, const std::array<u8, 37>& adapter_payload) { | 24 | GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_payload) { |
| 25 | GCPadStatus pad = {}; | 25 | GCPadStatus pad = {}; |
| 26 | bool get_origin = false; | 26 | bool get_origin = false; |
| 27 | 27 | ||
| 28 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); | 28 | ControllerTypes type = ControllerTypes(adapter_payload[1 + (9 * port)] >> 4); |
| 29 | if (type != ControllerTypes::None) | 29 | if (type != ControllerTypes::None) { |
| 30 | get_origin = true; | 30 | get_origin = true; |
| 31 | } | ||
| 31 | 32 | ||
| 32 | adapter_controllers_status[port] = type; | 33 | adapter_controllers_status[port] = type; |
| 33 | 34 | ||
| 34 | if (adapter_controllers_status[port] != ControllerTypes::None) { | 35 | constexpr std::array<PadButton, 8> b1_buttons{ |
| 35 | u8 b1 = adapter_payload[1 + (9 * port) + 1]; | 36 | PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, |
| 36 | u8 b2 = adapter_payload[1 + (9 * port) + 2]; | 37 | PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP}; |
| 37 | 38 | ||
| 38 | if (b1 & (1 << 0)) { | 39 | constexpr std::array<PadButton, 4> b2_buttons{PAD_BUTTON_START, PAD_TRIGGER_Z, PAD_TRIGGER_R, |
| 39 | pad.button |= PAD_BUTTON_A; | 40 | PAD_TRIGGER_L}; |
| 40 | } | ||
| 41 | if (b1 & (1 << 1)) { | ||
| 42 | pad.button |= PAD_BUTTON_B; | ||
| 43 | } | ||
| 44 | if (b1 & (1 << 2)) { | ||
| 45 | pad.button |= PAD_BUTTON_X; | ||
| 46 | } | ||
| 47 | if (b1 & (1 << 3)) { | ||
| 48 | pad.button |= PAD_BUTTON_Y; | ||
| 49 | } | ||
| 50 | 41 | ||
| 51 | if (b1 & (1 << 4)) { | 42 | if (adapter_controllers_status[port] != ControllerTypes::None) { |
| 52 | pad.button |= PAD_BUTTON_LEFT; | 43 | const u8 b1 = adapter_payload[1 + (9 * port) + 1]; |
| 53 | } | 44 | const u8 b2 = adapter_payload[1 + (9 * port) + 2]; |
| 54 | if (b1 & (1 << 5)) { | ||
| 55 | pad.button |= PAD_BUTTON_RIGHT; | ||
| 56 | } | ||
| 57 | if (b1 & (1 << 6)) { | ||
| 58 | pad.button |= PAD_BUTTON_DOWN; | ||
| 59 | } | ||
| 60 | if (b1 & (1 << 7)) { | ||
| 61 | pad.button |= PAD_BUTTON_UP; | ||
| 62 | } | ||
| 63 | 45 | ||
| 64 | if (b2 & (1 << 0)) { | 46 | for (int i = 0; i < b1_buttons.size(); i++) { |
| 65 | pad.button |= PAD_BUTTON_START; | 47 | if (b1 & (1 << i)) { |
| 66 | } | 48 | pad.button |= b1_buttons[i]; |
| 67 | if (b2 & (1 << 1)) { | 49 | } |
| 68 | pad.button |= PAD_TRIGGER_Z; | ||
| 69 | } | ||
| 70 | if (b2 & (1 << 2)) { | ||
| 71 | pad.button |= PAD_TRIGGER_R; | ||
| 72 | } | 50 | } |
| 73 | if (b2 & (1 << 3)) { | 51 | |
| 74 | pad.button |= PAD_TRIGGER_L; | 52 | for (int j = 0; j < b2_buttons.size(); j++) { |
| 53 | if (b2 & (1 << j)) { | ||
| 54 | pad.button |= b2_buttons[j]; | ||
| 55 | } | ||
| 75 | } | 56 | } |
| 76 | 57 | ||
| 77 | if (get_origin) { | 58 | if (get_origin) { |
| @@ -112,65 +93,65 @@ void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { | |||
| 112 | void Adapter::Read() { | 93 | void Adapter::Read() { |
| 113 | LOG_INFO(Input, "GC Adapter Read() thread started"); | 94 | LOG_INFO(Input, "GC Adapter Read() thread started"); |
| 114 | 95 | ||
| 115 | int payload_size_in, payload_size; | 96 | int payload_size_in, payload_size_copy; |
| 116 | std::array<u8, 37> adapter_payload; | 97 | std::array<u8, 37> adapter_payload; |
| 117 | std::array<u8, 37> controller_payload_copy; | 98 | std::array<u8, 37> adapter_payload_copy; |
| 118 | std::array<GCPadStatus, 4> pad; | 99 | std::array<GCPadStatus, 4> pads; |
| 119 | 100 | ||
| 120 | while (adapter_thread_running) { | 101 | while (adapter_thread_running) { |
| 121 | libusb_interrupt_transfer(usb_adapter_handle, input_endpoint, adapter_payload.data(), | 102 | libusb_interrupt_transfer(usb_adapter_handle, input_endpoint, adapter_payload.data(), |
| 122 | sizeof(adapter_payload), &payload_size_in, 32); | 103 | sizeof(adapter_payload), &payload_size_in, 32); |
| 123 | payload_size = 0; | 104 | payload_size_copy = 0; |
| 124 | { | 105 | { |
| 125 | std::lock_guard<std::mutex> lk(s_mutex); | 106 | std::lock_guard<std::mutex> lk(s_mutex); |
| 126 | std::copy(std::begin(adapter_payload), std::end(adapter_payload), | 107 | std::copy(std::begin(adapter_payload), std::end(adapter_payload), |
| 127 | std::begin(controller_payload_copy)); | 108 | std::begin(adapter_payload_copy)); |
| 128 | payload_size = payload_size_in; | 109 | payload_size_copy = payload_size_in; |
| 129 | } | 110 | } |
| 130 | 111 | ||
| 131 | if (payload_size != sizeof(controller_payload_copy) || | 112 | if (payload_size_copy != sizeof(adapter_payload_copy) || |
| 132 | controller_payload_copy[0] != LIBUSB_DT_HID) { | 113 | adapter_payload_copy[0] != LIBUSB_DT_HID) { |
| 133 | // TODO: It might be worthwhile to Shutdown GC Adapter if we encounter errors here | 114 | // TODO: It might be worthwhile to Shutdown GC Adapter if we encounter errors here |
| 134 | LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size, | 115 | LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy, |
| 135 | controller_payload_copy[0]); | 116 | adapter_payload_copy[0]); |
| 136 | } else { | 117 | } else { |
| 137 | for (int port = 0; port < 4; port++) { | 118 | for (int port = 0; port < pads.size(); port++) { |
| 138 | pad[port] = CheckStatus(port, controller_payload_copy); | 119 | pads[port] = GetPadStatus(port, adapter_payload_copy); |
| 139 | } | 120 | } |
| 140 | } | 121 | } |
| 141 | for (int port = 0; port < 4; port++) { | 122 | for (int port = 0; port < pads.size(); port++) { |
| 142 | if (DeviceConnected(port) && configuring) { | 123 | if (DeviceConnected(port) && configuring) { |
| 143 | if (pad[port].button != PAD_GET_ORIGIN) { | 124 | if (pads[port].button != PAD_GET_ORIGIN) { |
| 144 | pad_queue[port].Push(pad[port]); | 125 | pad_queue[port].Push(pads[port]); |
| 145 | } | 126 | } |
| 146 | 127 | ||
| 147 | // Accounting for a threshold here because of some controller variance | 128 | // Accounting for a threshold here because of some controller variance |
| 148 | if (pad[port].stick_x > pad[port].MAIN_STICK_CENTER_X + pad[port].THRESHOLD || | 129 | if (pads[port].stick_x > pads[port].MAIN_STICK_CENTER_X + pads[port].THRESHOLD || |
| 149 | pad[port].stick_x < pad[port].MAIN_STICK_CENTER_X - pad[port].THRESHOLD) { | 130 | pads[port].stick_x < pads[port].MAIN_STICK_CENTER_X - pads[port].THRESHOLD) { |
| 150 | pad[port].axis = GCAdapter::PadAxes::StickX; | 131 | pads[port].axis = GCAdapter::PadAxes::StickX; |
| 151 | pad[port].axis_value = pad[port].stick_x; | 132 | pads[port].axis_value = pads[port].stick_x; |
| 152 | pad_queue[port].Push(pad[port]); | 133 | pad_queue[port].Push(pads[port]); |
| 153 | } | 134 | } |
| 154 | if (pad[port].stick_y > pad[port].MAIN_STICK_CENTER_Y + pad[port].THRESHOLD || | 135 | if (pads[port].stick_y > pads[port].MAIN_STICK_CENTER_Y + pads[port].THRESHOLD || |
| 155 | pad[port].stick_y < pad[port].MAIN_STICK_CENTER_Y - pad[port].THRESHOLD) { | 136 | pads[port].stick_y < pads[port].MAIN_STICK_CENTER_Y - pads[port].THRESHOLD) { |
| 156 | pad[port].axis = GCAdapter::PadAxes::StickY; | 137 | pads[port].axis = GCAdapter::PadAxes::StickY; |
| 157 | pad[port].axis_value = pad[port].stick_y; | 138 | pads[port].axis_value = pads[port].stick_y; |
| 158 | pad_queue[port].Push(pad[port]); | 139 | pad_queue[port].Push(pads[port]); |
| 159 | } | 140 | } |
| 160 | if (pad[port].substick_x > pad[port].C_STICK_CENTER_X + pad[port].THRESHOLD || | 141 | if (pads[port].substick_x > pads[port].C_STICK_CENTER_X + pads[port].THRESHOLD || |
| 161 | pad[port].substick_x < pad[port].C_STICK_CENTER_X - pad[port].THRESHOLD) { | 142 | pads[port].substick_x < pads[port].C_STICK_CENTER_X - pads[port].THRESHOLD) { |
| 162 | pad[port].axis = GCAdapter::PadAxes::SubstickX; | 143 | pads[port].axis = GCAdapter::PadAxes::SubstickX; |
| 163 | pad[port].axis_value = pad[port].substick_x; | 144 | pads[port].axis_value = pads[port].substick_x; |
| 164 | pad_queue[port].Push(pad[port]); | 145 | pad_queue[port].Push(pads[port]); |
| 165 | } | 146 | } |
| 166 | if (pad[port].substick_y > pad[port].C_STICK_CENTER_Y + pad[port].THRESHOLD || | 147 | if (pads[port].substick_y > pads[port].C_STICK_CENTER_Y + pads[port].THRESHOLD || |
| 167 | pad[port].substick_y < pad[port].C_STICK_CENTER_Y - pad[port].THRESHOLD) { | 148 | pads[port].substick_y < pads[port].C_STICK_CENTER_Y - pads[port].THRESHOLD) { |
| 168 | pad[port].axis = GCAdapter::PadAxes::SubstickY; | 149 | pads[port].axis = GCAdapter::PadAxes::SubstickY; |
| 169 | pad[port].axis_value = pad[port].substick_y; | 150 | pads[port].axis_value = pads[port].substick_y; |
| 170 | pad_queue[port].Push(pad[port]); | 151 | pad_queue[port].Push(pads[port]); |
| 171 | } | 152 | } |
| 172 | } | 153 | } |
| 173 | PadToState(pad[port], state[port]); | 154 | PadToState(pads[port], state[port]); |
| 174 | } | 155 | } |
| 175 | std::this_thread::yield(); | 156 | std::this_thread::yield(); |
| 176 | } | 157 | } |
| @@ -215,11 +196,11 @@ void Adapter::Setup() { | |||
| 215 | 196 | ||
| 216 | libusb_device** devs; // pointer to list of connected usb devices | 197 | libusb_device** devs; // pointer to list of connected usb devices |
| 217 | 198 | ||
| 218 | int cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices | 199 | const int cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices |
| 219 | 200 | ||
| 220 | for (int i = 0; i < cnt; i++) { | 201 | for (int i = 0; i < cnt; i++) { |
| 221 | if (CheckDeviceAccess(devs[i])) { | 202 | if (CheckDeviceAccess(devs[i])) { |
| 222 | // GC Adapter found, registering it | 203 | // GC Adapter found and accessible, registering it |
| 223 | GetGCEndpoint(devs[i]); | 204 | GetGCEndpoint(devs[i]); |
| 224 | break; | 205 | break; |
| 225 | } | 206 | } |
| @@ -228,10 +209,11 @@ void Adapter::Setup() { | |||
| 228 | 209 | ||
| 229 | bool Adapter::CheckDeviceAccess(libusb_device* device) { | 210 | bool Adapter::CheckDeviceAccess(libusb_device* device) { |
| 230 | libusb_device_descriptor desc; | 211 | libusb_device_descriptor desc; |
| 231 | int ret = libusb_get_device_descriptor(device, &desc); | 212 | const int get_descriptor_error = libusb_get_device_descriptor(device, &desc); |
| 232 | if (ret) { | 213 | if (get_descriptor_error) { |
| 233 | // could not acquire the descriptor, no point in trying to use it. | 214 | // could not acquire the descriptor, no point in trying to use it. |
| 234 | LOG_ERROR(Input, "libusb_get_device_descriptor failed with error: %d", ret); | 215 | LOG_ERROR(Input, "libusb_get_device_descriptor failed with error: %d", |
| 216 | get_descriptor_error); | ||
| 235 | return false; | 217 | return false; |
| 236 | } | 218 | } |
| 237 | 219 | ||
| @@ -239,35 +221,36 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { | |||
| 239 | // This isn’t the device we are looking for. | 221 | // This isn’t the device we are looking for. |
| 240 | return false; | 222 | return false; |
| 241 | } | 223 | } |
| 242 | ret = libusb_open(device, &usb_adapter_handle); | 224 | const int open_error = libusb_open(device, &usb_adapter_handle); |
| 243 | 225 | ||
| 244 | if (ret == LIBUSB_ERROR_ACCESS) { | 226 | if (open_error == LIBUSB_ERROR_ACCESS) { |
| 245 | LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, | 227 | LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, |
| 246 | desc.idProduct); | 228 | desc.idProduct); |
| 247 | return false; | 229 | return false; |
| 248 | } | 230 | } |
| 249 | if (ret) { | 231 | if (open_error) { |
| 250 | LOG_ERROR(Input, "libusb_open failed to open device with error = %d", ret); | 232 | LOG_ERROR(Input, "libusb_open failed to open device with error = %d", open_error); |
| 251 | return false; | 233 | return false; |
| 252 | } | 234 | } |
| 253 | 235 | ||
| 254 | ret = libusb_kernel_driver_active(usb_adapter_handle, 0); | 236 | int kernel_driver_error = libusb_kernel_driver_active(usb_adapter_handle, 0); |
| 255 | if (ret == 1) { | 237 | if (kernel_driver_error == 1) { |
| 256 | ret = libusb_detach_kernel_driver(usb_adapter_handle, 0); | 238 | kernel_driver_error = libusb_detach_kernel_driver(usb_adapter_handle, 0); |
| 257 | if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { | 239 | if (kernel_driver_error != 0 && kernel_driver_error != LIBUSB_ERROR_NOT_SUPPORTED) { |
| 258 | LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", ret); | 240 | LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", |
| 241 | kernel_driver_error); | ||
| 259 | } | 242 | } |
| 260 | } | 243 | } |
| 261 | 244 | ||
| 262 | if (ret != 0 && ret != LIBUSB_ERROR_NOT_SUPPORTED) { | 245 | if (kernel_driver_error && kernel_driver_error != LIBUSB_ERROR_NOT_SUPPORTED) { |
| 263 | libusb_close(usb_adapter_handle); | 246 | libusb_close(usb_adapter_handle); |
| 264 | usb_adapter_handle = nullptr; | 247 | usb_adapter_handle = nullptr; |
| 265 | return false; | 248 | return false; |
| 266 | } | 249 | } |
| 267 | 250 | ||
| 268 | ret = libusb_claim_interface(usb_adapter_handle, 0); | 251 | const int interface_claim_error = libusb_claim_interface(usb_adapter_handle, 0); |
| 269 | if (ret) { | 252 | if (interface_claim_error) { |
| 270 | LOG_ERROR(Input, "libusb_claim_interface failed with error = %d", ret); | 253 | LOG_ERROR(Input, "libusb_claim_interface failed with error = %d", interface_claim_error); |
| 271 | libusb_close(usb_adapter_handle); | 254 | libusb_close(usb_adapter_handle); |
| 272 | usb_adapter_handle = nullptr; | 255 | usb_adapter_handle = nullptr; |
| 273 | return false; | 256 | return false; |
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 7aed0b480..abfe0d7b3 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -37,6 +37,12 @@ enum PadButton { | |||
| 37 | 37 | ||
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | /// Used to loop through the and assign button in poller | ||
| 41 | static constexpr std::array<PadButton, 12> PadButtonArray{ | ||
| 42 | PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP, | ||
| 43 | PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L, PAD_BUTTON_A, | ||
| 44 | PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, PAD_BUTTON_START}; | ||
| 45 | |||
| 40 | enum class PadAxes : u8 { | 46 | enum class PadAxes : u8 { |
| 41 | StickX, | 47 | StickX, |
| 42 | StickY, | 48 | StickY, |
| @@ -100,7 +106,7 @@ public: | |||
| 100 | const std::array<GCState, 4>& GetPadState() const; | 106 | const std::array<GCState, 4>& GetPadState() const; |
| 101 | 107 | ||
| 102 | private: | 108 | private: |
| 103 | GCPadStatus CheckStatus(int port, const std::array<u8, 37>& adapter_payload); | 109 | GCPadStatus GetPadStatus(int 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 | ||
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index be7c600a2..977261884 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -58,8 +58,8 @@ GCButtonFactory::GCButtonFactory(std::shared_ptr<GCAdapter::Adapter> adapter_) | |||
| 58 | GCButton::~GCButton() = default; | 58 | GCButton::~GCButton() = default; |
| 59 | 59 | ||
| 60 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { | 60 | std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { |
| 61 | int button_id = params.Get("button", 0); | 61 | const int button_id = params.Get("button", 0); |
| 62 | int port = params.Get("port", 0); | 62 | const int port = params.Get("port", 0); |
| 63 | // For Axis buttons, used by the binary sticks. | 63 | // For Axis buttons, used by the binary sticks. |
| 64 | if (params.Has("axis")) { | 64 | if (params.Has("axis")) { |
| 65 | const int axis = params.Get("axis", 0); | 65 | const int axis = params.Get("axis", 0); |
| @@ -86,61 +86,22 @@ std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::Param | |||
| 86 | Common::ParamPackage GCButtonFactory::GetNextInput() { | 86 | Common::ParamPackage GCButtonFactory::GetNextInput() { |
| 87 | Common::ParamPackage params; | 87 | Common::ParamPackage params; |
| 88 | GCAdapter::GCPadStatus pad; | 88 | GCAdapter::GCPadStatus pad; |
| 89 | for (int i = 0; i < 4; i++) { | 89 | auto& queue = adapter->GetPadQueue(); |
| 90 | while (adapter->GetPadQueue()[i].Pop(pad)) { | 90 | for (int port = 0; port < queue.size(); port++) { |
| 91 | while (queue[port].Pop(pad)) { | ||
| 91 | // This while loop will break on the earliest detected button | 92 | // This while loop will break on the earliest detected button |
| 92 | params.Set("engine", "gcpad"); | 93 | params.Set("engine", "gcpad"); |
| 93 | params.Set("port", i); | 94 | params.Set("port", port); |
| 94 | // I was debating whether to keep these verbose for ease of reading | 95 | // I was debating whether to keep these verbose for ease of reading |
| 95 | // or to use a while loop shifting the bits to test and set the value. | 96 | // or to use a while loop shifting the bits to test and set the value. |
| 96 | if (pad.button & GCAdapter::PAD_BUTTON_A) { | 97 | |
| 97 | params.Set("button", GCAdapter::PAD_BUTTON_A); | 98 | for (auto button : GCAdapter::PadButtonArray) { |
| 98 | break; | 99 | if (pad.button & button) { |
| 99 | } | 100 | params.Set("button", button); |
| 100 | if (pad.button & GCAdapter::PAD_BUTTON_B) { | 101 | break; |
| 101 | params.Set("button", GCAdapter::PAD_BUTTON_B); | 102 | } |
| 102 | break; | ||
| 103 | } | ||
| 104 | if (pad.button & GCAdapter::PAD_BUTTON_X) { | ||
| 105 | params.Set("button", GCAdapter::PAD_BUTTON_X); | ||
| 106 | break; | ||
| 107 | } | ||
| 108 | if (pad.button & GCAdapter::PAD_BUTTON_Y) { | ||
| 109 | params.Set("button", GCAdapter::PAD_BUTTON_Y); | ||
| 110 | break; | ||
| 111 | } | ||
| 112 | if (pad.button & GCAdapter::PAD_BUTTON_DOWN) { | ||
| 113 | params.Set("button", GCAdapter::PAD_BUTTON_DOWN); | ||
| 114 | break; | ||
| 115 | } | ||
| 116 | if (pad.button & GCAdapter::PAD_BUTTON_LEFT) { | ||
| 117 | params.Set("button", GCAdapter::PAD_BUTTON_LEFT); | ||
| 118 | break; | ||
| 119 | } | ||
| 120 | if (pad.button & GCAdapter::PAD_BUTTON_RIGHT) { | ||
| 121 | params.Set("button", GCAdapter::PAD_BUTTON_RIGHT); | ||
| 122 | break; | ||
| 123 | } | ||
| 124 | if (pad.button & GCAdapter::PAD_BUTTON_UP) { | ||
| 125 | params.Set("button", GCAdapter::PAD_BUTTON_UP); | ||
| 126 | break; | ||
| 127 | } | ||
| 128 | if (pad.button & GCAdapter::PAD_TRIGGER_L) { | ||
| 129 | params.Set("button", GCAdapter::PAD_TRIGGER_L); | ||
| 130 | break; | ||
| 131 | } | ||
| 132 | if (pad.button & GCAdapter::PAD_TRIGGER_R) { | ||
| 133 | params.Set("button", GCAdapter::PAD_TRIGGER_R); | ||
| 134 | break; | ||
| 135 | } | ||
| 136 | if (pad.button & GCAdapter::PAD_TRIGGER_Z) { | ||
| 137 | params.Set("button", GCAdapter::PAD_TRIGGER_Z); | ||
| 138 | break; | ||
| 139 | } | ||
| 140 | if (pad.button & GCAdapter::PAD_BUTTON_START) { | ||
| 141 | params.Set("button", GCAdapter::PAD_BUTTON_START); | ||
| 142 | break; | ||
| 143 | } | 103 | } |
| 104 | |||
| 144 | // For Axis button implementation | 105 | // For Axis button implementation |
| 145 | if (pad.axis != GCAdapter::PadAxes::Undefined) { | 106 | if (pad.axis != GCAdapter::PadAxes::Undefined) { |
| 146 | params.Set("axis", static_cast<u8>(pad.axis)); | 107 | params.Set("axis", static_cast<u8>(pad.axis)); |
| @@ -265,8 +226,9 @@ void GCAnalogFactory::EndConfiguration() { | |||
| 265 | 226 | ||
| 266 | Common::ParamPackage GCAnalogFactory::GetNextInput() { | 227 | Common::ParamPackage GCAnalogFactory::GetNextInput() { |
| 267 | GCAdapter::GCPadStatus pad; | 228 | GCAdapter::GCPadStatus pad; |
| 268 | for (int i = 0; i < 4; i++) { | 229 | auto& queue = adapter->GetPadQueue(); |
| 269 | while (adapter->GetPadQueue()[i].Pop(pad)) { | 230 | for (int port = 0; port < queue.size(); port++) { |
| 231 | while (queue[port].Pop(pad)) { | ||
| 270 | if (pad.axis == GCAdapter::PadAxes::Undefined || | 232 | if (pad.axis == GCAdapter::PadAxes::Undefined || |
| 271 | std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { | 233 | std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { |
| 272 | continue; | 234 | continue; |
| @@ -276,8 +238,8 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { | |||
| 276 | const u8 axis = static_cast<u8>(pad.axis); | 238 | const u8 axis = static_cast<u8>(pad.axis); |
| 277 | if (analog_x_axis == -1) { | 239 | if (analog_x_axis == -1) { |
| 278 | analog_x_axis = axis; | 240 | analog_x_axis = axis; |
| 279 | controller_number = i; | 241 | controller_number = port; |
| 280 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == i) { | 242 | } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { |
| 281 | analog_y_axis = axis; | 243 | analog_y_axis = axis; |
| 282 | } | 244 | } |
| 283 | } | 245 | } |
diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp index 9138a7563..eb6c3112b 100644 --- a/src/input_common/keyboard.cpp +++ b/src/input_common/keyboard.cpp | |||
| @@ -51,7 +51,6 @@ public: | |||
| 51 | for (const KeyButtonPair& pair : list) { | 51 | for (const KeyButtonPair& pair : list) { |
| 52 | if (pair.key_code == key_code) { | 52 | if (pair.key_code == key_code) { |
| 53 | pair.key_button->status.store(pressed); | 53 | pair.key_button->status.store(pressed); |
| 54 | break; | ||
| 55 | } | 54 | } |
| 56 | } | 55 | } |
| 57 | } | 56 | } |