summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/GCAdapter.cpp
diff options
context:
space:
mode:
authorPokechu22 <Pokechu022@gmail.com>2022-04-19 15:21:23 -0700
committerPokechu22 <Pokechu022@gmail.com>2022-06-02 19:39:36 -0700
commit55922e6d17442723e57f7435b758c5450aa12f11 (patch)
tree3e422d36593a8991d57406bda292c23cd90412bc /Source/Core/InputCommon/GCAdapter.cpp
parent682d86f4daaba99294f17d1534f3f98fd9bc2f25 (diff)
GCAdapter: Convert ControllerType to an enum class
Diffstat (limited to 'Source/Core/InputCommon/GCAdapter.cpp')
-rw-r--r--Source/Core/InputCommon/GCAdapter.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/Source/Core/InputCommon/GCAdapter.cpp b/Source/Core/InputCommon/GCAdapter.cpp
index d13f743817..25e14a7e5d 100644
--- a/Source/Core/InputCommon/GCAdapter.cpp
+++ b/Source/Core/InputCommon/GCAdapter.cpp
@@ -82,9 +82,15 @@ static bool s_detected = false;
static int s_fd = 0;
#endif
-static std::array<u8, SerialInterface::MAX_SI_CHANNELS> s_controller_type = {
- ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE,
- ControllerTypes::CONTROLLER_NONE, ControllerTypes::CONTROLLER_NONE};
+enum class ControllerType : u8
+{
+ 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{};
constexpr size_t CONTROLER_INPUT_PAYLOAD_EXPECTED_SIZE = 37;
@@ -471,7 +477,7 @@ static void Setup()
if (s_status < 0)
s_status = NO_ADAPTER_DETECTED;
- s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
+ s_controller_type.fill(ControllerType::None);
s_controller_rumble.fill(0);
s_libusb_context->GetDeviceList([](libusb_device* device) {
@@ -667,7 +673,7 @@ static void Reset()
s_read_adapter_thread.join();
#endif
- s_controller_type.fill(ControllerTypes::CONTROLLER_NONE);
+ s_controller_type.fill(ControllerType::None);
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
s_status = NO_ADAPTER_DETECTED;
@@ -731,9 +737,9 @@ GCPadStatus Input(int chan)
else
{
bool get_origin = false;
- u8 type = controller_payload_copy[1 + (9 * chan)] >> 4;
- if (type != ControllerTypes::CONTROLLER_NONE &&
- s_controller_type[chan] == ControllerTypes::CONTROLLER_NONE)
+ // TODO: What do the other bits here indicate? Does casting to an enum like this make sense?
+ const auto type = static_cast<ControllerType>(controller_payload_copy[1 + (9 * chan)] >> 4);
+ if (type != ControllerType::None && s_controller_type[chan] == ControllerType::None)
{
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "New device connected to Port {} of Type: {:02x}",
chan + 1, controller_payload_copy[1 + (9 * chan)]);
@@ -742,7 +748,7 @@ GCPadStatus Input(int chan)
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 b2 = controller_payload_copy[1 + (9 * chan) + 2];
@@ -801,12 +807,12 @@ GCPadStatus Input(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)
{
- s_controller_type[chan] = ControllerTypes::CONTROLLER_NONE;
+ s_controller_type[chan] = ControllerType::None;
}
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
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;
#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION