summaryrefslogtreecommitdiff
path: root/src/core/frontend/applets/controller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/frontend/applets/controller.cpp')
-rw-r--r--src/core/frontend/applets/controller.cpp51
1 files changed, 21 insertions, 30 deletions
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp
index ca1edce15..30500ef1e 100644
--- a/src/core/frontend/applets/controller.cpp
+++ b/src/core/frontend/applets/controller.cpp
@@ -5,16 +5,16 @@
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "core/frontend/applets/controller.h" 7#include "core/frontend/applets/controller.h"
8#include "core/hle/service/hid/controllers/npad.h" 8#include "core/hid/emulated_controller.h"
9#include "core/hle/service/hid/hid.h" 9#include "core/hid/hid_core.h"
10#include "core/hle/service/sm/sm.h" 10#include "core/hid/hid_types.h"
11 11
12namespace Core::Frontend { 12namespace Core::Frontend {
13 13
14ControllerApplet::~ControllerApplet() = default; 14ControllerApplet::~ControllerApplet() = default;
15 15
16DefaultControllerApplet::DefaultControllerApplet(Service::SM::ServiceManager& service_manager_) 16DefaultControllerApplet::DefaultControllerApplet(HID::HIDCore& hid_core_)
17 : service_manager{service_manager_} {} 17 : hid_core{hid_core_} {}
18 18
19DefaultControllerApplet::~DefaultControllerApplet() = default; 19DefaultControllerApplet::~DefaultControllerApplet() = default;
20 20
@@ -22,24 +22,20 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb
22 const ControllerParameters& parameters) const { 22 const ControllerParameters& parameters) const {
23 LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!"); 23 LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!");
24 24
25 auto& npad =
26 service_manager.GetService<Service::HID::Hid>("hid")
27 ->GetAppletResource()
28 ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad);
29
30 auto& players = Settings::values.players.GetValue();
31
32 const std::size_t min_supported_players = 25 const std::size_t min_supported_players =
33 parameters.enable_single_mode ? 1 : parameters.min_players; 26 parameters.enable_single_mode ? 1 : parameters.min_players;
34 27
35 // Disconnect Handheld first. 28 // Disconnect Handheld first.
36 npad.DisconnectNpadAtIndex(8); 29 auto* handheld =hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld);
30 handheld->Disconnect();
37 31
38 // Deduce the best configuration based on the input parameters. 32 // Deduce the best configuration based on the input parameters.
39 for (std::size_t index = 0; index < players.size() - 2; ++index) { 33 for (std::size_t index = 0; index < hid_core.available_controllers - 2; ++index) {
34 auto* controller = hid_core.GetEmulatedControllerByIndex(index);
35
40 // First, disconnect all controllers regardless of the value of keep_controllers_connected. 36 // First, disconnect all controllers regardless of the value of keep_controllers_connected.
41 // This makes it easy to connect the desired controllers. 37 // This makes it easy to connect the desired controllers.
42 npad.DisconnectNpadAtIndex(index); 38 controller->Disconnect();
43 39
44 // Only connect the minimum number of required players. 40 // Only connect the minimum number of required players.
45 if (index >= min_supported_players) { 41 if (index >= min_supported_players) {
@@ -49,32 +45,27 @@ void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callb
49 // Connect controllers based on the following priority list from highest to lowest priority: 45 // Connect controllers based on the following priority list from highest to lowest priority:
50 // Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld 46 // Pro Controller -> Dual Joycons -> Left Joycon/Right Joycon -> Handheld
51 if (parameters.allow_pro_controller) { 47 if (parameters.allow_pro_controller) {
52 npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( 48 controller->SetNpadType(Core::HID::NpadType::ProController);
53 Settings::ControllerType::ProController), 49 controller->Connect();
54 index);
55 } else if (parameters.allow_dual_joycons) { 50 } else if (parameters.allow_dual_joycons) {
56 npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( 51 controller->SetNpadType(Core::HID::NpadType::JoyconDual);
57 Settings::ControllerType::DualJoyconDetached), 52 controller->Connect();
58 index);
59 } else if (parameters.allow_left_joycon && parameters.allow_right_joycon) { 53 } else if (parameters.allow_left_joycon && parameters.allow_right_joycon) {
60 // Assign left joycons to even player indices and right joycons to odd player indices. 54 // Assign left joycons to even player indices and right joycons to odd player indices.
61 // We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and 55 // We do this since Captain Toad Treasure Tracker expects a left joycon for Player 1 and
62 // a right Joycon for Player 2 in 2 Player Assist mode. 56 // a right Joycon for Player 2 in 2 Player Assist mode.
63 if (index % 2 == 0) { 57 if (index % 2 == 0) {
64 npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( 58 controller->SetNpadType(Core::HID::NpadType::JoyconLeft);
65 Settings::ControllerType::LeftJoycon), 59 controller->Connect();
66 index);
67 } else { 60 } else {
68 npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( 61 controller->SetNpadType(Core::HID::NpadType::JoyconRight);
69 Settings::ControllerType::RightJoycon), 62 controller->Connect();
70 index);
71 } 63 }
72 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld && 64 } else if (index == 0 && parameters.enable_single_mode && parameters.allow_handheld &&
73 !Settings::values.use_docked_mode.GetValue()) { 65 !Settings::values.use_docked_mode.GetValue()) {
74 // We should *never* reach here under any normal circumstances. 66 // We should *never* reach here under any normal circumstances.
75 npad.AddNewControllerAt(Core::HID::EmulatedController::MapSettingsTypeToNPad( 67 controller->SetNpadType(Core::HID::NpadType::Handheld);
76 Settings::ControllerType::Handheld), 68 controller->Connect();
77 index);
78 } else { 69 } else {
79 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!"); 70 UNREACHABLE_MSG("Unable to add a new controller based on the given parameters!");
80 } 71 }