summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ameer2020-06-30 17:28:02 -0400
committerGravatar Ameer2020-06-30 17:28:02 -0400
commita76e11e7f0c97222388bede03325aa71f1434510 (patch)
treeb1af57677dabe161da2e6a596d752c880ea1769f
parentfix implicit conversion of size_t type to int (diff)
downloadyuzu-a76e11e7f0c97222388bede03325aa71f1434510.tar.gz
yuzu-a76e11e7f0c97222388bede03325aa71f1434510.tar.xz
yuzu-a76e11e7f0c97222388bede03325aa71f1434510.zip
Address feedback regarding increments, const vars, and general cleanup
-rw-r--r--src/input_common/gcadapter/gc_adapter.cpp28
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp17
2 files changed, 21 insertions, 24 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp
index b509b3e46..b98b85441 100644
--- a/src/input_common/gcadapter/gc_adapter.cpp
+++ b/src/input_common/gcadapter/gc_adapter.cpp
@@ -45,13 +45,13 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
45 const u8 b1 = adapter_payload[1 + (9 * port) + 1]; 45 const u8 b1 = adapter_payload[1 + (9 * port) + 1];
46 const u8 b2 = adapter_payload[1 + (9 * port) + 2]; 46 const u8 b2 = adapter_payload[1 + (9 * port) + 2];
47 47
48 for (int i = 0; i < b1_buttons.size(); i++) { 48 for (std::size_t i = 0; i < b1_buttons.size(); ++i) {
49 if (b1 & (1 << i)) { 49 if (b1 & (1 << i)) {
50 pad.button |= static_cast<u16>(b1_buttons[i]); 50 pad.button |= static_cast<u16>(b1_buttons[i]);
51 } 51 }
52 } 52 }
53 53
54 for (int j = 0; j < b2_buttons.size(); j++) { 54 for (std::size_t j = 0; j < b2_buttons.size(); ++j) {
55 if (b2 & (1 << j)) { 55 if (b2 & (1 << j)) {
56 pad.button |= static_cast<u16>(b2_buttons[j]); 56 pad.button |= static_cast<u16>(b2_buttons[j]);
57 } 57 }
@@ -73,7 +73,7 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa
73 73
74void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { 74void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
75 for (const auto& button : PadButtonArray) { 75 for (const auto& button : PadButtonArray) {
76 u16 button_value = static_cast<u16>(button); 76 const u16 button_value = static_cast<u16>(button);
77 state.buttons.insert_or_assign(button_value, pad.button & button_value); 77 state.buttons.insert_or_assign(button_value, pad.button & button_value);
78 } 78 }
79 79
@@ -86,7 +86,7 @@ void Adapter::PadToState(const GCPadStatus& pad, GCState& state) {
86} 86}
87 87
88void Adapter::Read() { 88void Adapter::Read() {
89 LOG_INFO(Input, "GC Adapter Read() thread started"); 89 LOG_DEBUG(Input, "GC Adapter Read() thread started");
90 90
91 int payload_size_in, payload_size_copy; 91 int payload_size_in, payload_size_copy;
92 std::array<u8, 37> adapter_payload; 92 std::array<u8, 37> adapter_payload;
@@ -109,12 +109,10 @@ void Adapter::Read() {
109 LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy, 109 LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size_copy,
110 adapter_payload_copy[0]); 110 adapter_payload_copy[0]);
111 adapter_thread_running = false; // error reading from adapter, stop reading. 111 adapter_thread_running = false; // error reading from adapter, stop reading.
112 } else { 112 break;
113 for (int port = 0; port < pads.size(); port++) {
114 pads[port] = GetPadStatus(port, adapter_payload_copy);
115 }
116 } 113 }
117 for (int port = 0; port < pads.size(); port++) { 114 for (std::size_t port = 0; port < pads.size(); ++port) {
115 pads[port] = GetPadStatus(port, adapter_payload_copy);
118 if (DeviceConnected(port) && configuring) { 116 if (DeviceConnected(port) && configuring) {
119 if (pads[port].button != PAD_GET_ORIGIN) { 117 if (pads[port].button != PAD_GET_ORIGIN) {
120 pad_queue[port].Push(pads[port]); 118 pad_queue[port].Push(pads[port]);
@@ -189,14 +187,16 @@ void Adapter::Setup() {
189 187
190 adapter_controllers_status.fill(ControllerTypes::None); 188 adapter_controllers_status.fill(ControllerTypes::None);
191 189
192 libusb_device** devs; // pointer to list of connected usb devices 190 // pointer to list of connected usb devices
191 libusb_device** devices;
193 192
194 const std::size_t cnt = libusb_get_device_list(libusb_ctx, &devs); // get the list of devices 193 // populate the list of devices, get the count
194 const std::size_t device_count = libusb_get_device_list(libusb_ctx, &devices);
195 195
196 for (int i = 0; i < cnt; i++) { 196 for (std::size_t index = 0; index < device_count; ++index) {
197 if (CheckDeviceAccess(devs[i])) { 197 if (CheckDeviceAccess(devices[index])) {
198 // GC Adapter found and accessible, registering it 198 // GC Adapter found and accessible, registering it
199 GetGCEndpoint(devs[i]); 199 GetGCEndpoint(devices[index]);
200 break; 200 break;
201 } 201 }
202 } 202 }
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index 06e16880f..a9de9fedf 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -39,9 +39,9 @@ public:
39 bool GetStatus() const override { 39 bool GetStatus() const override {
40 const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; 40 const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f;
41 if (trigger_if_greater) { 41 if (trigger_if_greater) {
42 return axis_value > 0.10f; // TODO(ameerj) : Fix threshold. 42 return axis_value > threshold; // TODO(ameerj) : Fix threshold.
43 } 43 }
44 return axis_value < -0.10f; 44 return axis_value < -threshold;
45 } 45 }
46 46
47private: 47private:
@@ -87,16 +87,13 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
87 Common::ParamPackage params; 87 Common::ParamPackage params;
88 GCAdapter::GCPadStatus pad; 88 GCAdapter::GCPadStatus pad;
89 auto& queue = adapter->GetPadQueue(); 89 auto& queue = adapter->GetPadQueue();
90 for (int port = 0; port < queue.size(); port++) { 90 for (std::size_t port = 0; port < queue.size(); ++port) {
91 while (queue[port].Pop(pad)) { 91 while (queue[port].Pop(pad)) {
92 // This while loop will break on the earliest detected button 92 // This while loop will break on the earliest detected button
93 params.Set("engine", "gcpad"); 93 params.Set("engine", "gcpad");
94 params.Set("port", port); 94 params.Set("port", static_cast<int>(port));
95 // I was debating whether to keep these verbose for ease of reading 95 for (const auto& button : GCAdapter::PadButtonArray) {
96 // or to use a while loop shifting the bits to test and set the value. 96 const u16 button_value = static_cast<u16>(button);
97
98 for (auto button : GCAdapter::PadButtonArray) {
99 u16 button_value = static_cast<u16>(button);
100 if (pad.button & button_value) { 97 if (pad.button & button_value) {
101 params.Set("button", button_value); 98 params.Set("button", button_value);
102 break; 99 break;
@@ -228,7 +225,7 @@ void GCAnalogFactory::EndConfiguration() {
228Common::ParamPackage GCAnalogFactory::GetNextInput() { 225Common::ParamPackage GCAnalogFactory::GetNextInput() {
229 GCAdapter::GCPadStatus pad; 226 GCAdapter::GCPadStatus pad;
230 auto& queue = adapter->GetPadQueue(); 227 auto& queue = adapter->GetPadQueue();
231 for (int port = 0; port < queue.size(); port++) { 228 for (std::size_t port = 0; port < queue.size(); ++port) {
232 while (queue[port].Pop(pad)) { 229 while (queue[port].Pop(pad)) {
233 if (pad.axis == GCAdapter::PadAxes::Undefined || 230 if (pad.axis == GCAdapter::PadAxes::Undefined ||
234 std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) { 231 std::abs((pad.axis_value - 128.0f) / 128.0f) < 0.1) {