diff options
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
-rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 82f97572f..f58b0e11c 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -9,6 +9,14 @@ namespace GCAdapter { +/// Used to loop through and assign button in poller +constexpr std::array<PadButton, 12> PadButtonArray{ + PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, + PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, + PadButton::PAD_TRIGGER_L, PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, + PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START, +}; + Adapter::Adapter() { if (usb_adapter_handle != nullptr) { return; @@ -32,27 +40,31 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa adapter_controllers_status[port] = type; - constexpr std::array<PadButton, 8> b1_buttons{ + static constexpr std::array<PadButton, 8> b1_buttons{ PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, - PadButton::PAD_BUTTON_DOWN, PadButton::PAD_BUTTON_UP}; + PadButton::PAD_BUTTON_DOWN, PadButton::PAD_BUTTON_UP, + }; - constexpr std::array<PadButton, 4> b2_buttons{ - PadButton::PAD_BUTTON_START, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, - PadButton::PAD_TRIGGER_L}; + static constexpr std::array<PadButton, 4> b2_buttons{ + PadButton::PAD_BUTTON_START, + PadButton::PAD_TRIGGER_Z, + PadButton::PAD_TRIGGER_R, + PadButton::PAD_TRIGGER_L, + }; if (adapter_controllers_status[port] != ControllerTypes::None) { const u8 b1 = adapter_payload[1 + (9 * port) + 1]; const u8 b2 = adapter_payload[1 + (9 * port) + 2]; for (std::size_t i = 0; i < b1_buttons.size(); ++i) { - if (b1 & (1 << i)) { + if ((b1 & (1U << i)) != 0) { pad.button |= static_cast<u16>(b1_buttons[i]); } } for (std::size_t j = 0; j < b2_buttons.size(); ++j) { - if (b2 & (1 << j)) { + if ((b2 & (1U << j)) != 0) { pad.button |= static_cast<u16>(b2_buttons[j]); } } @@ -107,7 +119,7 @@ void Adapter::Read() { if (payload_size_copy != sizeof(adapter_payload_copy) || adapter_payload_copy[0] != LIBUSB_DT_HID) { - LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy, + LOG_ERROR(Input, "error reading payload (size: {}, type: {:02x})", payload_size_copy, adapter_payload_copy[0]); adapter_thread_running = false; // error reading from adapter, stop reading. break; @@ -220,7 +232,7 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { const int get_descriptor_error = libusb_get_device_descriptor(device, &desc); if (get_descriptor_error) { // could not acquire the descriptor, no point in trying to use it. - LOG_ERROR(Input, "libusb_get_device_descriptor failed with error: %d", + LOG_ERROR(Input, "libusb_get_device_descriptor failed with error: {}", get_descriptor_error); return false; } @@ -232,12 +244,12 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { const int open_error = libusb_open(device, &usb_adapter_handle); if (open_error == LIBUSB_ERROR_ACCESS) { - LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, - desc.idProduct); + LOG_ERROR(Input, "Yuzu can not gain access to this device: ID {:04X}:{:04X}.", + desc.idVendor, desc.idProduct); return false; } if (open_error) { - LOG_ERROR(Input, "libusb_open failed to open device with error = %d", open_error); + LOG_ERROR(Input, "libusb_open failed to open device with error = {}", open_error); return false; } @@ -245,7 +257,7 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { if (kernel_driver_error == 1) { kernel_driver_error = libusb_detach_kernel_driver(usb_adapter_handle, 0); if (kernel_driver_error != 0 && kernel_driver_error != LIBUSB_ERROR_NOT_SUPPORTED) { - LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", + LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = {}", kernel_driver_error); } } @@ -258,7 +270,7 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) { const int interface_claim_error = libusb_claim_interface(usb_adapter_handle, 0); if (interface_claim_error) { - LOG_ERROR(Input, "libusb_claim_interface failed with error = %d", interface_claim_error); + LOG_ERROR(Input, "libusb_claim_interface failed with error = {}", interface_claim_error); libusb_close(usb_adapter_handle); usb_adapter_handle = nullptr; return false; |