diff options
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 91 |
1 files changed, 41 insertions, 50 deletions
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 17f71beaf..1e9ff8132 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -529,6 +529,14 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 529 | auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; | 529 | auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; |
| 530 | auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; | 530 | auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; |
| 531 | 531 | ||
| 532 | // Clear previous state | ||
| 533 | sixaxis_fullkey_state = {}; | ||
| 534 | sixaxis_handheld_state = {}; | ||
| 535 | sixaxis_dual_left_state = {}; | ||
| 536 | sixaxis_dual_right_state = {}; | ||
| 537 | sixaxis_left_lifo_state = {}; | ||
| 538 | sixaxis_right_lifo_state = {}; | ||
| 539 | |||
| 532 | if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) { | 540 | if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) { |
| 533 | controller.sixaxis_at_rest = true; | 541 | controller.sixaxis_at_rest = true; |
| 534 | for (std::size_t e = 0; e < motion_state.size(); ++e) { | 542 | for (std::size_t e = 0; e < motion_state.size(); ++e) { |
| @@ -537,69 +545,52 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing | |||
| 537 | } | 545 | } |
| 538 | } | 546 | } |
| 539 | 547 | ||
| 548 | const auto set_motion_state = [&](SixAxisSensorState& state, | ||
| 549 | const Core::HID::ControllerMotion& hid_state) { | ||
| 550 | static constexpr SixAxisSensorState default_motion_state = { | ||
| 551 | .accel = {0, 0, -1.0f}, | ||
| 552 | .orientation = | ||
| 553 | { | ||
| 554 | Common::Vec3f{1.0f, 0, 0}, | ||
| 555 | Common::Vec3f{0, 1.0f, 0}, | ||
| 556 | Common::Vec3f{0, 0, 1.0f}, | ||
| 557 | }, | ||
| 558 | .attribute = {1}, | ||
| 559 | }; | ||
| 560 | if (!controller.sixaxis_sensor_enabled) { | ||
| 561 | state = default_motion_state; | ||
| 562 | return; | ||
| 563 | } | ||
| 564 | if (!Settings::values.motion_enabled.GetValue()) { | ||
| 565 | state = default_motion_state; | ||
| 566 | return; | ||
| 567 | } | ||
| 568 | state.attribute.is_connected.Assign(1); | ||
| 569 | state.accel = hid_state.accel; | ||
| 570 | state.gyro = hid_state.gyro; | ||
| 571 | state.rotation = hid_state.rotation; | ||
| 572 | state.orientation = hid_state.orientation; | ||
| 573 | }; | ||
| 574 | |||
| 540 | switch (controller_type) { | 575 | switch (controller_type) { |
| 541 | case Core::HID::NpadStyleIndex::None: | 576 | case Core::HID::NpadStyleIndex::None: |
| 542 | UNREACHABLE(); | 577 | UNREACHABLE(); |
| 543 | break; | 578 | break; |
| 544 | case Core::HID::NpadStyleIndex::ProController: | 579 | case Core::HID::NpadStyleIndex::ProController: |
| 545 | sixaxis_fullkey_state.attribute.raw = 0; | 580 | 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; | 581 | break; |
| 554 | case Core::HID::NpadStyleIndex::Handheld: | 582 | case Core::HID::NpadStyleIndex::Handheld: |
| 555 | sixaxis_handheld_state.attribute.raw = 0; | 583 | 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; | 584 | break; |
| 564 | case Core::HID::NpadStyleIndex::JoyconDual: | 585 | case Core::HID::NpadStyleIndex::JoyconDual: |
| 565 | sixaxis_dual_left_state.attribute.raw = 0; | 586 | set_motion_state(sixaxis_dual_left_state, motion_state[0]); |
| 566 | sixaxis_dual_right_state.attribute.raw = 0; | 587 | 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; | 588 | break; |
| 584 | case Core::HID::NpadStyleIndex::JoyconLeft: | 589 | case Core::HID::NpadStyleIndex::JoyconLeft: |
| 585 | sixaxis_left_lifo_state.attribute.raw = 0; | 590 | 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; | 591 | break; |
| 594 | case Core::HID::NpadStyleIndex::JoyconRight: | 592 | case Core::HID::NpadStyleIndex::JoyconRight: |
| 595 | sixaxis_right_lifo_state.attribute.raw = 0; | 593 | 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; | 594 | break; |
| 604 | default: | 595 | default: |
| 605 | break; | 596 | break; |