summaryrefslogtreecommitdiff
path: root/src/core/frontend/applets
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/frontend/applets')
-rw-r--r--src/core/frontend/applets/controller.cpp40
-rw-r--r--src/core/frontend/applets/controller.h45
2 files changed, 85 insertions, 0 deletions
diff --git a/src/core/frontend/applets/controller.cpp b/src/core/frontend/applets/controller.cpp
new file mode 100644
index 000000000..0fbc7932c
--- /dev/null
+++ b/src/core/frontend/applets/controller.cpp
@@ -0,0 +1,40 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "core/core.h"
6#include "core/frontend/applets/controller.h"
7#include "core/hle/service/hid/controllers/npad.h"
8#include "core/hle/service/hid/hid.h"
9#include "core/hle/service/sm/sm.h"
10
11namespace Core::Frontend {
12
13ControllerApplet::~ControllerApplet() = default;
14
15DefaultControllerApplet::~DefaultControllerApplet() = default;
16
17void DefaultControllerApplet::ReconfigureControllers(std::function<void()> callback,
18 ControllerParameters parameters) const {
19 LOG_INFO(Service_HID, "called, deducing the best configuration based on the given parameters!");
20
21 auto& npad =
22 Core::System::GetInstance()
23 .ServiceManager()
24 .GetService<Service::HID::Hid>("hid")
25 ->GetAppletResource()
26 ->GetController<Service::HID::Controller_NPad>(Service::HID::HidController::NPad);
27
28 auto& players = Settings::values.players;
29
30 // Deduce the best configuration based on the input parameters.
31 for (std::size_t index = 0; index < players.size(); ++index) {
32 // First, disconnect all controllers regardless of the value of keep_controllers_connected.
33 // This makes it easy to connect the desired controllers.
34 npad.DisconnectNPadAtIndex(index);
35 }
36
37 callback();
38}
39
40} // namespace Core::Frontend
diff --git a/src/core/frontend/applets/controller.h b/src/core/frontend/applets/controller.h
new file mode 100644
index 000000000..0908f2b69
--- /dev/null
+++ b/src/core/frontend/applets/controller.h
@@ -0,0 +1,45 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <functional>
8
9#include "common/common_types.h"
10
11namespace Core::Frontend {
12
13using BorderColor = std::array<u8, 4>;
14
15struct ControllerParameters {
16 s8 min_players{};
17 s8 max_players{};
18 bool keep_controllers_connected{};
19 bool enable_single_mode{};
20 bool enable_border_color{};
21 std::vector<BorderColor> border_colors{};
22 bool allow_pro_controller{};
23 bool allow_handheld{};
24 bool allow_dual_joycons{};
25 bool allow_left_joycon{};
26 bool allow_right_joycon{};
27};
28
29class ControllerApplet {
30public:
31 virtual ~ControllerApplet();
32
33 virtual void ReconfigureControllers(std::function<void()> callback,
34 ControllerParameters parameters) const = 0;
35};
36
37class DefaultControllerApplet final : public ControllerApplet {
38public:
39 ~DefaultControllerApplet() override;
40
41 void ReconfigureControllers(std::function<void()> callback,
42 ControllerParameters parameters) const override;
43};
44
45} // namespace Core::Frontend