summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/input_common/gcadapter/gc_adapter.cpp16
-rw-r--r--src/input_common/gcadapter/gc_adapter.h5
-rw-r--r--src/input_common/gcadapter/gc_poller.cpp16
-rw-r--r--src/input_common/gcadapter/gc_poller.h4
-rw-r--r--src/input_common/main.cpp1
5 files changed, 15 insertions, 27 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp
index 0696a96c7..498bd0d6e 100644
--- a/src/input_common/gcadapter/gc_adapter.cpp
+++ b/src/input_common/gcadapter/gc_adapter.cpp
@@ -134,7 +134,7 @@ void Adapter::Read() {
134 payload_size = payload_size_in; 134 payload_size = payload_size_in;
135 } 135 }
136 136
137 GCPadStatus pad[4]; 137 std::array<GCPadStatus, 4> pad;
138 if (payload_size != sizeof(controller_payload_copy) || 138 if (payload_size != sizeof(controller_payload_copy) ||
139 controller_payload_copy[0] != LIBUSB_DT_HID) { 139 controller_payload_copy[0] != LIBUSB_DT_HID) {
140 LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size, 140 LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size,
@@ -224,9 +224,7 @@ void Adapter::Setup() {
224 current_status = NO_ADAPTER_DETECTED; 224 current_status = NO_ADAPTER_DETECTED;
225 } 225 }
226 226
227 for (int i = 0; i < 4; i++) { 227 adapter_controllers_status.fill(ControllerTypes::None);
228 adapter_controllers_status[i] = ControllerTypes::None;
229 }
230 228
231 libusb_device** devs; // pointer to list of connected usb devices 229 libusb_device** devs; // pointer to list of connected usb devices
232 230
@@ -332,9 +330,7 @@ void Adapter::Reset() {
332 adapter_input_thread.join(); 330 adapter_input_thread.join();
333 } 331 }
334 332
335 for (int i = 0; i < 4; i++) { 333 adapter_controllers_status.fill(ControllerTypes::None);
336 adapter_controllers_status[i] = ControllerTypes::None;
337 }
338 334
339 current_status = NO_ADAPTER_DETECTED; 335 current_status = NO_ADAPTER_DETECTED;
340 336
@@ -354,10 +350,16 @@ void Adapter::ResetDeviceType(int port) {
354} 350}
355 351
356void Adapter::BeginConfiguration() { 352void Adapter::BeginConfiguration() {
353 for (auto& pq : pad_queue) {
354 pq.Clear();
355 }
357 configuring = true; 356 configuring = true;
358} 357}
359 358
360void Adapter::EndConfiguration() { 359void Adapter::EndConfiguration() {
360 for (auto& pq : pad_queue) {
361 pq.Clear();
362 }
361 configuring = false; 363 configuring = false;
362} 364}
363 365
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h
index a32ca0464..cb0dd0ab1 100644
--- a/src/input_common/gcadapter/gc_adapter.h
+++ b/src/input_common/gcadapter/gc_adapter.h
@@ -96,6 +96,8 @@ public:
96 96
97 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue(); 97 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
98 std::array<GCState, 4>& GetPadState(); 98 std::array<GCState, 4>& GetPadState();
99 std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;
100 std::array<GCState, 4>& GetPadState() const;
99 101
100private: 102private:
101 /// Singleton instance. 103 /// Singleton instance.
@@ -139,8 +141,7 @@ private:
139 141
140 int current_status = NO_ADAPTER_DETECTED; 142 int current_status = NO_ADAPTER_DETECTED;
141 libusb_device_handle* usb_adapter_handle = nullptr; 143 libusb_device_handle* usb_adapter_handle = nullptr;
142 ControllerTypes adapter_controllers_status[4] = {ControllerTypes::None, ControllerTypes::None, 144 std::array<ControllerTypes, 4> adapter_controllers_status{};
143 ControllerTypes::None, ControllerTypes::None};
144 145
145 std::mutex s_mutex; 146 std::mutex s_mutex;
146 147
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp
index 0e591baca..ac4126cb6 100644
--- a/src/input_common/gcadapter/gc_poller.cpp
+++ b/src/input_common/gcadapter/gc_poller.cpp
@@ -56,9 +56,7 @@ GCButtonFactory::GCButtonFactory() {
56 adapter = GCAdapter::Adapter::GetInstance(); 56 adapter = GCAdapter::Adapter::GetInstance();
57} 57}
58 58
59GCButton::~GCButton() { 59GCButton::~GCButton() = default;
60 // GCAdapter::Shutdown();
61}
62 60
63std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) { 61std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) {
64 int button_id = params.Get("button", 0); 62 int button_id = params.Get("button", 0);
@@ -163,17 +161,11 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
163 161
164void GCButtonFactory::BeginConfiguration() { 162void GCButtonFactory::BeginConfiguration() {
165 polling = true; 163 polling = true;
166 for (int i = 0; i < 4; i++) {
167 adapter->GetPadQueue()[i].Clear();
168 }
169 adapter->BeginConfiguration(); 164 adapter->BeginConfiguration();
170} 165}
171 166
172void GCButtonFactory::EndConfiguration() { 167void GCButtonFactory::EndConfiguration() {
173 polling = false; 168 polling = false;
174 for (int i = 0; i < 4; i++) {
175 adapter->GetPadQueue()[i].Clear();
176 }
177 adapter->EndConfiguration(); 169 adapter->EndConfiguration();
178} 170}
179 171
@@ -265,17 +257,11 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param
265 257
266void GCAnalogFactory::BeginConfiguration() { 258void GCAnalogFactory::BeginConfiguration() {
267 polling = true; 259 polling = true;
268 for (int i = 0; i < 4; i++) {
269 adapter->GetPadQueue()[i].Clear();
270 }
271 adapter->BeginConfiguration(); 260 adapter->BeginConfiguration();
272} 261}
273 262
274void GCAnalogFactory::EndConfiguration() { 263void GCAnalogFactory::EndConfiguration() {
275 polling = false; 264 polling = false;
276 for (int i = 0; i < 4; i++) {
277 adapter->GetPadQueue()[i].Clear();
278 }
279 adapter->EndConfiguration(); 265 adapter->EndConfiguration();
280} 266}
281 267
diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h
index 29b8c0b7c..31ff1c123 100644
--- a/src/input_common/gcadapter/gc_poller.h
+++ b/src/input_common/gcadapter/gc_poller.h
@@ -30,7 +30,7 @@ public:
30 void BeginConfiguration(); 30 void BeginConfiguration();
31 void EndConfiguration(); 31 void EndConfiguration();
32 32
33 bool IsPolling() { 33 bool IsPolling() const {
34 return polling; 34 return polling;
35 } 35 }
36 36
@@ -50,7 +50,7 @@ public:
50 void BeginConfiguration(); 50 void BeginConfiguration();
51 void EndConfiguration(); 51 void EndConfiguration();
52 52
53 bool IsPolling() { 53 bool IsPolling() const {
54 return polling; 54 return polling;
55 } 55 }
56 56
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp
index 536e5c80a..89dddf7cf 100644
--- a/src/input_common/main.cpp
+++ b/src/input_common/main.cpp
@@ -2,7 +2,6 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <iostream>
6#include <memory> 5#include <memory>
7#include <thread> 6#include <thread>
8#include <libusb.h> 7#include <libusb.h>