summaryrefslogtreecommitdiff
path: root/src/input_common/gcadapter/gc_adapter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
-rw-r--r--src/input_common/gcadapter/gc_adapter.cpp40
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 @@
9 9
10namespace GCAdapter { 10namespace GCAdapter {
11 11
12/// Used to loop through and assign button in poller
13constexpr std::array<PadButton, 12> PadButtonArray{
14 PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN,
15 PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R,
16 PadButton::PAD_TRIGGER_L, PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B,
17 PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START,
18};
19
12Adapter::Adapter() { 20Adapter::Adapter() {
13 if (usb_adapter_handle != nullptr) { 21 if (usb_adapter_handle != nullptr) {
14 return; 22 return;
@@ -32,27 +40,31 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
32 40
33 adapter_controllers_status[port] = type; 41 adapter_controllers_status[port] = type;
34 42
35 constexpr std::array<PadButton, 8> b1_buttons{ 43 static constexpr std::array<PadButton, 8> b1_buttons{
36 PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X, 44 PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X,
37 PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, 45 PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT,
38 PadButton::PAD_BUTTON_DOWN, PadButton::PAD_BUTTON_UP}; 46 PadButton::PAD_BUTTON_DOWN, PadButton::PAD_BUTTON_UP,
47 };
39 48
40 constexpr std::array<PadButton, 4> b2_buttons{ 49 static constexpr std::array<PadButton, 4> b2_buttons{
41 PadButton::PAD_BUTTON_START, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, 50 PadButton::PAD_BUTTON_START,
42 PadButton::PAD_TRIGGER_L}; 51 PadButton::PAD_TRIGGER_Z,
52 PadButton::PAD_TRIGGER_R,
53 PadButton::PAD_TRIGGER_L,
54 };
43 55
44 if (adapter_controllers_status[port] != ControllerTypes::None) { 56 if (adapter_controllers_status[port] != ControllerTypes::None) {
45 const u8 b1 = adapter_payload[1 + (9 * port) + 1]; 57 const u8 b1 = adapter_payload[1 + (9 * port) + 1];
46 const u8 b2 = adapter_payload[1 + (9 * port) + 2]; 58 const u8 b2 = adapter_payload[1 + (9 * port) + 2];
47 59
48 for (std::size_t i = 0; i < b1_buttons.size(); ++i) { 60 for (std::size_t i = 0; i < b1_buttons.size(); ++i) {
49 if (b1 & (1 << i)) { 61 if ((b1 & (1U << i)) != 0) {
50 pad.button |= static_cast<u16>(b1_buttons[i]); 62 pad.button |= static_cast<u16>(b1_buttons[i]);
51 } 63 }
52 } 64 }
53 65
54 for (std::size_t j = 0; j < b2_buttons.size(); ++j) { 66 for (std::size_t j = 0; j < b2_buttons.size(); ++j) {
55 if (b2 & (1 << j)) { 67 if ((b2 & (1U << j)) != 0) {
56 pad.button |= static_cast<u16>(b2_buttons[j]); 68 pad.button |= static_cast<u16>(b2_buttons[j]);
57 } 69 }
58 } 70 }
@@ -107,7 +119,7 @@ void Adapter::Read() {
107 119
108 if (payload_size_copy != sizeof(adapter_payload_copy) || 120 if (payload_size_copy != sizeof(adapter_payload_copy) ||
109 adapter_payload_copy[0] != LIBUSB_DT_HID) { 121 adapter_payload_copy[0] != LIBUSB_DT_HID) {
110 LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy, 122 LOG_ERROR(Input, "error reading payload (size: {}, type: {:02x})", payload_size_copy,
111 adapter_payload_copy[0]); 123 adapter_payload_copy[0]);
112 adapter_thread_running = false; // error reading from adapter, stop reading. 124 adapter_thread_running = false; // error reading from adapter, stop reading.
113 break; 125 break;
@@ -220,7 +232,7 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) {
220 const int get_descriptor_error = libusb_get_device_descriptor(device, &desc); 232 const int get_descriptor_error = libusb_get_device_descriptor(device, &desc);
221 if (get_descriptor_error) { 233 if (get_descriptor_error) {
222 // could not acquire the descriptor, no point in trying to use it. 234 // could not acquire the descriptor, no point in trying to use it.
223 LOG_ERROR(Input, "libusb_get_device_descriptor failed with error: %d", 235 LOG_ERROR(Input, "libusb_get_device_descriptor failed with error: {}",
224 get_descriptor_error); 236 get_descriptor_error);
225 return false; 237 return false;
226 } 238 }
@@ -232,12 +244,12 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) {
232 const int open_error = libusb_open(device, &usb_adapter_handle); 244 const int open_error = libusb_open(device, &usb_adapter_handle);
233 245
234 if (open_error == LIBUSB_ERROR_ACCESS) { 246 if (open_error == LIBUSB_ERROR_ACCESS) {
235 LOG_ERROR(Input, "Yuzu can not gain access to this device: ID %04X:%04X.", desc.idVendor, 247 LOG_ERROR(Input, "Yuzu can not gain access to this device: ID {:04X}:{:04X}.",
236 desc.idProduct); 248 desc.idVendor, desc.idProduct);
237 return false; 249 return false;
238 } 250 }
239 if (open_error) { 251 if (open_error) {
240 LOG_ERROR(Input, "libusb_open failed to open device with error = %d", open_error); 252 LOG_ERROR(Input, "libusb_open failed to open device with error = {}", open_error);
241 return false; 253 return false;
242 } 254 }
243 255
@@ -245,7 +257,7 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) {
245 if (kernel_driver_error == 1) { 257 if (kernel_driver_error == 1) {
246 kernel_driver_error = libusb_detach_kernel_driver(usb_adapter_handle, 0); 258 kernel_driver_error = libusb_detach_kernel_driver(usb_adapter_handle, 0);
247 if (kernel_driver_error != 0 && kernel_driver_error != LIBUSB_ERROR_NOT_SUPPORTED) { 259 if (kernel_driver_error != 0 && kernel_driver_error != LIBUSB_ERROR_NOT_SUPPORTED) {
248 LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = %d", 260 LOG_ERROR(Input, "libusb_detach_kernel_driver failed with error = {}",
249 kernel_driver_error); 261 kernel_driver_error);
250 } 262 }
251 } 263 }
@@ -258,7 +270,7 @@ bool Adapter::CheckDeviceAccess(libusb_device* device) {
258 270
259 const int interface_claim_error = libusb_claim_interface(usb_adapter_handle, 0); 271 const int interface_claim_error = libusb_claim_interface(usb_adapter_handle, 0);
260 if (interface_claim_error) { 272 if (interface_claim_error) {
261 LOG_ERROR(Input, "libusb_claim_interface failed with error = %d", interface_claim_error); 273 LOG_ERROR(Input, "libusb_claim_interface failed with error = {}", interface_claim_error);
262 libusb_close(usb_adapter_handle); 274 libusb_close(usb_adapter_handle);
263 usb_adapter_handle = nullptr; 275 usb_adapter_handle = nullptr;
264 return false; 276 return false;