|
|
@ -5,16 +5,16 @@ |
|
|
#include "common/assert.h"
|
|
|
#include "common/assert.h"
|
|
|
#include "common/logging/log.h"
|
|
|
#include "common/logging/log.h"
|
|
|
#include "core/frontend/applets/controller.h"
|
|
|
#include "core/frontend/applets/controller.h"
|
|
|
#include "core/hle/service/hid/controllers/npad.h"
|
|
|
|
|
|
#include "core/hle/service/hid/hid.h"
|
|
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
|
|
|
|
|
|
|
|
#include "core/hid/emulated_controller.h"
|
|
|
|
|
|
#include "core/hid/hid_core.h"
|
|
|
|
|
|
#include "core/hid/hid_types.h"
|
|
|
|
|
|
|
|
|
namespace Core::Frontend { |
|
|
namespace Core::Frontend { |
|
|
|
|
|
|
|
|
ControllerApplet::~ControllerApplet() = default; |
|
|
ControllerApplet::~ControllerApplet() = default; |
|
|
|
|
|
|
|
|
DefaultControllerApplet::DefaultControllerApplet(Service::SM::ServiceManager& service_manager_) |
|
|
|
|
|
: service_manager{service_manager_} {} |
|
|
|
|
|
|
|
|
DefaultControllerApplet::DefaultControllerApplet(HID::HIDCore& hid_core_) |
|
|
|
|
|
: hid_core{hid_core_} {} |
|
|
|
|
|
|
|
|
DefaultControllerApplet::~DefaultControllerApplet() = default; |
|
|
DefaultControllerApplet::~DefaultControllerApplet() = default; |
|
|
|
|
|
|
|
|
@ -22,24 +22,20 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb |
|
|
const ControllerParameters& parameters) const { |
|
|
const ControllerParameters& parameters) const { |
|
|
LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!"); |
|
|
LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!"); |
|
|
|
|
|
|
|
|
auto& npad = |
|
|
|
|
|
service_manager.GetService<Service::HID::Hid>("hid") |
|
|
|
|
|
->GetAppletResource() |
|
|
|
|
|
->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad); |
|
|
|
|
|
|
|
|
|
|
|
auto& players = Settings::values.players.GetValue(); |
|
|
|
|
|
|
|
|
|
|
|
const std::size_t min_supported_players = |
|
|
const std::size_t min_supported_players = |
|
|
parameters.enable_single_mode ? 1 : parameters.min_players; |
|
|
parameters.enable_single_mode ? 1 : parameters.min_players; |
|
|
|
|
|
|
|
|
// Disconnect Handheld first.
|
|
|
// Disconnect Handheld first.
|
|
|
npad.DisconnectNpadAtIndex(8); |
|
|
|
|
|
|
|
|
auto* handheld =hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); |
|
|
|
|
|
handheld->Disconnect(); |
|
|
|
|
|
|
|
|
// Deduce the best configuration based on the input parameters.
|
|
|
// Deduce the best configuration based on the input parameters.
|
|
|
for (std::size_t index = 0; index < players.size() - 2; ++index) { |
|
|
|
|
|
|
|
|
for (std::size_t index = 0; index < hid_core.available_controllers - 2; ++index) { |
|
|
|
|
|
auto* controller = hid_core.GetEmulatedControllerByIndex(index); |
|
|
|
|
|
|
|
|
// First, disconnect all controllers regardless of the value of keep_controllers_connected.
|
|
|
// First, disconnect all controllers regardless of the value of keep_controllers_connected.
|
|
|
// This makes it easy to connect the desired controllers.
|
|
|
// This makes it easy to connect the desired controllers.
|
|
|
npad.DisconnectNpadAtIndex(index); |
|
|
|
|
|
|
|
|
controller->Disconnect(); |
|
|
|
|
|
|
|
|
// Only connect the minimum number of required players.
|
|
|
// Only connect the minimum number of required players.
|
|
|
if (index >= min_supported_players) { |
|
|
if (index >= min_supported_players) { |
|
|
@ -49,32 +45,27 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb |
|
|
// Connect controllers based on the following priority list from highest to lowest priority:
|
|
|
// Connect controllers based on the following priority list from highest to lowest priority:
|
|
|
// Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
|
|
|
// Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
|
|
|
if (parameters.allow_pro_controller) { |
|
|
if (parameters.allow_pro_controller) { |
|
|
npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( |
|
|
|
|
|
Settings::ControllerType::ProController), |
|
|
|
|
|
index); |
|
|
|
|
|
|
|
|
controller->SetNpadType(Core::HID::NpadType::ProController); |
|
|
|
|
|
controller->Connect(); |
|
|
} else if (parameters.allow_dual_joycons) { |
|
|
} else if (parameters.allow_dual_joycons) { |
|
|
npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( |
|
|
|
|
|
Settings::ControllerType::DualJoyconDetached), |
|
|
|
|
|
index); |
|
|
|
|
|
|
|
|
controller->SetNpadType(Core::HID::NpadType::JoyconDual); |
|
|
|
|
|
controller->Connect(); |
|
|
} else if (parameters.allow_left_joycon && parameters.allow_right_joycon) { |
|
|
} else if (parameters.allow_left_joycon && parameters.allow_right_joycon) { |
|
|
// Assign left joycons to even player indices and right joycons to odd player indices.
|
|
|
// Assign left joycons to even player indices and right joycons to odd player indices.
|
|
|
// We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and
|
|
|
// We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and
|
|
|
// a right Joycon for Player 2 in 2 Player Assist mode.
|
|
|
// a right Joycon for Player 2 in 2 Player Assist mode.
|
|
|
if (index % 2 == 0) { |
|
|
if (index % 2 == 0) { |
|
|
npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( |
|
|
|
|
|
Settings::ControllerType::LeftJoycon), |
|
|
|
|
|
index); |
|
|
|
|
|
|
|
|
controller->SetNpadType(Core::HID::NpadType::JoyconLeft); |
|
|
|
|
|
controller->Connect(); |
|
|
} else { |
|
|
} else { |
|
|
npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( |
|
|
|
|
|
Settings::ControllerType::RightJoycon), |
|
|
|
|
|
index); |
|
|
|
|
|
|
|
|
controller->SetNpadType(Core::HID::NpadType::JoyconRight); |
|
|
|
|
|
controller->Connect(); |
|
|
} |
|
|
} |
|
|
} else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld && |
|
|
} else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld && |
|
|
!Settings::values.use_docked_mode.GetValue()) { |
|
|
!Settings::values.use_docked_mode.GetValue()) { |
|
|
// We should *never* reach here under any normal circumstances.
|
|
|
// We should *never* reach here under any normal circumstances.
|
|
|
npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( |
|
|
|
|
|
Settings::ControllerType::Handheld), |
|
|
|
|
|
index); |
|
|
|
|
|
|
|
|
controller->SetNpadType(Core::HID::NpadType::Handheld); |
|
|
|
|
|
controller->Connect(); |
|
|
} else { |
|
|
} else { |
|
|
UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!"); |
|
|
UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!"); |
|
|
} |
|
|
} |
|
|
|