diff options
| author | 2022-12-20 13:09:10 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:20 -0600 | |
| commit | a4074001fe2e8ed72c87093f57ec972815661b81 (patch) | |
| tree | 145ff4c2896098d069cb2b08d175ed8e4c906e83 /src/core/hid/emulated_controller.cpp | |
| parent | yuzu: Update controller colors and button names (diff) | |
| download | yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.gz yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.xz yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.zip | |
core: hid: Migrate ring from emulated devices to emulated controller
Diffstat (limited to 'src/core/hid/emulated_controller.cpp')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 7a01f3f4c..128101e8c 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -139,6 +139,7 @@ void EmulatedController::LoadDevices() { | |||
| 139 | 139 | ||
| 140 | camera_params = Common::ParamPackage{"engine:camera,camera:1"}; | 140 | camera_params = Common::ParamPackage{"engine:camera,camera:1"}; |
| 141 | nfc_params = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"}; | 141 | nfc_params = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"}; |
| 142 | ring_params = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"}; | ||
| 142 | 143 | ||
| 143 | output_params[LeftIndex] = left_joycon; | 144 | output_params[LeftIndex] = left_joycon; |
| 144 | output_params[RightIndex] = right_joycon; | 145 | output_params[RightIndex] = right_joycon; |
| @@ -160,6 +161,7 @@ void EmulatedController::LoadDevices() { | |||
| 160 | std::ranges::transform(battery_params, battery_devices.begin(), | 161 | std::ranges::transform(battery_params, battery_devices.begin(), |
| 161 | Common::Input::CreateInputDevice); | 162 | Common::Input::CreateInputDevice); |
| 162 | camera_devices = Common::Input::CreateInputDevice(camera_params); | 163 | camera_devices = Common::Input::CreateInputDevice(camera_params); |
| 164 | ring_analog_device = Common::Input::CreateInputDevice(ring_params); | ||
| 163 | nfc_devices = Common::Input::CreateInputDevice(nfc_params); | 165 | nfc_devices = Common::Input::CreateInputDevice(nfc_params); |
| 164 | std::ranges::transform(output_params, output_devices.begin(), | 166 | std::ranges::transform(output_params, output_devices.begin(), |
| 165 | Common::Input::CreateOutputDevice); | 167 | Common::Input::CreateOutputDevice); |
| @@ -343,6 +345,13 @@ void EmulatedController::ReloadInput() { | |||
| 343 | camera_devices->ForceUpdate(); | 345 | camera_devices->ForceUpdate(); |
| 344 | } | 346 | } |
| 345 | 347 | ||
| 348 | if (ring_analog_device) { | ||
| 349 | ring_analog_device->SetCallback({ | ||
| 350 | .on_change = | ||
| 351 | [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); }, | ||
| 352 | }); | ||
| 353 | } | ||
| 354 | |||
| 346 | if (nfc_devices) { | 355 | if (nfc_devices) { |
| 347 | if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) { | 356 | if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) { |
| 348 | nfc_devices->SetCallback({ | 357 | nfc_devices->SetCallback({ |
| @@ -436,6 +445,7 @@ void EmulatedController::UnloadInput() { | |||
| 436 | stick.reset(); | 445 | stick.reset(); |
| 437 | } | 446 | } |
| 438 | camera_devices.reset(); | 447 | camera_devices.reset(); |
| 448 | ring_analog_device.reset(); | ||
| 439 | nfc_devices.reset(); | 449 | nfc_devices.reset(); |
| 440 | } | 450 | } |
| 441 | 451 | ||
| @@ -501,6 +511,7 @@ void EmulatedController::SaveCurrentConfig() { | |||
| 501 | for (std::size_t index = 0; index < player.motions.size(); ++index) { | 511 | for (std::size_t index = 0; index < player.motions.size(); ++index) { |
| 502 | player.motions[index] = motion_params[index].Serialize(); | 512 | player.motions[index] = motion_params[index].Serialize(); |
| 503 | } | 513 | } |
| 514 | Settings::values.ringcon_analogs = ring_params.Serialize(); | ||
| 504 | } | 515 | } |
| 505 | 516 | ||
| 506 | void EmulatedController::RestoreConfig() { | 517 | void EmulatedController::RestoreConfig() { |
| @@ -1005,6 +1016,24 @@ void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback | |||
| 1005 | TriggerOnChange(ControllerTriggerType::IrSensor, true); | 1016 | TriggerOnChange(ControllerTriggerType::IrSensor, true); |
| 1006 | } | 1017 | } |
| 1007 | 1018 | ||
| 1019 | void EmulatedController::SetRingAnalog(const Common::Input::CallbackStatus& callback) { | ||
| 1020 | std::unique_lock lock{mutex}; | ||
| 1021 | const auto force_value = TransformToStick(callback); | ||
| 1022 | |||
| 1023 | controller.ring_analog_value = force_value.x; | ||
| 1024 | |||
| 1025 | if (is_configuring) { | ||
| 1026 | lock.unlock(); | ||
| 1027 | TriggerOnChange(ControllerTriggerType::RingController, false); | ||
| 1028 | return; | ||
| 1029 | } | ||
| 1030 | |||
| 1031 | controller.ring_analog_state.force = force_value.x.value; | ||
| 1032 | |||
| 1033 | lock.unlock(); | ||
| 1034 | TriggerOnChange(ControllerTriggerType::RingController, true); | ||
| 1035 | } | ||
| 1036 | |||
| 1008 | void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) { | 1037 | void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) { |
| 1009 | std::unique_lock lock{mutex}; | 1038 | std::unique_lock lock{mutex}; |
| 1010 | controller.nfc_values = TransformToNfc(callback); | 1039 | controller.nfc_values = TransformToNfc(callback); |
| @@ -1104,6 +1133,15 @@ bool EmulatedController::SetCameraFormat( | |||
| 1104 | camera_format)) == Common::Input::CameraError::None; | 1133 | camera_format)) == Common::Input::CameraError::None; |
| 1105 | } | 1134 | } |
| 1106 | 1135 | ||
| 1136 | Common::ParamPackage EmulatedController::GetRingParam() const { | ||
| 1137 | return ring_params; | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | void EmulatedController::SetRingParam(Common::ParamPackage param) { | ||
| 1141 | ring_params = std::move(param); | ||
| 1142 | ReloadInput(); | ||
| 1143 | } | ||
| 1144 | |||
| 1107 | bool EmulatedController::HasNfc() const { | 1145 | bool EmulatedController::HasNfc() const { |
| 1108 | const auto& nfc_output_device = output_devices[3]; | 1146 | const auto& nfc_output_device = output_devices[3]; |
| 1109 | 1147 | ||
| @@ -1395,6 +1433,10 @@ CameraValues EmulatedController::GetCameraValues() const { | |||
| 1395 | return controller.camera_values; | 1433 | return controller.camera_values; |
| 1396 | } | 1434 | } |
| 1397 | 1435 | ||
| 1436 | RingAnalogValue EmulatedController::GetRingSensorValues() const { | ||
| 1437 | return controller.ring_analog_value; | ||
| 1438 | } | ||
| 1439 | |||
| 1398 | HomeButtonState EmulatedController::GetHomeButtons() const { | 1440 | HomeButtonState EmulatedController::GetHomeButtons() const { |
| 1399 | std::scoped_lock lock{mutex}; | 1441 | std::scoped_lock lock{mutex}; |
| 1400 | if (is_configuring) { | 1442 | if (is_configuring) { |
| @@ -1478,6 +1520,10 @@ const CameraState& EmulatedController::GetCamera() const { | |||
| 1478 | return controller.camera_state; | 1520 | return controller.camera_state; |
| 1479 | } | 1521 | } |
| 1480 | 1522 | ||
| 1523 | RingSensorForce EmulatedController::GetRingSensorForce() const { | ||
| 1524 | return controller.ring_analog_state; | ||
| 1525 | } | ||
| 1526 | |||
| 1481 | const NfcState& EmulatedController::GetNfc() const { | 1527 | const NfcState& EmulatedController::GetNfc() const { |
| 1482 | std::scoped_lock lock{mutex}; | 1528 | std::scoped_lock lock{mutex}; |
| 1483 | return controller.nfc_state; | 1529 | return controller.nfc_state; |