std::arrays where appropriate, clear q in adapter class, other touch ups
This commit is contained in:
parent
5f0fa4cb82
commit
968d631aa5
5 changed files with 15 additions and 27 deletions
|
@ -134,7 +134,7 @@ void Adapter::Read() {
|
||||||
payload_size = payload_size_in;
|
payload_size = payload_size_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
GCPadStatus pad[4];
|
std::array<GCPadStatus, 4> pad;
|
||||||
if (payload_size != sizeof(controller_payload_copy) ||
|
if (payload_size != sizeof(controller_payload_copy) ||
|
||||||
controller_payload_copy[0] != LIBUSB_DT_HID) {
|
controller_payload_copy[0] != LIBUSB_DT_HID) {
|
||||||
LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size,
|
LOG_ERROR(Input, "error reading payload (size: %d, type: %02x)", payload_size,
|
||||||
|
@ -224,9 +224,7 @@ void Adapter::Setup() {
|
||||||
current_status = NO_ADAPTER_DETECTED;
|
current_status = NO_ADAPTER_DETECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
adapter_controllers_status.fill(ControllerTypes::None);
|
||||||
adapter_controllers_status[i] = ControllerTypes::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
libusb_device** devs; // pointer to list of connected usb devices
|
libusb_device** devs; // pointer to list of connected usb devices
|
||||||
|
|
||||||
|
@ -332,9 +330,7 @@ void Adapter::Reset() {
|
||||||
adapter_input_thread.join();
|
adapter_input_thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
adapter_controllers_status.fill(ControllerTypes::None);
|
||||||
adapter_controllers_status[i] = ControllerTypes::None;
|
|
||||||
}
|
|
||||||
|
|
||||||
current_status = NO_ADAPTER_DETECTED;
|
current_status = NO_ADAPTER_DETECTED;
|
||||||
|
|
||||||
|
@ -354,10 +350,16 @@ void Adapter::ResetDeviceType(int port) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adapter::BeginConfiguration() {
|
void Adapter::BeginConfiguration() {
|
||||||
|
for (auto& pq : pad_queue) {
|
||||||
|
pq.Clear();
|
||||||
|
}
|
||||||
configuring = true;
|
configuring = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adapter::EndConfiguration() {
|
void Adapter::EndConfiguration() {
|
||||||
|
for (auto& pq : pad_queue) {
|
||||||
|
pq.Clear();
|
||||||
|
}
|
||||||
configuring = false;
|
configuring = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,8 @@ public:
|
||||||
|
|
||||||
std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
|
std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue();
|
||||||
std::array<GCState, 4>& GetPadState();
|
std::array<GCState, 4>& GetPadState();
|
||||||
|
std::array<Common::SPSCQueue<GCPadStatus>, 4>& GetPadQueue() const;
|
||||||
|
std::array<GCState, 4>& GetPadState() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Singleton instance.
|
/// Singleton instance.
|
||||||
|
@ -139,8 +141,7 @@ private:
|
||||||
|
|
||||||
int current_status = NO_ADAPTER_DETECTED;
|
int current_status = NO_ADAPTER_DETECTED;
|
||||||
libusb_device_handle* usb_adapter_handle = nullptr;
|
libusb_device_handle* usb_adapter_handle = nullptr;
|
||||||
ControllerTypes adapter_controllers_status[4] = {ControllerTypes::None, ControllerTypes::None,
|
std::array<ControllerTypes, 4> adapter_controllers_status{};
|
||||||
ControllerTypes::None, ControllerTypes::None};
|
|
||||||
|
|
||||||
std::mutex s_mutex;
|
std::mutex s_mutex;
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,7 @@ GCButtonFactory::GCButtonFactory() {
|
||||||
adapter = GCAdapter::Adapter::GetInstance();
|
adapter = GCAdapter::Adapter::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
GCButton::~GCButton() {
|
GCButton::~GCButton() = default;
|
||||||
// GCAdapter::Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) {
|
std::unique_ptr<Input::ButtonDevice> GCButtonFactory::Create(const Common::ParamPackage& params) {
|
||||||
int button_id = params.Get("button", 0);
|
int button_id = params.Get("button", 0);
|
||||||
|
@ -163,17 +161,11 @@ Common::ParamPackage GCButtonFactory::GetNextInput() {
|
||||||
|
|
||||||
void GCButtonFactory::BeginConfiguration() {
|
void GCButtonFactory::BeginConfiguration() {
|
||||||
polling = true;
|
polling = true;
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
adapter->GetPadQueue()[i].Clear();
|
|
||||||
}
|
|
||||||
adapter->BeginConfiguration();
|
adapter->BeginConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCButtonFactory::EndConfiguration() {
|
void GCButtonFactory::EndConfiguration() {
|
||||||
polling = false;
|
polling = false;
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
adapter->GetPadQueue()[i].Clear();
|
|
||||||
}
|
|
||||||
adapter->EndConfiguration();
|
adapter->EndConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,17 +257,11 @@ std::unique_ptr<Input::AnalogDevice> GCAnalogFactory::Create(const Common::Param
|
||||||
|
|
||||||
void GCAnalogFactory::BeginConfiguration() {
|
void GCAnalogFactory::BeginConfiguration() {
|
||||||
polling = true;
|
polling = true;
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
adapter->GetPadQueue()[i].Clear();
|
|
||||||
}
|
|
||||||
adapter->BeginConfiguration();
|
adapter->BeginConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GCAnalogFactory::EndConfiguration() {
|
void GCAnalogFactory::EndConfiguration() {
|
||||||
polling = false;
|
polling = false;
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
adapter->GetPadQueue()[i].Clear();
|
|
||||||
}
|
|
||||||
adapter->EndConfiguration();
|
adapter->EndConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
void BeginConfiguration();
|
void BeginConfiguration();
|
||||||
void EndConfiguration();
|
void EndConfiguration();
|
||||||
|
|
||||||
bool IsPolling() {
|
bool IsPolling() const {
|
||||||
return polling;
|
return polling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public:
|
||||||
void BeginConfiguration();
|
void BeginConfiguration();
|
||||||
void EndConfiguration();
|
void EndConfiguration();
|
||||||
|
|
||||||
bool IsPolling() {
|
bool IsPolling() const {
|
||||||
return polling;
|
return polling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
|
|
Loading…
Reference in a new issue