From 84c58666a4dbb6d46e132514e4d91437fb689fa0 Mon Sep 17 00:00:00 2001 From: german77 Date: Wed, 3 Nov 2021 22:35:45 -0600 Subject: config: Cleanup and documentation --- src/common/input.h | 34 ++++++++++- src/common/settings.h | 3 - src/core/hid/emulated_console.cpp | 6 +- src/yuzu/configuration/config.cpp | 4 -- src/yuzu/configuration/configure_motion_touch.cpp | 8 +-- src/yuzu/configuration/configure_motion_touch.ui | 70 +++-------------------- src/yuzu_cmd/config.cpp | 3 - src/yuzu_cmd/default_ini.h | 17 +----- 8 files changed, 46 insertions(+), 99 deletions(-) diff --git a/src/common/input.h b/src/common/input.h index f21872b0a..d997853c6 100644 --- a/src/common/input.h +++ b/src/common/input.h @@ -15,6 +15,7 @@ namespace Common::Input { +// Type of data that is expected to recieve or send enum class InputType { None, Battery, @@ -30,6 +31,7 @@ enum class InputType { Ir, }; +// Internal battery charge level enum class BatteryLevel : u32 { None, Empty, @@ -41,13 +43,17 @@ enum class BatteryLevel : u32 { }; enum class PollingMode { + // Constant polling of buttons, analogs and motion data Active, + // Only update on button change, digital analogs Pasive, - Camera, - NCF, + // Enable near field communication polling + NFC, + // Enable infrared camera polling IR, }; +// Vibration reply from the controller enum class VibrationError { None, NotSupported, @@ -55,6 +61,7 @@ enum class VibrationError { Unknown, }; +// Polling mode reply from the controller enum class PollingError { None, NotSupported, @@ -67,20 +74,28 @@ enum class VibrationAmplificationType { Exponential, }; +// Analog properties for calibration struct AnalogProperties { + // Anything below this value will be detected as zero float deadzone{}; + // Anyting above this values will be detected as one float range{1.0f}; + // Minimum value to be detected as active float threshold{0.5f}; + // Drift correction applied to the raw data float offset{}; + // Invert direction of the sensor data bool inverted{}; }; +// Single analog sensor data struct AnalogStatus { float value{}; float raw_value{}; AnalogProperties properties{}; }; +// Button data struct ButtonStatus { Common::UUID uuid{}; bool value{}; @@ -89,8 +104,10 @@ struct ButtonStatus { bool locked{}; }; +// Internal battery data using BatteryStatus = BatteryLevel; +// Analog and digital joystick data struct StickStatus { Common::UUID uuid{}; AnalogStatus x{}; @@ -101,18 +118,21 @@ struct StickStatus { bool down{}; }; +// Analog and digital trigger data struct TriggerStatus { Common::UUID uuid{}; AnalogStatus analog{}; ButtonStatus pressed{}; }; +// 3D vector representing motion input struct MotionSensor { AnalogStatus x{}; AnalogStatus y{}; AnalogStatus z{}; }; +// Motion data used to calculate controller orientation struct MotionStatus { // Gyroscope vector measurement in radians/s. MotionSensor gyro{}; @@ -124,6 +144,7 @@ struct MotionStatus { bool force_update{}; }; +// Data of a single point on a touch screen struct TouchStatus { ButtonStatus pressed{}; AnalogStatus x{}; @@ -131,11 +152,13 @@ struct TouchStatus { int id{}; }; +// Physical controller color in RGB format struct BodyColorStatus { u32 body{}; u32 buttons{}; }; +// HD rumble data struct VibrationStatus { f32 low_amplitude{}; f32 low_frequency{}; @@ -144,6 +167,7 @@ struct VibrationStatus { VibrationAmplificationType type; }; +// Physical controller LED pattern struct LedStatus { bool led_1{}; bool led_2{}; @@ -151,6 +175,7 @@ struct LedStatus { bool led_4{}; }; +// Callback data consisting of an input type and the equivalent data status struct CallbackStatus { InputType type{InputType::None}; ButtonStatus button_status{}; @@ -164,6 +189,7 @@ struct CallbackStatus { VibrationStatus vibration_status{}; }; +// Triggered once every input change struct InputCallback { std::function on_change; }; @@ -178,15 +204,17 @@ public: return; } - // Force input device to update data regarless of the current state + // Force input device to update data regardless of the current state virtual void ForceUpdate() { return; } + // Sets the function to be triggered when input changes void SetCallback(InputCallback callback_) { callback = std::move(callback_); } + // Triggers the function set in the callback void TriggerOnChange(CallbackStatus status) { if (callback.on_change) { callback.on_change(status); diff --git a/src/common/settings.h b/src/common/settings.h index 95225fba7..b52d0d1d0 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -559,8 +559,6 @@ struct Values { Setting enable_accurate_vibrations{false, "enable_accurate_vibrations"}; Setting motion_enabled{true, "motion_enabled"}; - BasicSetting motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01", - "motion_device"}; BasicSetting udp_input_servers{"127.0.0.1:26760", "udp_input_servers"}; BasicSetting pause_tas_on_load{true, "pause_tas_on_load"}; @@ -583,7 +581,6 @@ struct Values { TouchscreenInput touchscreen; - BasicSetting use_touch_from_button{false, "use_touch_from_button"}; BasicSetting touch_device{"min_x:100,min_y:50,max_x:1800,max_y:850", "touch_device"}; BasicSetting touch_from_button_map_index{0, "touch_from_button_map"}; diff --git a/src/core/hid/emulated_console.cpp b/src/core/hid/emulated_console.cpp index dfbaa3f8c..b51c72eae 100644 --- a/src/core/hid/emulated_console.cpp +++ b/src/core/hid/emulated_console.cpp @@ -11,7 +11,7 @@ EmulatedConsole::EmulatedConsole() = default; EmulatedConsole::~EmulatedConsole() = default; void EmulatedConsole::ReloadFromSettings() { - // Using first motion device from player 1. No need to assign a special config at the moment + // Using first motion device from player 1. No need to assign any unique config at the moment const auto& player = Settings::values.players.GetValue()[0]; motion_params = Common::ParamPackage(player.motions[0]); @@ -33,6 +33,7 @@ void EmulatedConsole::SetTouchParams() { static_cast(Settings::values.touch_from_button_map_index.GetValue()); const auto& touch_buttons = Settings::values.touch_from_button_maps[button_index].buttons; + // Map the rest of the fingers from touch from button configuration for (const auto& config_entry : touch_buttons) { Common::ParamPackage params{config_entry}; Common::ParamPackage touch_button_params; @@ -54,7 +55,9 @@ void EmulatedConsole::SetTouchParams() { } void EmulatedConsole::ReloadInput() { + // If you load any device here add the equivalent to the UnloadInput() function SetTouchParams(); + motion_devices = Common::Input::CreateDevice(motion_params); if (motion_devices) { Common::Input::InputCallback motion_callback{ @@ -62,6 +65,7 @@ void EmulatedConsole::ReloadInput() { motion_devices->SetCallback(motion_callback); } + // Unique index for identifying touch device source std::size_t index = 0; for (auto& touch_device : touch_devices) { touch_device = Common::Input::CreateDevice(touch_params[index]); diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 7a748d9c8..7669fe474 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -623,9 +623,7 @@ void Config::ReadMotionTouchValues() { } qt_config->endArray(); - ReadBasicSetting(Settings::values.motion_device); ReadBasicSetting(Settings::values.touch_device); - ReadBasicSetting(Settings::values.use_touch_from_button); ReadBasicSetting(Settings::values.touch_from_button_map_index); Settings::values.touch_from_button_map_index = std::clamp( Settings::values.touch_from_button_map_index.GetValue(), 0, num_touch_from_button_maps - 1); @@ -1131,9 +1129,7 @@ void Config::SaveTouchscreenValues() { } void Config::SaveMotionTouchValues() { - WriteBasicSetting(Settings::values.motion_device); WriteBasicSetting(Settings::values.touch_device); - WriteBasicSetting(Settings::values.use_touch_from_button); WriteBasicSetting(Settings::values.touch_from_button_map_index); WriteBasicSetting(Settings::values.udp_input_servers); diff --git a/src/yuzu/configuration/configure_motion_touch.cpp b/src/yuzu/configuration/configure_motion_touch.cpp index 9fd1a919f..8539a5c8b 100644 --- a/src/yuzu/configuration/configure_motion_touch.cpp +++ b/src/yuzu/configuration/configure_motion_touch.cpp @@ -93,6 +93,7 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent, "using-a-controller-or-android-phone-for-motion-or-touch-input'>Learn More")); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); SetConfiguration(); UpdateUiDisplay(); ConnectEvents(); @@ -101,17 +102,14 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent, ConfigureMotionTouch::~ConfigureMotionTouch() = default; void ConfigureMotionTouch::SetConfiguration() { - const Common::ParamPackage motion_param(Settings::values.motion_device.GetValue()); const Common::ParamPackage touch_param(Settings::values.touch_device.GetValue()); - ui->touch_from_button_checkbox->setChecked(Settings::values.use_touch_from_button.GetValue()); touch_from_button_maps = Settings::values.touch_from_button_maps; for (const auto& touch_map : touch_from_button_maps) { ui->touch_from_button_map->addItem(QString::fromStdString(touch_map.name)); } ui->touch_from_button_map->setCurrentIndex( Settings::values.touch_from_button_map_index.GetValue()); - ui->motion_sensitivity->setValue(motion_param.Get("sensitivity", 0.01f)); min_x = touch_param.Get("min_x", 100); min_y = touch_param.Get("min_y", 50); @@ -139,9 +137,6 @@ void ConfigureMotionTouch::SetConfiguration() { void ConfigureMotionTouch::UpdateUiDisplay() { const QString cemuhook_udp = QStringLiteral("cemuhookudp"); - ui->motion_sensitivity_label->setVisible(true); - ui->motion_sensitivity->setVisible(true); - ui->touch_calibration->setVisible(true); ui->touch_calibration_config->setVisible(true); ui->touch_calibration_label->setVisible(true); @@ -312,7 +307,6 @@ void ConfigureMotionTouch::ApplyConfiguration() { touch_param.Set("max_y", max_y); Settings::values.touch_device = touch_param.Serialize(); - Settings::values.use_touch_from_button = ui->touch_from_button_checkbox->isChecked(); Settings::values.touch_from_button_map_index = ui->touch_from_button_map->currentIndex(); Settings::values.touch_from_button_maps = touch_from_button_maps; Settings::values.udp_input_servers = GetUDPServerString(); diff --git a/src/yuzu/configuration/configure_motion_touch.ui b/src/yuzu/configuration/configure_motion_touch.ui index 1e35ea946..c75a84ae4 100644 --- a/src/yuzu/configuration/configure_motion_touch.ui +++ b/src/yuzu/configuration/configure_motion_touch.ui @@ -2,14 +2,6 @@ ConfigureMotionTouch - - - 0 - 0 - 500 - 482 - - Configure Motion / Touch @@ -17,48 +9,6 @@ - - - - Mouse Motion - - - - - - - - Sensitivity: - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 4 - - - 0.010000000000000 - - - 10.000000000000000 - - - 0.001000000000000 - - - 0.010000000000000 - - - - - - - - @@ -101,19 +51,13 @@ - - - - - 0 - 0 - - - - Use button mapping: - - - + + + + Touch from button profile: + + + diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 103a12b12..7ca09a635 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -292,8 +292,6 @@ void Config::ReadValues() { Settings::values.mouse_buttons[i] = default_param; } - ReadSetting("ControlsGeneral", Settings::values.motion_device); - ReadSetting("ControlsGeneral", Settings::values.touch_device); ReadSetting("ControlsGeneral", Settings::values.keyboard_enabled); @@ -362,7 +360,6 @@ void Config::ReadValues() { Settings::TouchFromButtonMap{"default", {}}); num_touch_from_button_maps = 1; } - ReadSetting("ControlsGeneral", Settings::values.use_touch_from_button); Settings::values.touch_from_button_map_index = std::clamp( Settings::values.touch_from_button_map_index.GetValue(), 0, num_touch_from_button_maps - 1); diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index ecdc271a8..6d613bf7a 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -84,23 +84,10 @@ enable_accurate_vibrations= # 0: Disabled, 1 (default): Enabled motion_enabled = -# for motion input, the following devices are available: -# - "motion_emu" (default) for emulating motion input from mouse input. Required parameters: -# - "update_period": update period in milliseconds (default to 100) -# - "sensitivity": the coefficient converting mouse movement to tilting angle (default to 0.01) -# - "cemuhookudp" reads motion input from a udp server that uses cemuhook's udp protocol -motion_device= - -# for touch input, the following devices are available: -# - "emu_window" (default) for emulating touch input from mouse input to the emulation window. No parameters required -# - "cemuhookudp" reads touch input from a udp server that uses cemuhook's udp protocol -# - "min_x", "min_y", "max_x", "max_y": defines the udp device's touch screen coordinate system +# Defines the udp device's touch screen coordinate system for cemuhookudp devices +# - "min_x", "min_y", "max_x", "max_y" touch_device= -# Whether to enable or disable touch input from button -# 0 (default): Disabled, 1: Enabled -use_touch_from_button= - # for mapping buttons to touch inputs. #touch_from_button_map=1 #touch_from_button_maps_0_name=default -- cgit v1.2.3