summaryrefslogtreecommitdiffstats
path: root/src/core/hid
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2021-10-21 06:18:04 +0200
committerNarr the Reg <juangerman-13@hotmail.com>2021-11-25 03:30:25 +0100
commit85052b8662d9512077780f717fb2e168390ed705 (patch)
tree0d966f3f0fdcb7dbe85fe6e2ca83cf25c492ae4c /src/core/hid
parentconfiguration: Migrate controller settings to emulated controller (diff)
downloadyuzu-85052b8662d9512077780f717fb2e168390ed705.tar
yuzu-85052b8662d9512077780f717fb2e168390ed705.tar.gz
yuzu-85052b8662d9512077780f717fb2e168390ed705.tar.bz2
yuzu-85052b8662d9512077780f717fb2e168390ed705.tar.lz
yuzu-85052b8662d9512077780f717fb2e168390ed705.tar.xz
yuzu-85052b8662d9512077780f717fb2e168390ed705.tar.zst
yuzu-85052b8662d9512077780f717fb2e168390ed705.zip
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_console.cpp57
-rw-r--r--src/core/hid/emulated_console.h3
-rw-r--r--src/core/hid/emulated_controller.cpp4
3 files changed, 37 insertions, 27 deletions
diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp
index 7f7c8fd59..e82cf5990 100644
--- a/src/core/hid/emulated_console.cpp
+++ b/src/core/hid/emulated_console.cpp
@@ -20,27 +20,21 @@ void EmulatedConsole::ReloadFromSettings() {
ReloadInput();
}
-void EmulatedConsole::ReloadInput() {
- motion_devices = Input::CreateDevice<Input::InputDevice>(motion_params);
- if (motion_devices) {
- Input::InputCallback motion_callback{
- [this](Input::CallbackStatus callback) { SetMotion(callback); }};
- motion_devices->SetCallback(motion_callback);
- }
-
- // TODO: Fix this mess
+void EmulatedConsole::SetTouchParams() {
+ // TODO(german77): Support any number of fingers
std::size_t index = 0;
- const std::string mouse_device_string =
- fmt::format("engine:mouse,axis_x:10,axis_y:11,button:{}", index);
- touch_devices[index] = Input::CreateDeviceFromString<Input::InputDevice>(mouse_device_string);
- Input::InputCallback trigger_callbackk{
- [this, index](Input::CallbackStatus callback) { SetTouch(callback, index); }};
- touch_devices[index]->SetCallback(trigger_callbackk);
-
- index++;
+
+ // Hardcode mouse, touchscreen and cemuhook parameters
+ touch_params[index++] = Common::ParamPackage{"engine:mouse,axis_x:10,axis_y:11,button:0"};
+ touch_params[index++] = Common::ParamPackage{"engine:touch,axis_x:0,axis_y:1,button:0"};
+ touch_params[index++] = Common::ParamPackage{"engine:touch,axis_x:2,axis_y:3,button:1"};
+ touch_params[index++] = Common::ParamPackage{"engine:cemuhookudp,axis_x:0,axis_y:1,button:0"};
+ touch_params[index++] = Common::ParamPackage{"engine:cemuhookudp,axis_x:2,axis_y:3,button:1"};
+
const auto button_index =
static_cast<u64>(Settings::values.touch_from_button_map_index.GetValue());
const auto& touch_buttons = Settings::values.touch_from_button_maps[button_index].buttons;
+
for (const auto& config_entry : touch_buttons) {
Common::ParamPackage params{config_entry};
Common::ParamPackage touch_button_params;
@@ -53,15 +47,32 @@ void EmulatedConsole::ReloadInput() {
touch_button_params.Set("x", x);
touch_button_params.Set("y", y);
touch_button_params.Set("touch_id", static_cast<int>(index));
- touch_devices[index] =
- Input::CreateDeviceFromString<Input::InputDevice>(touch_button_params.Serialize());
- if (!touch_devices[index]) {
- continue;
+ touch_params[index] = touch_button_params;
+ index++;
+ if (index >= touch_params.size()) {
+ return;
}
+ }
+}
- Input::InputCallback trigger_callback{
+void EmulatedConsole::ReloadInput() {
+ SetTouchParams();
+ motion_devices = Input::CreateDevice<Input::InputDevice>(motion_params);
+ if (motion_devices) {
+ Input::InputCallback motion_callback{
+ [this](Input::CallbackStatus callback) { SetMotion(callback); }};
+ motion_devices->SetCallback(motion_callback);
+ }
+
+ std::size_t index = 0;
+ for (auto& touch_device : touch_devices) {
+ touch_device = Input::CreateDevice<Input::InputDevice>(touch_params[index]);
+ if (!touch_device) {
+ continue;
+ }
+ Input::InputCallback touch_callback{
[this, index](Input::CallbackStatus callback) { SetTouch(callback, index); }};
- touch_devices[index]->SetCallback(trigger_callback);
+ touch_device->SetCallback(touch_callback);
index++;
}
}
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
index 7d6cf9506..c48d25794 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/core/hid/emulated_console.h
@@ -144,6 +144,9 @@ public:
void DeleteCallback(int key);
private:
+ /// Creates and stores the touch params
+ void SetTouchParams();
+
/**
* Updates the motion status of the console
* @param A CallbackStatus containing gyro and accelerometer data
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 662260327..1ff3022c5 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -705,7 +705,6 @@ void EmulatedController::Connect() {
}
is_connected = true;
}
- LOG_ERROR(Service_HID, "Connected controller {}", NpadIdTypeToIndex(npad_id_type));
TriggerOnChange(ControllerTriggerType::Connected, true);
}
@@ -714,8 +713,6 @@ void EmulatedController::Disconnect() {
std::lock_guard lock{mutex};
if (is_configuring) {
temporary_is_connected = false;
- LOG_ERROR(Service_HID, "Disconnected temporal controller {}",
- NpadIdTypeToIndex(npad_id_type));
TriggerOnChange(ControllerTriggerType::Disconnected, false);
return;
}
@@ -725,7 +722,6 @@ void EmulatedController::Disconnect() {
}
is_connected = false;
}
- LOG_ERROR(Service_HID, "Disconnected controller {}", NpadIdTypeToIndex(npad_id_type));
TriggerOnChange(ControllerTriggerType::Disconnected, true);
}