Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions UnleashedRecomp/hid/driver/sdl_hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Controller

SDL_GameControllerType GetControllerType() const
{
return SDL_GameControllerGetType(controller);
return SDL_GameControllerTypeForIndex(index);
}

hid::EInputDevice GetInputDevice() const
Expand All @@ -49,22 +49,9 @@ class Controller
case SDL_CONTROLLER_TYPE_PS4:
case SDL_CONTROLLER_TYPE_PS5:
return hid::EInputDevice::PlayStation;
case SDL_CONTROLLER_TYPE_XBOX360:
case SDL_CONTROLLER_TYPE_XBOXONE:
return hid::EInputDevice::Xbox;
default:
return hid::EInputDevice::Unknown;
}
}

const char* GetControllerName() const
{
auto result = SDL_GameControllerName(controller);

if (!result)
return "Unknown Device";

return result;
return hid::EInputDevice::Xbox;
}

void Close()
Expand Down Expand Up @@ -191,21 +178,12 @@ static void SetControllerInputDevice(Controller* controller)
hid::g_inputDeviceController = hid::g_inputDevice;

auto controllerType = (hid::EInputDeviceExplicit)controller->GetControllerType();
auto controllerName = controller->GetControllerName();

// Only proceed if the controller type changes.
if (hid::g_inputDeviceExplicit != controllerType)
{
hid::g_inputDeviceExplicit = controllerType;

if (controllerType == hid::EInputDeviceExplicit::Unknown)
{
LOGFN("Detected controller: {} (Unknown Controller Type)", controllerName);
}
else
{
LOGFN("Detected controller: {}", controllerName);
}
LOGFN("Detected controller: {}", hid::GetInputDeviceName());
}
}

Expand Down Expand Up @@ -332,8 +310,6 @@ void hid::Init()
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_WII, "1");
SDL_SetHint(SDL_HINT_XINPUT_ENABLED, "1");

SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0"); // Uses Button Labels. This hint is disabled for Nintendo Controllers.

SDL_InitSubSystem(SDL_INIT_EVENTS);
SDL_AddEventWatch(HID_OnSDLEvent, nullptr);
Expand Down
56 changes: 56 additions & 0 deletions UnleashedRecomp/hid/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,59 @@ bool hid::IsInputDeviceController()
return hid::g_inputDevice != hid::EInputDevice::Keyboard &&
hid::g_inputDevice != hid::EInputDevice::Mouse;
}

std::string hid::GetInputDeviceName()
{
switch (g_inputDevice)
{
case EInputDevice::Keyboard:
return "Keyboard";

case EInputDevice::Mouse:
return "Mouse";
}

switch (g_inputDeviceExplicit)
{
case EInputDeviceExplicit::Xbox360:
return "Xbox 360";

case EInputDeviceExplicit::XboxOne:
return "Xbox One";

case EInputDeviceExplicit::DualShock3:
return "DualShock 3";

case EInputDeviceExplicit::DualShock4:
return "DualShock 4";

case EInputDeviceExplicit::SwitchPro:
return "Nintendo Switch Pro";

case EInputDeviceExplicit::Virtual:
return "Virtual";

case EInputDeviceExplicit::DualSense:
return "DualSense";

case EInputDeviceExplicit::Luna:
return "Amazon Luna";

case EInputDeviceExplicit::Stadia:
return "Google Stadia";

case EInputDeviceExplicit::NvShield:
return "NVIDIA Shield";

case EInputDeviceExplicit::SwitchJCLeft:
return "Nintendo Switch Joy-Con (Left)";

case EInputDeviceExplicit::SwitchJCRight:
return "Nintendo Switch Joy-Con (Right)";

case EInputDeviceExplicit::SwitchJCPair:
return "Nintendo Switch Joy-Con (Pair)";
}

return "Unknown";
}
2 changes: 1 addition & 1 deletion UnleashedRecomp/hid/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace hid
{
enum class EInputDevice
{
Unknown,
Keyboard,
Mouse,
Xbox,
Expand Down Expand Up @@ -46,4 +45,5 @@ namespace hid
void SetProhibitedInputs(uint16_t wButtons = 0, bool leftStick = false, bool rightStick = false);
bool IsInputAllowed();
bool IsInputDeviceController();
std::string GetInputDeviceName();
}
Loading