summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Morph2022-05-11 17:51:54 -0400
committerGravatar GitHub2022-05-11 17:51:54 -0400
commit0b9ef3c0b844fbda14390c94bb6ddd37e3b36c90 (patch)
tree6a70f027699748b511f3224bac1e4903aa5366b0 /src
parentMerge pull request #8314 from liamwhite/gl-flip-2 (diff)
parentservice: hid: Fix motion refresh rate (diff)
downloadyuzu-0b9ef3c0b844fbda14390c94bb6ddd37e3b36c90.tar.gz
yuzu-0b9ef3c0b844fbda14390c94bb6ddd37e3b36c90.tar.xz
yuzu-0b9ef3c0b844fbda14390c94bb6ddd37e3b36c90.zip
Merge pull request #8308 from german77/disablesix
service: hid: Disable correctly motion input
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp96
-rw-r--r--src/core/hle/service/hid/hid.cpp3
2 files changed, 47 insertions, 52 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 17f71beaf..de06e1735 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -3,7 +3,9 @@
3 3
4#include <algorithm> 4#include <algorithm>
5#include <array> 5#include <array>
6#include <chrono>
6#include <cstring> 7#include <cstring>
8
7#include "common/assert.h" 9#include "common/assert.h"
8#include "common/bit_field.h" 10#include "common/bit_field.h"
9#include "common/common_types.h" 11#include "common/common_types.h"
@@ -529,6 +531,14 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
529 auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; 531 auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state;
530 auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; 532 auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state;
531 533
534 // Clear previous state
535 sixaxis_fullkey_state = {};
536 sixaxis_handheld_state = {};
537 sixaxis_dual_left_state = {};
538 sixaxis_dual_right_state = {};
539 sixaxis_left_lifo_state = {};
540 sixaxis_right_lifo_state = {};
541
532 if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) { 542 if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) {
533 controller.sixaxis_at_rest = true; 543 controller.sixaxis_at_rest = true;
534 for (std::size_t e = 0; e < motion_state.size(); ++e) { 544 for (std::size_t e = 0; e < motion_state.size(); ++e) {
@@ -537,69 +547,55 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
537 } 547 }
538 } 548 }
539 549
550 const auto set_motion_state = [&](SixAxisSensorState& state,
551 const Core::HID::ControllerMotion& hid_state) {
552 using namespace std::literals::chrono_literals;
553 static constexpr SixAxisSensorState default_motion_state = {
554 .delta_time = std::chrono::nanoseconds(5ms).count(),
555 .accel = {0, 0, -1.0f},
556 .orientation =
557 {
558 Common::Vec3f{1.0f, 0, 0},
559 Common::Vec3f{0, 1.0f, 0},
560 Common::Vec3f{0, 0, 1.0f},
561 },
562 .attribute = {1},
563 };
564 if (!controller.sixaxis_sensor_enabled) {
565 state = default_motion_state;
566 return;
567 }
568 if (!Settings::values.motion_enabled.GetValue()) {
569 state = default_motion_state;
570 return;
571 }
572 state.attribute.is_connected.Assign(1);
573 state.delta_time = std::chrono::nanoseconds(5ms).count();
574 state.accel = hid_state.accel;
575 state.gyro = hid_state.gyro;
576 state.rotation = hid_state.rotation;
577 state.orientation = hid_state.orientation;
578 };
579
540 switch (controller_type) { 580 switch (controller_type) {
541 case Core::HID::NpadStyleIndex::None: 581 case Core::HID::NpadStyleIndex::None:
542 UNREACHABLE(); 582 UNREACHABLE();
543 break; 583 break;
544 case Core::HID::NpadStyleIndex::ProController: 584 case Core::HID::NpadStyleIndex::ProController:
545 sixaxis_fullkey_state.attribute.raw = 0; 585 set_motion_state(sixaxis_fullkey_state, motion_state[0]);
546 if (controller.sixaxis_sensor_enabled) {
547 sixaxis_fullkey_state.attribute.is_connected.Assign(1);
548 sixaxis_fullkey_state.accel = motion_state[0].accel;
549 sixaxis_fullkey_state.gyro = motion_state[0].gyro;
550 sixaxis_fullkey_state.rotation = motion_state[0].rotation;
551 sixaxis_fullkey_state.orientation = motion_state[0].orientation;
552 }
553 break; 586 break;
554 case Core::HID::NpadStyleIndex::Handheld: 587 case Core::HID::NpadStyleIndex::Handheld:
555 sixaxis_handheld_state.attribute.raw = 0; 588 set_motion_state(sixaxis_handheld_state, motion_state[0]);
556 if (controller.sixaxis_sensor_enabled) {
557 sixaxis_handheld_state.attribute.is_connected.Assign(1);
558 sixaxis_handheld_state.accel = motion_state[0].accel;
559 sixaxis_handheld_state.gyro = motion_state[0].gyro;
560 sixaxis_handheld_state.rotation = motion_state[0].rotation;
561 sixaxis_handheld_state.orientation = motion_state[0].orientation;
562 }
563 break; 589 break;
564 case Core::HID::NpadStyleIndex::JoyconDual: 590 case Core::HID::NpadStyleIndex::JoyconDual:
565 sixaxis_dual_left_state.attribute.raw = 0; 591 set_motion_state(sixaxis_dual_left_state, motion_state[0]);
566 sixaxis_dual_right_state.attribute.raw = 0; 592 set_motion_state(sixaxis_dual_right_state, motion_state[1]);
567 if (controller.sixaxis_sensor_enabled) {
568 // Set motion for the left joycon
569 sixaxis_dual_left_state.attribute.is_connected.Assign(1);
570 sixaxis_dual_left_state.accel = motion_state[0].accel;
571 sixaxis_dual_left_state.gyro = motion_state[0].gyro;
572 sixaxis_dual_left_state.rotation = motion_state[0].rotation;
573 sixaxis_dual_left_state.orientation = motion_state[0].orientation;
574 }
575 if (controller.sixaxis_sensor_enabled) {
576 // Set motion for the right joycon
577 sixaxis_dual_right_state.attribute.is_connected.Assign(1);
578 sixaxis_dual_right_state.accel = motion_state[1].accel;
579 sixaxis_dual_right_state.gyro = motion_state[1].gyro;
580 sixaxis_dual_right_state.rotation = motion_state[1].rotation;
581 sixaxis_dual_right_state.orientation = motion_state[1].orientation;
582 }
583 break; 593 break;
584 case Core::HID::NpadStyleIndex::JoyconLeft: 594 case Core::HID::NpadStyleIndex::JoyconLeft:
585 sixaxis_left_lifo_state.attribute.raw = 0; 595 set_motion_state(sixaxis_left_lifo_state, motion_state[0]);
586 if (controller.sixaxis_sensor_enabled) {
587 sixaxis_left_lifo_state.attribute.is_connected.Assign(1);
588 sixaxis_left_lifo_state.accel = motion_state[0].accel;
589 sixaxis_left_lifo_state.gyro = motion_state[0].gyro;
590 sixaxis_left_lifo_state.rotation = motion_state[0].rotation;
591 sixaxis_left_lifo_state.orientation = motion_state[0].orientation;
592 }
593 break; 596 break;
594 case Core::HID::NpadStyleIndex::JoyconRight: 597 case Core::HID::NpadStyleIndex::JoyconRight:
595 sixaxis_right_lifo_state.attribute.raw = 0; 598 set_motion_state(sixaxis_right_lifo_state, motion_state[1]);
596 if (controller.sixaxis_sensor_enabled) {
597 sixaxis_right_lifo_state.attribute.is_connected.Assign(1);
598 sixaxis_right_lifo_state.accel = motion_state[1].accel;
599 sixaxis_right_lifo_state.gyro = motion_state[1].gyro;
600 sixaxis_right_lifo_state.rotation = motion_state[1].rotation;
601 sixaxis_right_lifo_state.orientation = motion_state[1].orientation;
602 }
603 break; 599 break;
604 default: 600 default:
605 break; 601 break;
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index eba44eda8..44f892da9 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -37,8 +37,7 @@ namespace Service::HID {
37// Period time is obtained by measuring the number of samples in a second on HW using a homebrew 37// Period time is obtained by measuring the number of samples in a second on HW using a homebrew
38constexpr auto pad_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; // (4ms, 250Hz) 38constexpr auto pad_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; // (4ms, 250Hz)
39constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz) 39constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz)
40// TODO: Correct update rate for motion is 5ms. Check why some games don't behave at that speed 40constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
41constexpr auto motion_update_ns = std::chrono::nanoseconds{10 * 1000 * 1000}; // (10ms, 100Hz)
42 41
43IAppletResource::IAppletResource(Core::System& system_, 42IAppletResource::IAppletResource(Core::System& system_,
44 KernelHelpers::ServiceContext& service_context_) 43 KernelHelpers::ServiceContext& service_context_)