diff options
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 1 | ||||
| -rw-r--r-- | src/core/hid/motion_input.cpp | 4 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 13 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 12 |
4 files changed, 24 insertions, 6 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index d12037b11..a7cdf45e6 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -749,6 +749,7 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback | |||
| 749 | raw_status.gyro.y.value, | 749 | raw_status.gyro.y.value, |
| 750 | raw_status.gyro.z.value, | 750 | raw_status.gyro.z.value, |
| 751 | }); | 751 | }); |
| 752 | emulated.SetGyroThreshold(raw_status.gyro.x.properties.threshold); | ||
| 752 | emulated.UpdateRotation(raw_status.delta_timestamp); | 753 | emulated.UpdateRotation(raw_status.delta_timestamp); |
| 753 | emulated.UpdateOrientation(raw_status.delta_timestamp); | 754 | emulated.UpdateOrientation(raw_status.delta_timestamp); |
| 754 | force_update_motion = raw_status.force_update; | 755 | force_update_motion = raw_status.force_update; |
diff --git a/src/core/hid/motion_input.cpp b/src/core/hid/motion_input.cpp index 6e126be19..05042fd99 100644 --- a/src/core/hid/motion_input.cpp +++ b/src/core/hid/motion_input.cpp | |||
| @@ -10,7 +10,7 @@ namespace Core::HID { | |||
| 10 | MotionInput::MotionInput() { | 10 | MotionInput::MotionInput() { |
| 11 | // Initialize PID constants with default values | 11 | // Initialize PID constants with default values |
| 12 | SetPID(0.3f, 0.005f, 0.0f); | 12 | SetPID(0.3f, 0.005f, 0.0f); |
| 13 | SetGyroThreshold(0.00005f); | 13 | SetGyroThreshold(0.007f); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { | 16 | void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) { |
| @@ -31,7 +31,7 @@ void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) { | |||
| 31 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); | 31 | gyro_bias = (gyro_bias * 0.9999f) + (gyroscope * 0.0001f); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | if (gyro.Length2() < gyro_threshold) { | 34 | if (gyro.Length() < gyro_threshold) { |
| 35 | gyro = {}; | 35 | gyro = {}; |
| 36 | } else { | 36 | } else { |
| 37 | only_accelerometer = false; | 37 | only_accelerometer = false; |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 7b370335f..2f3c0735a 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -504,9 +504,10 @@ private: | |||
| 504 | 504 | ||
| 505 | class InputFromMotion final : public Common::Input::InputDevice { | 505 | class InputFromMotion final : public Common::Input::InputDevice { |
| 506 | public: | 506 | public: |
| 507 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, | 507 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, |
| 508 | InputEngine* input_engine_) | 508 | InputEngine* input_engine_) |
| 509 | : identifier(identifier_), motion_sensor(motion_sensor_), input_engine(input_engine_) { | 509 | : identifier(identifier_), motion_sensor(motion_sensor_), gyro_threshold(gyro_threshold_), |
| 510 | input_engine(input_engine_) { | ||
| 510 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | 511 | UpdateCallback engine_callback{[this]() { OnChange(); }}; |
| 511 | const InputIdentifier input_identifier{ | 512 | const InputIdentifier input_identifier{ |
| 512 | .identifier = identifier, | 513 | .identifier = identifier, |
| @@ -525,8 +526,9 @@ public: | |||
| 525 | const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); | 526 | const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); |
| 526 | Common::Input::MotionStatus status{}; | 527 | Common::Input::MotionStatus status{}; |
| 527 | const Common::Input::AnalogProperties properties = { | 528 | const Common::Input::AnalogProperties properties = { |
| 528 | .deadzone = 0.001f, | 529 | .deadzone = 0.0f, |
| 529 | .range = 1.0f, | 530 | .range = 1.0f, |
| 531 | .threshold = gyro_threshold, | ||
| 530 | .offset = 0.0f, | 532 | .offset = 0.0f, |
| 531 | }; | 533 | }; |
| 532 | status.accel.x = {.raw_value = basic_motion.accel_x, .properties = properties}; | 534 | status.accel.x = {.raw_value = basic_motion.accel_x, .properties = properties}; |
| @@ -551,6 +553,7 @@ public: | |||
| 551 | private: | 553 | private: |
| 552 | const PadIdentifier identifier; | 554 | const PadIdentifier identifier; |
| 553 | const int motion_sensor; | 555 | const int motion_sensor; |
| 556 | const float gyro_threshold; | ||
| 554 | int callback_key; | 557 | int callback_key; |
| 555 | InputEngine* input_engine; | 558 | InputEngine* input_engine; |
| 556 | }; | 559 | }; |
| @@ -873,9 +876,11 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | |||
| 873 | 876 | ||
| 874 | if (params.Has("motion")) { | 877 | if (params.Has("motion")) { |
| 875 | const auto motion_sensor = params.Get("motion", 0); | 878 | const auto motion_sensor = params.Get("motion", 0); |
| 879 | const auto gyro_threshold = params.Get("threshold", 0.007f); | ||
| 876 | input_engine->PreSetController(identifier); | 880 | input_engine->PreSetController(identifier); |
| 877 | input_engine->PreSetMotion(identifier, motion_sensor); | 881 | input_engine->PreSetMotion(identifier, motion_sensor); |
| 878 | return std::make_unique<InputFromMotion>(identifier, motion_sensor, input_engine.get()); | 882 | return std::make_unique<InputFromMotion>(identifier, motion_sensor, gyro_threshold, |
| 883 | input_engine.get()); | ||
| 879 | } | 884 | } |
| 880 | 885 | ||
| 881 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); | 886 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index d2132b408..365e97411 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -403,10 +403,22 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 403 | connect(button, &QPushButton::customContextMenuRequested, | 403 | connect(button, &QPushButton::customContextMenuRequested, |
| 404 | [=, this](const QPoint& menu_location) { | 404 | [=, this](const QPoint& menu_location) { |
| 405 | QMenu context_menu; | 405 | QMenu context_menu; |
| 406 | Common::ParamPackage param = emulated_controller->GetMotionParam(motion_id); | ||
| 406 | context_menu.addAction(tr("Clear"), [&] { | 407 | context_menu.addAction(tr("Clear"), [&] { |
| 407 | emulated_controller->SetMotionParam(motion_id, {}); | 408 | emulated_controller->SetMotionParam(motion_id, {}); |
| 408 | motion_map[motion_id]->setText(tr("[not set]")); | 409 | motion_map[motion_id]->setText(tr("[not set]")); |
| 409 | }); | 410 | }); |
| 411 | if (param.Has("motion")) { | ||
| 412 | context_menu.addAction(tr("Set gyro threshold"), [&] { | ||
| 413 | const int gyro_threshold = | ||
| 414 | static_cast<int>(param.Get("threshold", 0.007f) * 1000.0f); | ||
| 415 | const int new_threshold = QInputDialog::getInt( | ||
| 416 | this, tr("Set threshold"), tr("Choose a value between 0% and 100%"), | ||
| 417 | gyro_threshold, 0, 100); | ||
| 418 | param.Set("threshold", new_threshold / 1000.0f); | ||
| 419 | emulated_controller->SetMotionParam(motion_id, param); | ||
| 420 | }); | ||
| 421 | } | ||
| 410 | context_menu.exec(motion_map[motion_id]->mapToGlobal(menu_location)); | 422 | context_menu.exec(motion_map[motion_id]->mapToGlobal(menu_location)); |
| 411 | }); | 423 | }); |
| 412 | } | 424 | } |