diff options
| -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 | ||||
| -rw-r--r-- | src/input_common/main.h | 10 | ||||
| -rw-r--r-- | src/input_common/settings.cpp | 7 | ||||
| -rw-r--r-- | src/input_common/settings.h | 17 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 29 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.h | 1 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 61 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.h | 3 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.ui | 99 |
13 files changed, 448 insertions, 16 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); |
diff --git a/src/input_common/main.h b/src/input_common/main.h index f3fbf696e..18f44dcc3 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -21,10 +21,14 @@ namespace Settings::NativeButton { | |||
| 21 | enum Values : int; | 21 | enum Values : int; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | namespace Settings::NativeMotion { | ||
| 25 | enum Values : int; | ||
| 26 | } | ||
| 27 | |||
| 24 | namespace InputCommon { | 28 | namespace InputCommon { |
| 25 | namespace Polling { | 29 | namespace Polling { |
| 26 | 30 | ||
| 27 | enum class DeviceType { Button, AnalogPreferred }; | 31 | enum class DeviceType { Button, AnalogPreferred, Motion }; |
| 28 | 32 | ||
| 29 | /** | 33 | /** |
| 30 | * A class that can be used to get inputs from an input device like controllers without having to | 34 | * A class that can be used to get inputs from an input device like controllers without having to |
| @@ -59,6 +63,7 @@ class MotionEmu; | |||
| 59 | */ | 63 | */ |
| 60 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; | 64 | using AnalogMapping = std::unordered_map<Settings::NativeAnalog::Values, Common::ParamPackage>; |
| 61 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; | 65 | using ButtonMapping = std::unordered_map<Settings::NativeButton::Values, Common::ParamPackage>; |
| 66 | using MotionMapping = std::unordered_map<Settings::NativeMotion::Values, Common::ParamPackage>; | ||
| 62 | 67 | ||
| 63 | class InputSubsystem { | 68 | class InputSubsystem { |
| 64 | public: | 69 | public: |
| @@ -103,6 +108,9 @@ public: | |||
| 103 | /// Retrieves the button mappings for the given device. | 108 | /// Retrieves the button mappings for the given device. |
| 104 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& device) const; | 109 | [[nodiscard]] ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& device) const; |
| 105 | 110 | ||
| 111 | /// Retrieves the motion mappings for the given device. | ||
| 112 | [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const; | ||
| 113 | |||
| 106 | /// Retrieves the underlying GameCube analog handler. | 114 | /// Retrieves the underlying GameCube analog handler. |
| 107 | [[nodiscard]] GCAnalogFactory* GetGCAnalogs(); | 115 | [[nodiscard]] GCAnalogFactory* GetGCAnalogs(); |
| 108 | 116 | ||
diff --git a/src/input_common/settings.cpp b/src/input_common/settings.cpp index 80c719cf4..b66c05856 100644 --- a/src/input_common/settings.cpp +++ b/src/input_common/settings.cpp | |||
| @@ -14,6 +14,13 @@ const std::array<const char*, NumButtons> mapping = {{ | |||
| 14 | }}; | 14 | }}; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | namespace NativeMotion { | ||
| 18 | const std::array<const char*, NumMotions> mapping = {{ | ||
| 19 | "motionleft", | ||
| 20 | "motionright", | ||
| 21 | }}; | ||
| 22 | } | ||
| 23 | |||
| 17 | namespace NativeAnalog { | 24 | namespace NativeAnalog { |
| 18 | const std::array<const char*, NumAnalogs> mapping = {{ | 25 | const std::array<const char*, NumAnalogs> mapping = {{ |
| 19 | "lstick", | 26 | "lstick", |
diff --git a/src/input_common/settings.h b/src/input_common/settings.h index 2d258960b..ab0b95cf1 100644 --- a/src/input_common/settings.h +++ b/src/input_common/settings.h | |||
| @@ -66,6 +66,21 @@ constexpr int NUM_STICKS_HID = NumAnalogs; | |||
| 66 | extern const std::array<const char*, NumAnalogs> mapping; | 66 | extern const std::array<const char*, NumAnalogs> mapping; |
| 67 | } // namespace NativeAnalog | 67 | } // namespace NativeAnalog |
| 68 | 68 | ||
| 69 | namespace NativeMotion { | ||
| 70 | enum Values : int { | ||
| 71 | MOTIONLEFT, | ||
| 72 | MOTIONRIGHT, | ||
| 73 | |||
| 74 | NumMotions, | ||
| 75 | }; | ||
| 76 | |||
| 77 | constexpr int MOTION_HID_BEGIN = MOTIONLEFT; | ||
| 78 | constexpr int MOTION_HID_END = NumMotions; | ||
| 79 | constexpr int NUM_MOTION_HID = NumMotions; | ||
| 80 | |||
| 81 | extern const std::array<const char*, NumMotions> mapping; | ||
| 82 | } // namespace NativeMotion | ||
| 83 | |||
| 69 | namespace NativeMouseButton { | 84 | namespace NativeMouseButton { |
| 70 | enum Values { | 85 | enum Values { |
| 71 | Left, | 86 | Left, |
| @@ -292,6 +307,7 @@ constexpr int NUM_KEYBOARD_MODS_HID = NumKeyboardMods; | |||
| 292 | 307 | ||
| 293 | using ButtonsRaw = std::array<std::string, NativeButton::NumButtons>; | 308 | using ButtonsRaw = std::array<std::string, NativeButton::NumButtons>; |
| 294 | using AnalogsRaw = std::array<std::string, NativeAnalog::NumAnalogs>; | 309 | using AnalogsRaw = std::array<std::string, NativeAnalog::NumAnalogs>; |
| 310 | using MotionRaw = std::array<std::string, NativeMotion::NumMotions>; | ||
| 295 | using MouseButtonsRaw = std::array<std::string, NativeMouseButton::NumMouseButtons>; | 311 | using MouseButtonsRaw = std::array<std::string, NativeMouseButton::NumMouseButtons>; |
| 296 | using KeyboardKeysRaw = std::array<std::string, NativeKeyboard::NumKeyboardKeys>; | 312 | using KeyboardKeysRaw = std::array<std::string, NativeKeyboard::NumKeyboardKeys>; |
| 297 | using KeyboardModsRaw = std::array<std::string, NativeKeyboard::NumKeyboardMods>; | 313 | using KeyboardModsRaw = std::array<std::string, NativeKeyboard::NumKeyboardMods>; |
| @@ -314,6 +330,7 @@ struct PlayerInput { | |||
| 314 | ControllerType controller_type; | 330 | ControllerType controller_type; |
| 315 | ButtonsRaw buttons; | 331 | ButtonsRaw buttons; |
| 316 | AnalogsRaw analogs; | 332 | AnalogsRaw analogs; |
| 333 | MotionRaw motions; | ||
| 317 | std::string lstick_mod; | 334 | std::string lstick_mod; |
| 318 | std::string rstick_mod; | 335 | std::string rstick_mod; |
| 319 | 336 | ||
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 2bc55a26a..40ca42b75 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -36,6 +36,11 @@ const std::array<int, Settings::NativeButton::NumButtons> Config::default_button | |||
| 36 | Qt::Key_H, Qt::Key_G, Qt::Key_D, Qt::Key_C, Qt::Key_B, Qt::Key_V, | 36 | Qt::Key_H, Qt::Key_G, Qt::Key_D, Qt::Key_C, Qt::Key_B, Qt::Key_V, |
| 37 | }; | 37 | }; |
| 38 | 38 | ||
| 39 | const std::array<int, Settings::NativeMotion::NumMotions> Config::default_motions = { | ||
| 40 | Qt::Key_7, | ||
| 41 | Qt::Key_8, | ||
| 42 | }; | ||
| 43 | |||
| 39 | const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{ | 44 | const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{ |
| 40 | { | 45 | { |
| 41 | Qt::Key_Up, | 46 | Qt::Key_Up, |
| @@ -284,6 +289,22 @@ void Config::ReadPlayerValues() { | |||
| 284 | } | 289 | } |
| 285 | } | 290 | } |
| 286 | 291 | ||
| 292 | for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) { | ||
| 293 | const std::string default_param = | ||
| 294 | InputCommon::GenerateKeyboardParam(default_motions[i]); | ||
| 295 | auto& player_motions = player.motions[i]; | ||
| 296 | |||
| 297 | player_motions = qt_config | ||
| 298 | ->value(QStringLiteral("player_%1_").arg(p) + | ||
| 299 | QString::fromUtf8(Settings::NativeMotion::mapping[i]), | ||
| 300 | QString::fromStdString(default_param)) | ||
| 301 | .toString() | ||
| 302 | .toStdString(); | ||
| 303 | if (player_motions.empty()) { | ||
| 304 | player_motions = default_param; | ||
| 305 | } | ||
| 306 | } | ||
| 307 | |||
| 287 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | 308 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { |
| 288 | const std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | 309 | const std::string default_param = InputCommon::GenerateAnalogParamFromKeys( |
| 289 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | 310 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], |
| @@ -922,6 +943,14 @@ void Config::SavePlayerValues() { | |||
| 922 | QString::fromStdString(player.buttons[i]), | 943 | QString::fromStdString(player.buttons[i]), |
| 923 | QString::fromStdString(default_param)); | 944 | QString::fromStdString(default_param)); |
| 924 | } | 945 | } |
| 946 | for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) { | ||
| 947 | const std::string default_param = | ||
| 948 | InputCommon::GenerateKeyboardParam(default_motions[i]); | ||
| 949 | WriteSetting(QStringLiteral("player_%1_").arg(p) + | ||
| 950 | QString::fromStdString(Settings::NativeMotion::mapping[i]), | ||
| 951 | QString::fromStdString(player.motions[i]), | ||
| 952 | QString::fromStdString(default_param)); | ||
| 953 | } | ||
| 925 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { | 954 | for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { |
| 926 | const std::string default_param = InputCommon::GenerateAnalogParamFromKeys( | 955 | const std::string default_param = InputCommon::GenerateAnalogParamFromKeys( |
| 927 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], | 956 | default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], |
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index ca0d29c6c..5d8e45d78 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -23,6 +23,7 @@ public: | |||
| 23 | void Save(); | 23 | void Save(); |
| 24 | 24 | ||
| 25 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons; | 25 | static const std::array<int, Settings::NativeButton::NumButtons> default_buttons; |
| 26 | static const std::array<int, Settings::NativeMotion::NumMotions> default_motions; | ||
| 26 | static const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> default_analogs; | 27 | static const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> default_analogs; |
| 27 | static const std::array<int, 2> default_stick_mod; | 28 | static const std::array<int, 2> default_stick_mod; |
| 28 | static const std::array<int, Settings::NativeMouseButton::NumMouseButtons> | 29 | static const std::array<int, Settings::NativeMouseButton::NumMouseButtons> |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 13ecb3dc5..f6942851a 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -262,6 +262,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 262 | }, | 262 | }, |
| 263 | }}; | 263 | }}; |
| 264 | 264 | ||
| 265 | motion_map = { | ||
| 266 | ui->buttonMotionLeft, | ||
| 267 | ui->buttonMotionRight, | ||
| 268 | }; | ||
| 269 | |||
| 265 | analog_map_deadzone_label = {ui->labelLStickDeadzone, ui->labelRStickDeadzone}; | 270 | analog_map_deadzone_label = {ui->labelLStickDeadzone, ui->labelRStickDeadzone}; |
| 266 | analog_map_deadzone_slider = {ui->sliderLStickDeadzone, ui->sliderRStickDeadzone}; | 271 | analog_map_deadzone_slider = {ui->sliderLStickDeadzone, ui->sliderRStickDeadzone}; |
| 267 | analog_map_modifier_groupbox = {ui->buttonLStickModGroup, ui->buttonRStickModGroup}; | 272 | analog_map_modifier_groupbox = {ui->buttonLStickModGroup, ui->buttonRStickModGroup}; |
| @@ -304,6 +309,37 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i | |||
| 304 | Config::default_buttons[button_id]); | 309 | Config::default_buttons[button_id]); |
| 305 | } | 310 | } |
| 306 | 311 | ||
| 312 | for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | ||
| 313 | auto* const button = motion_map[motion_id]; | ||
| 314 | if (button == nullptr) { | ||
| 315 | continue; | ||
| 316 | } | ||
| 317 | |||
| 318 | button->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 319 | connect(button, &QPushButton::clicked, [=, this] { | ||
| 320 | HandleClick( | ||
| 321 | motion_map[motion_id], | ||
| 322 | [=, this](Common::ParamPackage params) { | ||
| 323 | motions_param[motion_id] = std::move(params); | ||
| 324 | }, | ||
| 325 | InputCommon::Polling::DeviceType::Motion); | ||
| 326 | }); | ||
| 327 | connect(button, &QPushButton::customContextMenuRequested, | ||
| 328 | [=, this](const QPoint& menu_location) { | ||
| 329 | QMenu context_menu; | ||
| 330 | context_menu.addAction(tr("Clear"), [&] { | ||
| 331 | motions_param[motion_id].Clear(); | ||
| 332 | motion_map[motion_id]->setText(tr("[not set]")); | ||
| 333 | }); | ||
| 334 | context_menu.addAction(tr("Restore Default"), [&] { | ||
| 335 | motions_param[motion_id] = Common::ParamPackage{ | ||
| 336 | InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])}; | ||
| 337 | motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); | ||
| 338 | }); | ||
| 339 | context_menu.exec(motion_map[motion_id]->mapToGlobal(menu_location)); | ||
| 340 | }); | ||
| 341 | } | ||
| 342 | |||
| 307 | // Handle clicks for the modifier buttons as well. | 343 | // Handle clicks for the modifier buttons as well. |
| 308 | ConfigureButtonClick(ui->buttonLStickMod, &lstick_mod, Config::default_stick_mod[0]); | 344 | ConfigureButtonClick(ui->buttonLStickMod, &lstick_mod, Config::default_stick_mod[0]); |
| 309 | ConfigureButtonClick(ui->buttonRStickMod, &rstick_mod, Config::default_stick_mod[1]); | 345 | ConfigureButtonClick(ui->buttonRStickMod, &rstick_mod, Config::default_stick_mod[1]); |
| @@ -448,6 +484,10 @@ void ConfigureInputPlayer::ApplyConfiguration() { | |||
| 448 | return; | 484 | return; |
| 449 | } | 485 | } |
| 450 | 486 | ||
| 487 | auto& motions = player.motions; | ||
| 488 | std::transform(motions_param.begin(), motions_param.end(), motions.begin(), | ||
| 489 | [](const Common::ParamPackage& param) { return param.Serialize(); }); | ||
| 490 | |||
| 451 | player.controller_type = | 491 | player.controller_type = |
| 452 | static_cast<Settings::ControllerType>(ui->comboControllerType->currentIndex()); | 492 | static_cast<Settings::ControllerType>(ui->comboControllerType->currentIndex()); |
| 453 | player.connected = ui->groupConnectedController->isChecked(); | 493 | player.connected = ui->groupConnectedController->isChecked(); |
| @@ -501,6 +541,8 @@ void ConfigureInputPlayer::LoadConfiguration() { | |||
| 501 | [](const std::string& str) { return Common::ParamPackage(str); }); | 541 | [](const std::string& str) { return Common::ParamPackage(str); }); |
| 502 | std::transform(player.analogs.begin(), player.analogs.end(), analogs_param.begin(), | 542 | std::transform(player.analogs.begin(), player.analogs.end(), analogs_param.begin(), |
| 503 | [](const std::string& str) { return Common::ParamPackage(str); }); | 543 | [](const std::string& str) { return Common::ParamPackage(str); }); |
| 544 | std::transform(player.motions.begin(), player.motions.end(), motions_param.begin(), | ||
| 545 | [](const std::string& str) { return Common::ParamPackage(str); }); | ||
| 504 | } | 546 | } |
| 505 | 547 | ||
| 506 | UpdateUI(); | 548 | UpdateUI(); |
| @@ -544,6 +586,12 @@ void ConfigureInputPlayer::RestoreDefaults() { | |||
| 544 | SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); | 586 | SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]); |
| 545 | } | 587 | } |
| 546 | } | 588 | } |
| 589 | |||
| 590 | for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | ||
| 591 | motions_param[motion_id] = Common::ParamPackage{ | ||
| 592 | InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])}; | ||
| 593 | } | ||
| 594 | |||
| 547 | UpdateUI(); | 595 | UpdateUI(); |
| 548 | UpdateInputDevices(); | 596 | UpdateInputDevices(); |
| 549 | ui->comboControllerType->setCurrentIndex(0); | 597 | ui->comboControllerType->setCurrentIndex(0); |
| @@ -573,6 +621,15 @@ void ConfigureInputPlayer::ClearAll() { | |||
| 573 | } | 621 | } |
| 574 | } | 622 | } |
| 575 | 623 | ||
| 624 | for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | ||
| 625 | const auto* const button = motion_map[motion_id]; | ||
| 626 | if (button == nullptr || !button->isEnabled()) { | ||
| 627 | continue; | ||
| 628 | } | ||
| 629 | |||
| 630 | motions_param[motion_id].Clear(); | ||
| 631 | } | ||
| 632 | |||
| 576 | UpdateUI(); | 633 | UpdateUI(); |
| 577 | UpdateInputDevices(); | 634 | UpdateInputDevices(); |
| 578 | } | 635 | } |
| @@ -582,6 +639,10 @@ void ConfigureInputPlayer::UpdateUI() { | |||
| 582 | button_map[button]->setText(ButtonToText(buttons_param[button])); | 639 | button_map[button]->setText(ButtonToText(buttons_param[button])); |
| 583 | } | 640 | } |
| 584 | 641 | ||
| 642 | for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | ||
| 643 | motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); | ||
| 644 | } | ||
| 645 | |||
| 585 | ui->buttonLStickMod->setText(ButtonToText(lstick_mod)); | 646 | ui->buttonLStickMod->setText(ButtonToText(lstick_mod)); |
| 586 | ui->buttonRStickMod->setText(ButtonToText(rstick_mod)); | 647 | ui->buttonRStickMod->setText(ButtonToText(rstick_mod)); |
| 587 | 648 | ||
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index a25bc3bd9..a12216c55 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h | |||
| @@ -128,11 +128,14 @@ private: | |||
| 128 | 128 | ||
| 129 | std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param; | 129 | std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param; |
| 130 | std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param; | 130 | std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param; |
| 131 | std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param; | ||
| 131 | 132 | ||
| 132 | static constexpr int ANALOG_SUB_BUTTONS_NUM = 4; | 133 | static constexpr int ANALOG_SUB_BUTTONS_NUM = 4; |
| 133 | 134 | ||
| 134 | /// Each button input is represented by a QPushButton. | 135 | /// Each button input is represented by a QPushButton. |
| 135 | std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map; | 136 | std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map; |
| 137 | /// Each motion input is represented by a QPushButton. | ||
| 138 | std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map; | ||
| 136 | /// Extra buttons for the modifiers. | 139 | /// Extra buttons for the modifiers. |
| 137 | Common::ParamPackage lstick_mod; | 140 | Common::ParamPackage lstick_mod; |
| 138 | Common::ParamPackage rstick_mod; | 141 | Common::ParamPackage rstick_mod; |
diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui index 9bc681894..b0e572f37 100644 --- a/src/yuzu/configuration/configure_input_player.ui +++ b/src/yuzu/configuration/configure_input_player.ui | |||
| @@ -2264,6 +2264,105 @@ | |||
| 2264 | </layout> | 2264 | </layout> |
| 2265 | </widget> | 2265 | </widget> |
| 2266 | </item> | 2266 | </item> |
| 2267 | |||
| 2268 | <item alignment="Qt::AlignHCenter"> | ||
| 2269 | <widget class="QGroupBox" name="buttonMotionLeftGroup"> | ||
| 2270 | <property name="title"> | ||
| 2271 | <string>Motion left</string> | ||
| 2272 | </property> | ||
| 2273 | <property name="alignment"> | ||
| 2274 | <set>Qt::AlignCenter</set> | ||
| 2275 | </property> | ||
| 2276 | <layout class="QVBoxLayout" name="buttonMotionLeftVerticalLayout"> | ||
| 2277 | <property name="spacing"> | ||
| 2278 | <number>3</number> | ||
| 2279 | </property> | ||
| 2280 | <property name="leftMargin"> | ||
| 2281 | <number>3</number> | ||
| 2282 | </property> | ||
| 2283 | <property name="topMargin"> | ||
| 2284 | <number>3</number> | ||
| 2285 | </property> | ||
| 2286 | <property name="rightMargin"> | ||
| 2287 | <number>3</number> | ||
| 2288 | </property> | ||
| 2289 | <property name="bottomMargin"> | ||
| 2290 | <number>3</number> | ||
| 2291 | </property> | ||
| 2292 | <item> | ||
| 2293 | <widget class="QPushButton" name="buttonMotionLeft"> | ||
| 2294 | <property name="minimumSize"> | ||
| 2295 | <size> | ||
| 2296 | <width>57</width> | ||
| 2297 | <height>0</height> | ||
| 2298 | </size> | ||
| 2299 | </property> | ||
| 2300 | <property name="maximumSize"> | ||
| 2301 | <size> | ||
| 2302 | <width>55</width> | ||
| 2303 | <height>16777215</height> | ||
| 2304 | </size> | ||
| 2305 | </property> | ||
| 2306 | <property name="styleSheet"> | ||
| 2307 | <string notr="true">min-width: 55px;</string> | ||
| 2308 | </property> | ||
| 2309 | <property name="text"> | ||
| 2310 | <string>Motion left</string> | ||
| 2311 | </property> | ||
| 2312 | </widget> | ||
| 2313 | </item> | ||
| 2314 | </layout> | ||
| 2315 | </widget> | ||
| 2316 | </item> | ||
| 2317 | <item alignment="Qt::AlignHCenter"> | ||
| 2318 | <widget class="QGroupBox" name="buttonMotionRightGroup"> | ||
| 2319 | <property name="title"> | ||
| 2320 | <string>Motion right</string> | ||
| 2321 | </property> | ||
| 2322 | <property name="alignment"> | ||
| 2323 | <set>Qt::AlignCenter</set> | ||
| 2324 | </property> | ||
| 2325 | <layout class="QVBoxLayout" name="buttonMotionRightVerticalLayout"> | ||
| 2326 | <property name="spacing"> | ||
| 2327 | <number>3</number> | ||
| 2328 | </property> | ||
| 2329 | <property name="leftMargin"> | ||
| 2330 | <number>3</number> | ||
| 2331 | </property> | ||
| 2332 | <property name="topMargin"> | ||
| 2333 | <number>3</number> | ||
| 2334 | </property> | ||
| 2335 | <property name="rightMargin"> | ||
| 2336 | <number>3</number> | ||
| 2337 | </property> | ||
| 2338 | <property name="bottomMargin"> | ||
| 2339 | <number>3</number> | ||
| 2340 | </property> | ||
| 2341 | <item> | ||
| 2342 | <widget class="QPushButton" name="buttonMotionRight"> | ||
| 2343 | <property name="minimumSize"> | ||
| 2344 | <size> | ||
| 2345 | <width>57</width> | ||
| 2346 | <height>0</height> | ||
| 2347 | </size> | ||
| 2348 | </property> | ||
| 2349 | <property name="maximumSize"> | ||
| 2350 | <size> | ||
| 2351 | <width>55</width> | ||
| 2352 | <height>16777215</height> | ||
| 2353 | </size> | ||
| 2354 | </property> | ||
| 2355 | <property name="styleSheet"> | ||
| 2356 | <string notr="true">min-width: 55px;</string> | ||
| 2357 | </property> | ||
| 2358 | <property name="text"> | ||
| 2359 | <string>Motion right</string> | ||
| 2360 | </property> | ||
| 2361 | </widget> | ||
| 2362 | </item> | ||
| 2363 | </layout> | ||
| 2364 | </widget> | ||
| 2365 | </item> | ||
| 2267 | </layout> | 2366 | </layout> |
| 2268 | </item> | 2367 | </item> |
| 2269 | <item> | 2368 | <item> |