GCAdapter: Convert ControllerType to an enum class
This commit is contained in:
parent
682d86f4da
commit
55922e6d17
|
@ -82,9 +82,15 @@ static bool s_detected = false;
|
||||||
static int s_fd = 0;
|
static int s_fd = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::array<u8, SerialInterface::MAX_SI_CHANNELS> s_controller_type = {
|
enum class ControllerType : u8
|
||||||
ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE,
|
{
|
||||||
ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE};
|
None = 0,
|
||||||
|
Wired = 1,
|
||||||
|
Wireless = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::array<ControllerType, SerialInterface::MAX_SI_CHANNELS> s_controller_type = {
|
||||||
|
ControllerType::None, ControllerType::None, ControllerType::None, ControllerType::None};
|
||||||
static std::array<u8, SerialInterface::MAX_SI_CHANNELS> s_controller_rumble{};
|
static std::array<u8, SerialInterface::MAX_SI_CHANNELS> s_controller_rumble{};
|
||||||
|
|
||||||
constexpr size_t CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE = 37;
|
constexpr size_t CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE = 37;
|
||||||
|
@ -471,7 +477,7 @@ static void Setup()
|
||||||
if (s_status < 0)
|
if (s_status < 0)
|
||||||
s_status = NO_ADAPTER_DETECTED;
|
s_status = NO_ADAPTER_DETECTED;
|
||||||
|
|
||||||
s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
|
s_controller_type.fill(ControllerType::None);
|
||||||
s_controller_rumble.fill(0);
|
s_controller_rumble.fill(0);
|
||||||
|
|
||||||
s_libusb_context->GetDeviceList([](libusb_device* device) {
|
s_libusb_context->GetDeviceList([](libusb_device* device) {
|
||||||
|
@ -667,7 +673,7 @@ static void Reset()
|
||||||
s_read_adapter_thread.join();
|
s_read_adapter_thread.join();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
|
s_controller_type.fill(ControllerType::None);
|
||||||
|
|
||||||
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
||||||
s_status = NO_ADAPTER_DETECTED;
|
s_status = NO_ADAPTER_DETECTED;
|
||||||
|
@ -731,9 +737,9 @@ GCPadStatus Input(int chan)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool get_origin = false;
|
bool get_origin = false;
|
||||||
u8 type = controller_payload_copy[1 + (9 * chan)] >> 4;
|
// TODO: What do the other bits here indicate? Does casting to an enum like this make sense?
|
||||||
if (type != ControllerTypes::CONTROLLER_NONE &&
|
const auto type = static_cast<ControllerType>(controller_payload_copy[1 + (9 * chan)] >> 4);
|
||||||
s_controller_type[chan] == ControllerTypes::CONTROLLER_NONE)
|
if (type != ControllerType::None && s_controller_type[chan] == ControllerType::None)
|
||||||
{
|
{
|
||||||
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "New device connected to Port {} of Type: {:02x}",
|
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "New device connected to Port {} of Type: {:02x}",
|
||||||
chan + 1, controller_payload_copy[1 + (9 * chan)]);
|
chan + 1, controller_payload_copy[1 + (9 * chan)]);
|
||||||
|
@ -742,7 +748,7 @@ GCPadStatus Input(int chan)
|
||||||
|
|
||||||
s_controller_type[chan] = type;
|
s_controller_type[chan] = type;
|
||||||
|
|
||||||
if (s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE)
|
if (s_controller_type[chan] != ControllerType::None)
|
||||||
{
|
{
|
||||||
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
u8 b1 = controller_payload_copy[1 + (9 * chan) + 1];
|
||||||
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
u8 b2 = controller_payload_copy[1 + (9 * chan) + 2];
|
||||||
|
@ -801,12 +807,12 @@ GCPadStatus Input(int chan)
|
||||||
|
|
||||||
bool DeviceConnected(int chan)
|
bool DeviceConnected(int chan)
|
||||||
{
|
{
|
||||||
return s_controller_type[chan] != ControllerTypes::CONTROLLER_NONE;
|
return s_controller_type[chan] != ControllerType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetDeviceType(int chan)
|
void ResetDeviceType(int chan)
|
||||||
{
|
{
|
||||||
s_controller_type[chan] = ControllerTypes::CONTROLLER_NONE;
|
s_controller_type[chan] = ControllerType::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UseAdapter()
|
bool UseAdapter()
|
||||||
|
@ -874,7 +880,7 @@ void Output(int chan, u8 rumble_command)
|
||||||
|
|
||||||
// Skip over rumble commands if it has not changed or the controller is wireless
|
// Skip over rumble commands if it has not changed or the controller is wireless
|
||||||
if (rumble_command != s_controller_rumble[chan] &&
|
if (rumble_command != s_controller_rumble[chan] &&
|
||||||
s_controller_type[chan] != ControllerTypes::CONTROLLER_WIRELESS)
|
s_controller_type[chan] != ControllerType::Wireless)
|
||||||
{
|
{
|
||||||
s_controller_rumble[chan] = rumble_command;
|
s_controller_rumble[chan] = rumble_command;
|
||||||
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
|
||||||
|
|
|
@ -11,12 +11,6 @@ struct GCPadStatus;
|
||||||
|
|
||||||
namespace GCAdapter
|
namespace GCAdapter
|
||||||
{
|
{
|
||||||
enum ControllerTypes
|
|
||||||
{
|
|
||||||
CONTROLLER_NONE = 0,
|
|
||||||
CONTROLLER_WIRED = 1,
|
|
||||||
CONTROLLER_WIRELESS = 2
|
|
||||||
};
|
|
||||||
void Init();
|
void Init();
|
||||||
void ResetRumble();
|
void ResetRumble();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
Loading…
Reference in New Issue