diff options
| author | 2020-09-04 21:48:03 -0500 | |
|---|---|---|
| committer | 2020-09-04 21:48:03 -0500 | |
| commit | ff679f3d171ace12d1b3b68f305b1bb24b2130de (patch) | |
| tree | 67cd6da1b1ef1e7b817ffd82cc8606ace6da779e /src/core | |
| parent | Merge pull request #4629 from Morph1984/mergesinglejoyasdualjoy-impl (diff) | |
| download | yuzu-ff679f3d171ace12d1b3b68f305b1bb24b2130de.tar.gz yuzu-ff679f3d171ace12d1b3b68f305b1bb24b2130de.tar.xz yuzu-ff679f3d171ace12d1b3b68f305b1bb24b2130de.zip | |
Include HID and configuration changes related to motion
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/frontend/input.h | 27 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.cpp | 117 | ||||
| -rw-r--r-- | src/core/hle/service/hid/controllers/npad.h | 54 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 37 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h | 2 |
5 files changed, 222 insertions, 15 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h index 2b098b7c6..6770475cf 100644 --- a/src/core/frontend/input.h +++ b/src/core/frontend/input.h | |||
| @@ -137,6 +137,33 @@ using AnalogDevice = InputDevice<std::tuple<float, float>>; | |||
| 137 | using MotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<float>>>; | 137 | using MotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<float>>>; |
| 138 | 138 | ||
| 139 | /** | 139 | /** |
| 140 | * A real motion device is an input device that returns a tuple of accelerometer state vector, | ||
| 141 | * gyroscope state vector, rotation state vector and orientation state matrix. | ||
| 142 | * | ||
| 143 | * For both vectors: | ||
| 144 | * x+ is the same direction as RIGHT on D-pad. | ||
| 145 | * y+ is normal to the touch screen, pointing outward. | ||
| 146 | * z+ is the same direction as UP on D-pad. | ||
| 147 | * | ||
| 148 | * For accelerometer state vector | ||
| 149 | * Units: g (gravitational acceleration) | ||
| 150 | * | ||
| 151 | * For gyroscope state vector: | ||
| 152 | * Orientation is determined by right-hand rule. | ||
| 153 | * Units: deg/sec | ||
| 154 | * | ||
| 155 | * For rotation state vector | ||
| 156 | * Units: rotations | ||
| 157 | * | ||
| 158 | * For orientation state matrix | ||
| 159 | * x vector | ||
| 160 | * y vector | ||
| 161 | * z vector | ||
| 162 | */ | ||
| 163 | using RealMotionDevice = InputDevice<std::tuple<Common::Vec3<float>, Common::Vec3<float>, | ||
| 164 | Common::Vec3<float>, std::array<Common::Vec3f, 3>>>; | ||
| 165 | |||
| 166 | /** | ||
| 140 | * A touch device is an input device that returns a tuple of two floats and a bool. The floats are | 167 | * A touch device is an input device that returns a tuple of two floats and a bool. The floats are |
| 141 | * x and y coordinates in the range 0.0 - 1.0, and the bool indicates whether it is pressed. | 168 | * x and y coordinates in the range 0.0 - 1.0, and the bool indicates whether it is pressed. |
| 142 | */ | 169 | */ |
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index e742497e1..acf748bf1 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp | |||
| @@ -249,6 +249,9 @@ void Controller_NPad::OnLoadInputDevices() { | |||
| 249 | std::transform(players[i].analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, | 249 | std::transform(players[i].analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, |
| 250 | players[i].analogs.begin() + Settings::NativeAnalog::STICK_HID_END, | 250 | players[i].analogs.begin() + Settings::NativeAnalog::STICK_HID_END, |
| 251 | sticks[i].begin(), Input::CreateDevice<Input::AnalogDevice>); | 251 | sticks[i].begin(), Input::CreateDevice<Input::AnalogDevice>); |
| 252 | std::transform(players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_BEGIN, | ||
| 253 | players[i].motions.begin() + Settings::NativeMotion::MOTION_HID_END, | ||
| 254 | motions[i].begin(), Input::CreateDevice<Input::RealMotionDevice>); | ||
| 252 | } | 255 | } |
| 253 | } | 256 | } |
| 254 | 257 | ||
| @@ -265,6 +268,7 @@ void Controller_NPad::RequestPadStateUpdate(u32 npad_id) { | |||
| 265 | auto& rstick_entry = npad_pad_states[controller_idx].r_stick; | 268 | auto& rstick_entry = npad_pad_states[controller_idx].r_stick; |
| 266 | const auto& button_state = buttons[controller_idx]; | 269 | const auto& button_state = buttons[controller_idx]; |
| 267 | const auto& analog_state = sticks[controller_idx]; | 270 | const auto& analog_state = sticks[controller_idx]; |
| 271 | const auto& motion_state = motions[controller_idx]; | ||
| 268 | const auto [stick_l_x_f, stick_l_y_f] = | 272 | const auto [stick_l_x_f, stick_l_y_f] = |
| 269 | analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); | 273 | analog_state[static_cast<std::size_t>(JoystickId::Joystick_Left)]->GetStatus(); |
| 270 | const auto [stick_r_x_f, stick_r_y_f] = | 274 | const auto [stick_r_x_f, stick_r_y_f] = |
| @@ -359,6 +363,45 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 359 | continue; | 363 | continue; |
| 360 | } | 364 | } |
| 361 | const u32 npad_index = static_cast<u32>(i); | 365 | const u32 npad_index = static_cast<u32>(i); |
| 366 | |||
| 367 | const std::array<SixAxisGeneric*, 6> controller_sixaxes{ | ||
| 368 | &npad.sixaxis_full, &npad.sixaxis_handheld, &npad.sixaxis_dual_left, | ||
| 369 | &npad.sixaxis_dual_right, &npad.sixaxis_left, &npad.sixaxis_right, | ||
| 370 | }; | ||
| 371 | |||
| 372 | for (auto* sixaxis_sensor : controller_sixaxes) { | ||
| 373 | sixaxis_sensor->common.entry_count = 16; | ||
| 374 | sixaxis_sensor->common.total_entry_count = 17; | ||
| 375 | |||
| 376 | const auto& last_entry = | ||
| 377 | sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; | ||
| 378 | |||
| 379 | sixaxis_sensor->common.timestamp = core_timing.GetCPUTicks(); | ||
| 380 | sixaxis_sensor->common.last_entry_index = | ||
| 381 | (sixaxis_sensor->common.last_entry_index + 1) % 17; | ||
| 382 | |||
| 383 | auto& cur_entry = sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; | ||
| 384 | |||
| 385 | cur_entry.timestamp = last_entry.timestamp + 1; | ||
| 386 | cur_entry.timestamp2 = cur_entry.timestamp; | ||
| 387 | } | ||
| 388 | |||
| 389 | // Try to read sixaxis sensor states | ||
| 390 | std::array<MotionDevice, 2> motion_devices; | ||
| 391 | |||
| 392 | if (sixaxis_sensors_enabled) { | ||
| 393 | sixaxis_at_rest = true; | ||
| 394 | for (std::size_t e = 0; e < motion_devices.size(); ++e) { | ||
| 395 | const auto& device = motions[i][e]; | ||
| 396 | if (device) { | ||
| 397 | std::tie(motion_devices[e].accel, motion_devices[e].gyro, | ||
| 398 | motion_devices[e].rotation, motion_devices[e].orientation) = | ||
| 399 | device->GetStatus(); | ||
| 400 | sixaxis_at_rest = sixaxis_at_rest && motion_devices[e].gyro.Length2() < 1.0f; | ||
| 401 | } | ||
| 402 | } | ||
| 403 | } | ||
| 404 | |||
| 362 | RequestPadStateUpdate(npad_index); | 405 | RequestPadStateUpdate(npad_index); |
| 363 | auto& pad_state = npad_pad_states[npad_index]; | 406 | auto& pad_state = npad_pad_states[npad_index]; |
| 364 | 407 | ||
| @@ -376,6 +419,18 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 376 | 419 | ||
| 377 | libnx_entry.connection_status.raw = 0; | 420 | libnx_entry.connection_status.raw = 0; |
| 378 | libnx_entry.connection_status.IsConnected.Assign(1); | 421 | libnx_entry.connection_status.IsConnected.Assign(1); |
| 422 | auto& full_sixaxis_entry = | ||
| 423 | npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; | ||
| 424 | auto& handheld_sixaxis_entry = | ||
| 425 | npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index]; | ||
| 426 | auto& dual_left_sixaxis_entry = | ||
| 427 | npad.sixaxis_dual_left.sixaxis[npad.sixaxis_dual_left.common.last_entry_index]; | ||
| 428 | auto& dual_right_sixaxis_entry = | ||
| 429 | npad.sixaxis_dual_right.sixaxis[npad.sixaxis_dual_right.common.last_entry_index]; | ||
| 430 | auto& left_sixaxis_entry = | ||
| 431 | npad.sixaxis_left.sixaxis[npad.sixaxis_left.common.last_entry_index]; | ||
| 432 | auto& right_sixaxis_entry = | ||
| 433 | npad.sixaxis_right.sixaxis[npad.sixaxis_right.common.last_entry_index]; | ||
| 379 | 434 | ||
| 380 | switch (controller_type) { | 435 | switch (controller_type) { |
| 381 | case NPadControllerType::None: | 436 | case NPadControllerType::None: |
| @@ -390,6 +445,13 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 390 | main_controller.pad.r_stick = pad_state.r_stick; | 445 | main_controller.pad.r_stick = pad_state.r_stick; |
| 391 | 446 | ||
| 392 | libnx_entry.connection_status.IsWired.Assign(1); | 447 | libnx_entry.connection_status.IsWired.Assign(1); |
| 448 | |||
| 449 | if (sixaxis_sensors_enabled && motions[i][0]) { | ||
| 450 | full_sixaxis_entry.accel = motion_devices[0].accel; | ||
| 451 | full_sixaxis_entry.gyro = motion_devices[0].gyro; | ||
| 452 | full_sixaxis_entry.rotation = motion_devices[0].rotation; | ||
| 453 | full_sixaxis_entry.orientation = motion_devices[0].orientation; | ||
| 454 | } | ||
| 393 | break; | 455 | break; |
| 394 | case NPadControllerType::Handheld: | 456 | case NPadControllerType::Handheld: |
| 395 | handheld_entry.connection_status.raw = 0; | 457 | handheld_entry.connection_status.raw = 0; |
| @@ -408,6 +470,13 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 408 | libnx_entry.connection_status.IsRightJoyConnected.Assign(1); | 470 | libnx_entry.connection_status.IsRightJoyConnected.Assign(1); |
| 409 | libnx_entry.connection_status.IsLeftJoyWired.Assign(1); | 471 | libnx_entry.connection_status.IsLeftJoyWired.Assign(1); |
| 410 | libnx_entry.connection_status.IsRightJoyWired.Assign(1); | 472 | libnx_entry.connection_status.IsRightJoyWired.Assign(1); |
| 473 | |||
| 474 | if (sixaxis_sensors_enabled && motions[i][0]) { | ||
| 475 | handheld_sixaxis_entry.accel = motion_devices[0].accel; | ||
| 476 | handheld_sixaxis_entry.gyro = motion_devices[0].gyro; | ||
| 477 | handheld_sixaxis_entry.rotation = motion_devices[0].rotation; | ||
| 478 | handheld_sixaxis_entry.orientation = motion_devices[0].orientation; | ||
| 479 | } | ||
| 411 | break; | 480 | break; |
| 412 | case NPadControllerType::JoyDual: | 481 | case NPadControllerType::JoyDual: |
| 413 | dual_entry.connection_status.raw = 0; | 482 | dual_entry.connection_status.raw = 0; |
| @@ -420,6 +489,32 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 420 | 489 | ||
| 421 | libnx_entry.connection_status.IsLeftJoyConnected.Assign(1); | 490 | libnx_entry.connection_status.IsLeftJoyConnected.Assign(1); |
| 422 | libnx_entry.connection_status.IsRightJoyConnected.Assign(1); | 491 | libnx_entry.connection_status.IsRightJoyConnected.Assign(1); |
| 492 | |||
| 493 | if (sixaxis_sensors_enabled) { | ||
| 494 | if (motions[i][0] && motions[i][1]) { | ||
| 495 | // set both | ||
| 496 | dual_left_sixaxis_entry.accel = motion_devices[0].accel; | ||
| 497 | dual_left_sixaxis_entry.gyro = motion_devices[0].gyro; | ||
| 498 | dual_left_sixaxis_entry.rotation = motion_devices[0].rotation; | ||
| 499 | dual_left_sixaxis_entry.orientation = motion_devices[0].orientation; | ||
| 500 | dual_right_sixaxis_entry.accel = motion_devices[1].accel; | ||
| 501 | dual_right_sixaxis_entry.gyro = motion_devices[1].gyro; | ||
| 502 | dual_right_sixaxis_entry.rotation = motion_devices[1].rotation; | ||
| 503 | dual_right_sixaxis_entry.orientation = motion_devices[1].orientation; | ||
| 504 | } else if (motions[i][0]) { | ||
| 505 | // set right | ||
| 506 | dual_right_sixaxis_entry.accel = motion_devices[0].accel; | ||
| 507 | dual_right_sixaxis_entry.gyro = motion_devices[0].gyro; | ||
| 508 | dual_right_sixaxis_entry.rotation = motion_devices[0].rotation; | ||
| 509 | dual_right_sixaxis_entry.orientation = motion_devices[0].orientation; | ||
| 510 | } else if (motions[i][1]) { | ||
| 511 | // set right | ||
| 512 | dual_right_sixaxis_entry.accel = motion_devices[1].accel; | ||
| 513 | dual_right_sixaxis_entry.gyro = motion_devices[1].gyro; | ||
| 514 | dual_right_sixaxis_entry.rotation = motion_devices[1].rotation; | ||
| 515 | dual_right_sixaxis_entry.orientation = motion_devices[1].orientation; | ||
| 516 | } | ||
| 517 | } | ||
| 423 | break; | 518 | break; |
| 424 | case NPadControllerType::JoyLeft: | 519 | case NPadControllerType::JoyLeft: |
| 425 | left_entry.connection_status.raw = 0; | 520 | left_entry.connection_status.raw = 0; |
| @@ -430,6 +525,13 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 430 | left_entry.pad.r_stick = pad_state.r_stick; | 525 | left_entry.pad.r_stick = pad_state.r_stick; |
| 431 | 526 | ||
| 432 | libnx_entry.connection_status.IsLeftJoyConnected.Assign(1); | 527 | libnx_entry.connection_status.IsLeftJoyConnected.Assign(1); |
| 528 | |||
| 529 | if (sixaxis_sensors_enabled && motions[i][0]) { | ||
| 530 | left_sixaxis_entry.accel = motion_devices[0].accel; | ||
| 531 | left_sixaxis_entry.gyro = motion_devices[0].gyro; | ||
| 532 | left_sixaxis_entry.rotation = motion_devices[0].rotation; | ||
| 533 | left_sixaxis_entry.orientation = motion_devices[0].orientation; | ||
| 534 | } | ||
| 433 | break; | 535 | break; |
| 434 | case NPadControllerType::JoyRight: | 536 | case NPadControllerType::JoyRight: |
| 435 | right_entry.connection_status.raw = 0; | 537 | right_entry.connection_status.raw = 0; |
| @@ -440,6 +542,13 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* | |||
| 440 | right_entry.pad.r_stick = pad_state.r_stick; | 542 | right_entry.pad.r_stick = pad_state.r_stick; |
| 441 | 543 | ||
| 442 | libnx_entry.connection_status.IsRightJoyConnected.Assign(1); | 544 | libnx_entry.connection_status.IsRightJoyConnected.Assign(1); |
| 545 | |||
| 546 | if (sixaxis_sensors_enabled && motions[i][0]) { | ||
| 547 | right_sixaxis_entry.accel = motion_devices[0].accel; | ||
| 548 | right_sixaxis_entry.gyro = motion_devices[0].gyro; | ||
| 549 | right_sixaxis_entry.rotation = motion_devices[0].rotation; | ||
| 550 | right_sixaxis_entry.orientation = motion_devices[0].orientation; | ||
| 551 | } | ||
| 443 | break; | 552 | break; |
| 444 | case NPadControllerType::Pokeball: | 553 | case NPadControllerType::Pokeball: |
| 445 | pokeball_entry.connection_status.raw = 0; | 554 | pokeball_entry.connection_status.raw = 0; |
| @@ -574,6 +683,14 @@ Controller_NPad::GyroscopeZeroDriftMode Controller_NPad::GetGyroscopeZeroDriftMo | |||
| 574 | return gyroscope_zero_drift_mode; | 683 | return gyroscope_zero_drift_mode; |
| 575 | } | 684 | } |
| 576 | 685 | ||
| 686 | bool Controller_NPad::IsSixAxisSensorAtRest() const { | ||
| 687 | return sixaxis_at_rest; | ||
| 688 | } | ||
| 689 | |||
| 690 | void Controller_NPad::SetSixAxisEnabled(bool six_axis_status) { | ||
| 691 | sixaxis_sensors_enabled = six_axis_status; | ||
| 692 | } | ||
| 693 | |||
| 577 | void Controller_NPad::MergeSingleJoyAsDualJoy(u32 npad_id_1, u32 npad_id_2) { | 694 | void Controller_NPad::MergeSingleJoyAsDualJoy(u32 npad_id_1, u32 npad_id_2) { |
| 578 | const auto npad_index_1 = NPadIdToIndex(npad_id_1); | 695 | const auto npad_index_1 = NPadIdToIndex(npad_id_1); |
| 579 | const auto npad_index_2 = NPadIdToIndex(npad_id_2); | 696 | const auto npad_index_2 = NPadIdToIndex(npad_id_2); |
diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index ad25c6fbf..99d7e459a 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h | |||
| @@ -126,6 +126,8 @@ public: | |||
| 126 | void DisconnectNPad(u32 npad_id); | 126 | void DisconnectNPad(u32 npad_id); |
| 127 | void SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode drift_mode); | 127 | void SetGyroscopeZeroDriftMode(GyroscopeZeroDriftMode drift_mode); |
| 128 | GyroscopeZeroDriftMode GetGyroscopeZeroDriftMode() const; | 128 | GyroscopeZeroDriftMode GetGyroscopeZeroDriftMode() const; |
| 129 | bool IsSixAxisSensorAtRest() const; | ||
| 130 | void SetSixAxisEnabled(bool six_axis_status); | ||
| 129 | LedPattern GetLedPattern(u32 npad_id); | 131 | LedPattern GetLedPattern(u32 npad_id); |
| 130 | void SetVibrationEnabled(bool can_vibrate); | 132 | void SetVibrationEnabled(bool can_vibrate); |
| 131 | bool IsVibrationEnabled() const; | 133 | bool IsVibrationEnabled() const; |
| @@ -248,6 +250,24 @@ private: | |||
| 248 | }; | 250 | }; |
| 249 | static_assert(sizeof(NPadGeneric) == 0x350, "NPadGeneric is an invalid size"); | 251 | static_assert(sizeof(NPadGeneric) == 0x350, "NPadGeneric is an invalid size"); |
| 250 | 252 | ||
| 253 | struct SixAxisStates { | ||
| 254 | s64_le timestamp{}; | ||
| 255 | INSERT_PADDING_WORDS(2); | ||
| 256 | s64_le timestamp2{}; | ||
| 257 | Common::Vec3f accel{}; | ||
| 258 | Common::Vec3f gyro{}; | ||
| 259 | Common::Vec3f rotation{}; | ||
| 260 | std::array<Common::Vec3f, 3> orientation{}; | ||
| 261 | s64_le always_one{1}; | ||
| 262 | }; | ||
| 263 | static_assert(sizeof(SixAxisStates) == 0x68, "SixAxisStates is an invalid size"); | ||
| 264 | |||
| 265 | struct SixAxisGeneric { | ||
| 266 | CommonHeader common{}; | ||
| 267 | std::array<SixAxisStates, 17> sixaxis{}; | ||
| 268 | }; | ||
| 269 | static_assert(sizeof(SixAxisGeneric) == 0x708, "SixAxisGeneric is an invalid size"); | ||
| 270 | |||
| 251 | enum class ColorReadError : u32_le { | 271 | enum class ColorReadError : u32_le { |
| 252 | ReadOk = 0, | 272 | ReadOk = 0, |
| 253 | ColorDoesntExist = 1, | 273 | ColorDoesntExist = 1, |
| @@ -277,6 +297,13 @@ private: | |||
| 277 | }; | 297 | }; |
| 278 | }; | 298 | }; |
| 279 | 299 | ||
| 300 | struct MotionDevice { | ||
| 301 | Common::Vec3f accel; | ||
| 302 | Common::Vec3f gyro{}; | ||
| 303 | Common::Vec3f rotation; | ||
| 304 | std::array<Common::Vec3f, 3> orientation{}; | ||
| 305 | }; | ||
| 306 | |||
| 280 | struct NPadEntry { | 307 | struct NPadEntry { |
| 281 | NPadType joy_styles; | 308 | NPadType joy_styles; |
| 282 | NPadAssignments pad_assignment; | 309 | NPadAssignments pad_assignment; |
| @@ -296,9 +323,12 @@ private: | |||
| 296 | NPadGeneric pokeball_states; | 323 | NPadGeneric pokeball_states; |
| 297 | NPadGeneric libnx; // TODO(ogniK): Find out what this actually is, libnx seems to only be | 324 | NPadGeneric libnx; // TODO(ogniK): Find out what this actually is, libnx seems to only be |
| 298 | // relying on this for the time being | 325 | // relying on this for the time being |
| 299 | INSERT_PADDING_BYTES( | 326 | SixAxisGeneric sixaxis_full; |
| 300 | 0x708 * | 327 | SixAxisGeneric sixaxis_handheld; |
| 301 | 6); // TODO(ogniK): SixAxis states, require more information before implementation | 328 | SixAxisGeneric sixaxis_dual_left; |
| 329 | SixAxisGeneric sixaxis_dual_right; | ||
| 330 | SixAxisGeneric sixaxis_left; | ||
| 331 | SixAxisGeneric sixaxis_right; | ||
| 302 | NPadDevice device_type; | 332 | NPadDevice device_type; |
| 303 | NPadProperties properties; | 333 | NPadProperties properties; |
| 304 | INSERT_PADDING_WORDS(1); | 334 | INSERT_PADDING_WORDS(1); |
| @@ -322,14 +352,18 @@ private: | |||
| 322 | 352 | ||
| 323 | NPadType style{}; | 353 | NPadType style{}; |
| 324 | std::array<NPadEntry, 10> shared_memory_entries{}; | 354 | std::array<NPadEntry, 10> shared_memory_entries{}; |
| 325 | std::array< | 355 | using ButtonArray = std::array< |
| 326 | std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>, | 356 | std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>, |
| 327 | 10> | 357 | 10>; |
| 328 | buttons; | 358 | using StickArray = std::array< |
| 329 | std::array< | ||
| 330 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>, | 359 | std::array<std::unique_ptr<Input::AnalogDevice>, Settings::NativeAnalog::NUM_STICKS_HID>, |
| 331 | 10> | 360 | 10>; |
| 332 | sticks; | 361 | using MotionArray = std::array<std::array<std::unique_ptr<Input::RealMotionDevice>, |
| 362 | Settings::NativeMotion::NUM_MOTION_HID>, | ||
| 363 | 10>; | ||
| 364 | ButtonArray buttons; | ||
| 365 | StickArray sticks; | ||
| 366 | MotionArray motions; | ||
| 333 | std::vector<u32> supported_npad_id_types{}; | 367 | std::vector<u32> supported_npad_id_types{}; |
| 334 | NpadHoldType hold_type{NpadHoldType::Vertical}; | 368 | NpadHoldType hold_type{NpadHoldType::Vertical}; |
| 335 | // Each controller should have their own styleset changed event | 369 | // Each controller should have their own styleset changed event |
| @@ -338,6 +372,8 @@ private: | |||
| 338 | std::array<ControllerHolder, 10> connected_controllers{}; | 372 | std::array<ControllerHolder, 10> connected_controllers{}; |
| 339 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; | 373 | GyroscopeZeroDriftMode gyroscope_zero_drift_mode{GyroscopeZeroDriftMode::Standard}; |
| 340 | bool can_controllers_vibrate{true}; | 374 | bool can_controllers_vibrate{true}; |
| 375 | bool sixaxis_sensors_enabled{true}; | ||
| 376 | bool sixaxis_at_rest{true}; | ||
| 341 | std::array<ControllerPad, 10> npad_pad_states{}; | 377 | std::array<ControllerPad, 10> npad_pad_states{}; |
| 342 | bool is_in_lr_assignment_mode{false}; | 378 | bool is_in_lr_assignment_mode{false}; |
| 343 | Core::System& system; | 379 | Core::System& system; |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index bd3c2f26b..302a25540 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -164,8 +164,8 @@ Hid::Hid(Core::System& system) : ServiceFramework("hid"), system(system) { | |||
| 164 | {56, nullptr, "ActivateJoyXpad"}, | 164 | {56, nullptr, "ActivateJoyXpad"}, |
| 165 | {58, nullptr, "GetJoyXpadLifoHandle"}, | 165 | {58, nullptr, "GetJoyXpadLifoHandle"}, |
| 166 | {59, nullptr, "GetJoyXpadIds"}, | 166 | {59, nullptr, "GetJoyXpadIds"}, |
| 167 | {60, nullptr, "ActivateSixAxisSensor"}, | 167 | {60, &Hid::ActivateSixAxisSensor, "ActivateSixAxisSensor"}, |
| 168 | {61, nullptr, "DeactivateSixAxisSensor"}, | 168 | {61, &Hid::DeactivateSixAxisSensor, "DeactivateSixAxisSensor"}, |
| 169 | {62, nullptr, "GetSixAxisSensorLifoHandle"}, | 169 | {62, nullptr, "GetSixAxisSensorLifoHandle"}, |
| 170 | {63, nullptr, "ActivateJoySixAxisSensor"}, | 170 | {63, nullptr, "ActivateJoySixAxisSensor"}, |
| 171 | {64, nullptr, "DeactivateJoySixAxisSensor"}, | 171 | {64, nullptr, "DeactivateJoySixAxisSensor"}, |
| @@ -329,6 +329,31 @@ void Hid::GetXpadIDs(Kernel::HLERequestContext& ctx) { | |||
| 329 | rb.Push(0); | 329 | rb.Push(0); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | void Hid::ActivateSixAxisSensor(Kernel::HLERequestContext& ctx) { | ||
| 333 | IPC::RequestParser rp{ctx}; | ||
| 334 | const auto handle{rp.Pop<u32>()}; | ||
| 335 | const auto applet_resource_user_id{rp.Pop<u64>()}; | ||
| 336 | applet_resource->GetController<Controller_NPad>(HidController::NPad).SetSixAxisEnabled(true); | ||
| 337 | LOG_DEBUG(Service_HID, "called, handle={}, applet_resource_user_id={}", handle, | ||
| 338 | applet_resource_user_id); | ||
| 339 | |||
| 340 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 341 | rb.Push(RESULT_SUCCESS); | ||
| 342 | } | ||
| 343 | |||
| 344 | void Hid::DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx) { | ||
| 345 | IPC::RequestParser rp{ctx}; | ||
| 346 | const auto handle{rp.Pop<u32>()}; | ||
| 347 | const auto applet_resource_user_id{rp.Pop<u64>()}; | ||
| 348 | applet_resource->GetController<Controller_NPad>(HidController::NPad).SetSixAxisEnabled(false); | ||
| 349 | |||
| 350 | LOG_DEBUG(Service_HID, "called, handle={}, applet_resource_user_id={}", handle, | ||
| 351 | applet_resource_user_id); | ||
| 352 | |||
| 353 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 354 | rb.Push(RESULT_SUCCESS); | ||
| 355 | } | ||
| 356 | |||
| 332 | void Hid::ActivateDebugPad(Kernel::HLERequestContext& ctx) { | 357 | void Hid::ActivateDebugPad(Kernel::HLERequestContext& ctx) { |
| 333 | IPC::RequestParser rp{ctx}; | 358 | IPC::RequestParser rp{ctx}; |
| 334 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 359 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| @@ -484,13 +509,13 @@ void Hid::IsSixAxisSensorAtRest(Kernel::HLERequestContext& ctx) { | |||
| 484 | const auto handle{rp.Pop<u32>()}; | 509 | const auto handle{rp.Pop<u32>()}; |
| 485 | const auto applet_resource_user_id{rp.Pop<u64>()}; | 510 | const auto applet_resource_user_id{rp.Pop<u64>()}; |
| 486 | 511 | ||
| 487 | LOG_WARNING(Service_HID, "(STUBBED) called, handle={}, applet_resource_user_id={}", handle, | 512 | LOG_DEBUG(Service_HID, "called, handle={}, applet_resource_user_id={}", handle, |
| 488 | applet_resource_user_id); | 513 | applet_resource_user_id); |
| 489 | 514 | ||
| 490 | IPC::ResponseBuilder rb{ctx, 3}; | 515 | IPC::ResponseBuilder rb{ctx, 3}; |
| 491 | rb.Push(RESULT_SUCCESS); | 516 | rb.Push(RESULT_SUCCESS); |
| 492 | // TODO (Hexagon12): Properly implement reading gyroscope values from controllers. | 517 | rb.Push(applet_resource->GetController<Controller_NPad>(HidController::NPad) |
| 493 | rb.Push(true); | 518 | .IsSixAxisSensorAtRest()); |
| 494 | } | 519 | } |
| 495 | 520 | ||
| 496 | void Hid::SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { | 521 | void Hid::SetSupportedNpadStyleSet(Kernel::HLERequestContext& ctx) { |
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index efb07547f..e04aaf1e9 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -86,6 +86,8 @@ private: | |||
| 86 | void CreateAppletResource(Kernel::HLERequestContext& ctx); | 86 | void CreateAppletResource(Kernel::HLERequestContext& ctx); |
| 87 | void ActivateXpad(Kernel::HLERequestContext& ctx); | 87 | void ActivateXpad(Kernel::HLERequestContext& ctx); |
| 88 | void GetXpadIDs(Kernel::HLERequestContext& ctx); | 88 | void GetXpadIDs(Kernel::HLERequestContext& ctx); |
| 89 | void ActivateSixAxisSensor(Kernel::HLERequestContext& ctx); | ||
| 90 | void DeactivateSixAxisSensor(Kernel::HLERequestContext& ctx); | ||
| 89 | void ActivateDebugPad(Kernel::HLERequestContext& ctx); | 91 | void ActivateDebugPad(Kernel::HLERequestContext& ctx); |
| 90 | void ActivateTouchScreen(Kernel::HLERequestContext& ctx); | 92 | void ActivateTouchScreen(Kernel::HLERequestContext& ctx); |
| 91 | void ActivateMouse(Kernel::HLERequestContext& ctx); | 93 | void ActivateMouse(Kernel::HLERequestContext& ctx); |