summaryrefslogtreecommitdiff
path: root/src/core/hid/emulated_console.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid/emulated_console.h')
-rw-r--r--src/core/hid/emulated_console.h192
1 files changed, 0 insertions, 192 deletions
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
deleted file mode 100644
index fae15a556..000000000
--- a/src/core/hid/emulated_console.h
+++ /dev/null
@@ -1,192 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7#include <functional>
8#include <memory>
9#include <mutex>
10#include <optional>
11#include <unordered_map>
12
13#include "common/common_funcs.h"
14#include "common/common_types.h"
15#include "common/input.h"
16#include "common/param_package.h"
17#include "common/point.h"
18#include "common/quaternion.h"
19#include "common/vector_math.h"
20#include "core/hid/hid_types.h"
21#include "core/hid/motion_input.h"
22
23namespace Core::HID {
24static constexpr std::size_t MaxTouchDevices = 32;
25static constexpr std::size_t MaxActiveTouchInputs = 16;
26
27struct ConsoleMotionInfo {
28 Common::Input::MotionStatus raw_status{};
29 MotionInput emulated{};
30};
31
32using ConsoleMotionDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, 2>;
33using TouchDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, MaxTouchDevices>;
34
35using ConsoleMotionParams = std::array<Common::ParamPackage, 2>;
36using TouchParams = std::array<Common::ParamPackage, MaxTouchDevices>;
37
38using ConsoleMotionValues = ConsoleMotionInfo;
39using TouchValues = std::array<Common::Input::TouchStatus, MaxTouchDevices>;
40
41// Contains all motion related data that is used on the services
42struct ConsoleMotion {
43 Common::Vec3f accel{};
44 Common::Vec3f gyro{};
45 Common::Vec3f rotation{};
46 std::array<Common::Vec3f, 3> orientation{};
47 Common::Quaternion<f32> quaternion{};
48 Common::Vec3f gyro_bias{};
49 f32 verticalization_error{};
50 bool is_at_rest{};
51};
52
53using TouchFingerState = std::array<TouchFinger, MaxActiveTouchInputs>;
54
55struct ConsoleStatus {
56 // Data from input_common
57 ConsoleMotionValues motion_values{};
58 TouchValues touch_values{};
59
60 // Data for HID services
61 ConsoleMotion motion_state{};
62 TouchFingerState touch_state{};
63};
64
65enum class ConsoleTriggerType {
66 Motion,
67 Touch,
68 All,
69};
70
71struct ConsoleUpdateCallback {
72 std::function<void(ConsoleTriggerType)> on_change;
73};
74
75class EmulatedConsole {
76public:
77 /**
78 * Contains all input data within the emulated switch console tablet such as touch and motion
79 */
80 explicit EmulatedConsole();
81 ~EmulatedConsole();
82
83 YUZU_NON_COPYABLE(EmulatedConsole);
84 YUZU_NON_MOVEABLE(EmulatedConsole);
85
86 /// Removes all callbacks created from input devices
87 void UnloadInput();
88
89 /**
90 * Sets the emulated console into configuring mode
91 * This prevents the modification of the HID state of the emulated console by input commands
92 */
93 void EnableConfiguration();
94
95 /// Returns the emulated console into normal mode, allowing the modification of the HID state
96 void DisableConfiguration();
97
98 /// Returns true if the emulated console is in configuring mode
99 bool IsConfiguring() const;
100
101 /// Reload all input devices
102 void ReloadInput();
103
104 /// Overrides current mapped devices with the stored configuration and reloads all input devices
105 void ReloadFromSettings();
106
107 /// Saves the current mapped configuration
108 void SaveCurrentConfig();
109
110 /// Reverts any mapped changes made that weren't saved
111 void RestoreConfig();
112
113 // Returns the current mapped motion device
114 Common::ParamPackage GetMotionParam() const;
115
116 /**
117 * Updates the current mapped motion device
118 * @param param ParamPackage with controller data to be mapped
119 */
120 void SetMotionParam(Common::ParamPackage param);
121
122 /// Returns the latest status of motion input from the console with parameters
123 ConsoleMotionValues GetMotionValues() const;
124
125 /// Returns the latest status of touch input from the console with parameters
126 TouchValues GetTouchValues() const;
127
128 /// Returns the latest status of motion input from the console
129 ConsoleMotion GetMotion() const;
130
131 /// Returns the latest status of touch input from the console
132 TouchFingerState GetTouch() const;
133
134 /**
135 * Adds a callback to the list of events
136 * @param update_callback A ConsoleUpdateCallback that will be triggered
137 * @return an unique key corresponding to the callback index in the list
138 */
139 int SetCallback(ConsoleUpdateCallback update_callback);
140
141 /**
142 * Removes a callback from the list stopping any future events to this object
143 * @param key Key corresponding to the callback index in the list
144 */
145 void DeleteCallback(int key);
146
147private:
148 /// Creates and stores the touch params
149 void SetTouchParams();
150
151 /**
152 * Updates the motion status of the console
153 * @param callback A CallbackStatus containing gyro and accelerometer data
154 */
155 void SetMotion(const Common::Input::CallbackStatus& callback);
156
157 /**
158 * Updates the touch status of the console
159 * @param callback A CallbackStatus containing the touch position
160 * @param index Finger ID to be updated
161 */
162 void SetTouch(const Common::Input::CallbackStatus& callback, std::size_t index);
163
164 std::optional<std::size_t> GetIndexFromFingerId(std::size_t finger_id) const;
165
166 std::optional<std::size_t> GetNextFreeIndex() const;
167
168 /**
169 * Triggers a callback that something has changed on the console status
170 * @param type Input type of the event to trigger
171 */
172 void TriggerOnChange(ConsoleTriggerType type);
173
174 bool is_configuring{false};
175 f32 motion_sensitivity{0.01f};
176
177 ConsoleMotionParams motion_params;
178 TouchParams touch_params;
179
180 ConsoleMotionDevices motion_devices;
181 TouchDevices touch_devices;
182
183 mutable std::mutex mutex;
184 mutable std::mutex callback_mutex;
185 std::unordered_map<int, ConsoleUpdateCallback> callback_list;
186 int last_callback_key = 0;
187
188 // Stores the current status of all console input
189 ConsoleStatus console;
190};
191
192} // namespace Core::HID