diff options
| author | 2022-12-20 13:23:31 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:20 -0600 | |
| commit | ed5fa10e9729cf55205533f62a428e646aa5ed7c (patch) | |
| tree | fe1fa3882df8a26845f937dbb0a51beb7ac7acc3 /src/core | |
| parent | core: hid: Migrate ring from emulated devices to emulated controller (diff) | |
| download | yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.gz yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.xz yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.zip | |
core: hid: Enable pulling color data from controllers
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 80 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 12 | ||||
| -rw-r--r-- | src/core/hid/input_converter.cpp | 14 | ||||
| -rw-r--r-- | src/core/hid/input_converter.h | 10 |
4 files changed, 115 insertions, 1 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 128101e8c..89638cb85 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -93,6 +93,7 @@ void EmulatedController::ReloadFromSettings() { | |||
| 93 | motion_params[index] = Common::ParamPackage(player.motions[index]); | 93 | motion_params[index] = Common::ParamPackage(player.motions[index]); |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | controller.color_values = {}; | ||
| 96 | controller.colors_state.fullkey = { | 97 | controller.colors_state.fullkey = { |
| 97 | .body = GetNpadColor(player.body_color_left), | 98 | .body = GetNpadColor(player.body_color_left), |
| 98 | .button = GetNpadColor(player.button_color_left), | 99 | .button = GetNpadColor(player.button_color_left), |
| @@ -132,6 +133,11 @@ void EmulatedController::LoadDevices() { | |||
| 132 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; | 133 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; |
| 133 | trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR]; | 134 | trigger_params[RightIndex] = button_params[Settings::NativeButton::ZR]; |
| 134 | 135 | ||
| 136 | color_params[LeftIndex] = left_joycon; | ||
| 137 | color_params[RightIndex] = right_joycon; | ||
| 138 | color_params[LeftIndex].Set("color", true); | ||
| 139 | color_params[RightIndex].Set("color", true); | ||
| 140 | |||
| 135 | battery_params[LeftIndex] = left_joycon; | 141 | battery_params[LeftIndex] = left_joycon; |
| 136 | battery_params[RightIndex] = right_joycon; | 142 | battery_params[RightIndex] = right_joycon; |
| 137 | battery_params[LeftIndex].Set("battery", true); | 143 | battery_params[LeftIndex].Set("battery", true); |
| @@ -160,6 +166,7 @@ void EmulatedController::LoadDevices() { | |||
| 160 | Common::Input::CreateInputDevice); | 166 | Common::Input::CreateInputDevice); |
| 161 | std::ranges::transform(battery_params, battery_devices.begin(), | 167 | std::ranges::transform(battery_params, battery_devices.begin(), |
| 162 | Common::Input::CreateInputDevice); | 168 | Common::Input::CreateInputDevice); |
| 169 | std::ranges::transform(color_params, color_devices.begin(), Common::Input::CreateInputDevice); | ||
| 163 | camera_devices = Common::Input::CreateInputDevice(camera_params); | 170 | camera_devices = Common::Input::CreateInputDevice(camera_params); |
| 164 | ring_analog_device = Common::Input::CreateInputDevice(ring_params); | 171 | ring_analog_device = Common::Input::CreateInputDevice(ring_params); |
| 165 | nfc_devices = Common::Input::CreateInputDevice(nfc_params); | 172 | nfc_devices = Common::Input::CreateInputDevice(nfc_params); |
| @@ -324,6 +331,19 @@ void EmulatedController::ReloadInput() { | |||
| 324 | battery_devices[index]->ForceUpdate(); | 331 | battery_devices[index]->ForceUpdate(); |
| 325 | } | 332 | } |
| 326 | 333 | ||
| 334 | for (std::size_t index = 0; index < color_devices.size(); ++index) { | ||
| 335 | if (!color_devices[index]) { | ||
| 336 | continue; | ||
| 337 | } | ||
| 338 | color_devices[index]->SetCallback({ | ||
| 339 | .on_change = | ||
| 340 | [this, index](const Common::Input::CallbackStatus& callback) { | ||
| 341 | SetColors(callback, index); | ||
| 342 | }, | ||
| 343 | }); | ||
| 344 | color_devices[index]->ForceUpdate(); | ||
| 345 | } | ||
| 346 | |||
| 327 | for (std::size_t index = 0; index < motion_devices.size(); ++index) { | 347 | for (std::size_t index = 0; index < motion_devices.size(); ++index) { |
| 328 | if (!motion_devices[index]) { | 348 | if (!motion_devices[index]) { |
| 329 | continue; | 349 | continue; |
| @@ -429,6 +449,9 @@ void EmulatedController::UnloadInput() { | |||
| 429 | for (auto& battery : battery_devices) { | 449 | for (auto& battery : battery_devices) { |
| 430 | battery.reset(); | 450 | battery.reset(); |
| 431 | } | 451 | } |
| 452 | for (auto& color : color_devices) { | ||
| 453 | color.reset(); | ||
| 454 | } | ||
| 432 | for (auto& output : output_devices) { | 455 | for (auto& output : output_devices) { |
| 433 | output.reset(); | 456 | output.reset(); |
| 434 | } | 457 | } |
| @@ -458,6 +481,11 @@ void EmulatedController::EnableConfiguration() { | |||
| 458 | void EmulatedController::DisableConfiguration() { | 481 | void EmulatedController::DisableConfiguration() { |
| 459 | is_configuring = false; | 482 | is_configuring = false; |
| 460 | 483 | ||
| 484 | // Get Joycon colors before turning on the controller | ||
| 485 | for (const auto& color_device : color_devices) { | ||
| 486 | color_device->ForceUpdate(); | ||
| 487 | } | ||
| 488 | |||
| 461 | // Apply temporary npad type to the real controller | 489 | // Apply temporary npad type to the real controller |
| 462 | if (tmp_npad_type != npad_type) { | 490 | if (tmp_npad_type != npad_type) { |
| 463 | if (is_connected) { | 491 | if (is_connected) { |
| @@ -926,6 +954,58 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback | |||
| 926 | TriggerOnChange(ControllerTriggerType::Motion, true); | 954 | TriggerOnChange(ControllerTriggerType::Motion, true); |
| 927 | } | 955 | } |
| 928 | 956 | ||
| 957 | void EmulatedController::SetColors(const Common::Input::CallbackStatus& callback, | ||
| 958 | std::size_t index) { | ||
| 959 | if (index >= controller.color_values.size()) { | ||
| 960 | return; | ||
| 961 | } | ||
| 962 | std::unique_lock lock{mutex}; | ||
| 963 | controller.color_values[index] = TransformToColor(callback); | ||
| 964 | |||
| 965 | if (is_configuring) { | ||
| 966 | lock.unlock(); | ||
| 967 | TriggerOnChange(ControllerTriggerType::Color, false); | ||
| 968 | return; | ||
| 969 | } | ||
| 970 | |||
| 971 | if (controller.color_values[index].body == 0) { | ||
| 972 | return; | ||
| 973 | } | ||
| 974 | |||
| 975 | controller.colors_state.fullkey = { | ||
| 976 | .body = GetNpadColor(controller.color_values[index].body), | ||
| 977 | .button = GetNpadColor(controller.color_values[index].buttons), | ||
| 978 | }; | ||
| 979 | if (npad_type == NpadStyleIndex::ProController) { | ||
| 980 | controller.colors_state.left = { | ||
| 981 | .body = GetNpadColor(controller.color_values[index].left_grip), | ||
| 982 | .button = GetNpadColor(controller.color_values[index].buttons), | ||
| 983 | }; | ||
| 984 | controller.colors_state.right = { | ||
| 985 | .body = GetNpadColor(controller.color_values[index].right_grip), | ||
| 986 | .button = GetNpadColor(controller.color_values[index].buttons), | ||
| 987 | }; | ||
| 988 | } else { | ||
| 989 | switch (index) { | ||
| 990 | case LeftIndex: | ||
| 991 | controller.colors_state.left = { | ||
| 992 | .body = GetNpadColor(controller.color_values[index].body), | ||
| 993 | .button = GetNpadColor(controller.color_values[index].buttons), | ||
| 994 | }; | ||
| 995 | break; | ||
| 996 | case RightIndex: | ||
| 997 | controller.colors_state.right = { | ||
| 998 | .body = GetNpadColor(controller.color_values[index].body), | ||
| 999 | .button = GetNpadColor(controller.color_values[index].buttons), | ||
| 1000 | }; | ||
| 1001 | break; | ||
| 1002 | } | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | lock.unlock(); | ||
| 1006 | TriggerOnChange(ControllerTriggerType::Color, true); | ||
| 1007 | } | ||
| 1008 | |||
| 929 | void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback, | 1009 | void EmulatedController::SetBattery(const Common::Input::CallbackStatus& callback, |
| 930 | std::size_t index) { | 1010 | std::size_t index) { |
| 931 | if (index >= controller.battery_values.size()) { | 1011 | if (index >= controller.battery_values.size()) { |
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index aed331a1a..d044cc36b 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -35,6 +35,8 @@ using ControllerMotionDevices = | |||
| 35 | std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeMotion::NumMotions>; | 35 | std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeMotion::NumMotions>; |
| 36 | using TriggerDevices = | 36 | using TriggerDevices = |
| 37 | std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; | 37 | std::array<std::unique_ptr<Common::Input::InputDevice>, Settings::NativeTrigger::NumTriggers>; |
| 38 | using ColorDevices = | ||
| 39 | std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; | ||
| 38 | using BatteryDevices = | 40 | using BatteryDevices = |
| 39 | std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; | 41 | std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; |
| 40 | using CameraDevices = std::unique_ptr<Common::Input::InputDevice>; | 42 | using CameraDevices = std::unique_ptr<Common::Input::InputDevice>; |
| @@ -46,6 +48,7 @@ using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::Nu | |||
| 46 | using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; | 48 | using StickParams = std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs>; |
| 47 | using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; | 49 | using ControllerMotionParams = std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions>; |
| 48 | using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; | 50 | using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>; |
| 51 | using ColorParams = std::array<Common::ParamPackage, max_emulated_controllers>; | ||
| 49 | using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; | 52 | using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; |
| 50 | using CameraParams = Common::ParamPackage; | 53 | using CameraParams = Common::ParamPackage; |
| 51 | using RingAnalogParams = Common::ParamPackage; | 54 | using RingAnalogParams = Common::ParamPackage; |
| @@ -458,6 +461,13 @@ private: | |||
| 458 | void SetMotion(const Common::Input::CallbackStatus& callback, std::size_t index); | 461 | void SetMotion(const Common::Input::CallbackStatus& callback, std::size_t index); |
| 459 | 462 | ||
| 460 | /** | 463 | /** |
| 464 | * Updates the color status of the controller | ||
| 465 | * @param callback A CallbackStatus containing the color status | ||
| 466 | * @param index color ID of the to be updated | ||
| 467 | */ | ||
| 468 | void SetColors(const Common::Input::CallbackStatus& callback, std::size_t index); | ||
| 469 | |||
| 470 | /** | ||
| 461 | * Updates the battery status of the controller | 471 | * Updates the battery status of the controller |
| 462 | * @param callback A CallbackStatus containing the battery status | 472 | * @param callback A CallbackStatus containing the battery status |
| 463 | * @param index battery ID of the to be updated | 473 | * @param index battery ID of the to be updated |
| @@ -515,6 +525,7 @@ private: | |||
| 515 | ControllerMotionParams motion_params; | 525 | ControllerMotionParams motion_params; |
| 516 | TriggerParams trigger_params; | 526 | TriggerParams trigger_params; |
| 517 | BatteryParams battery_params; | 527 | BatteryParams battery_params; |
| 528 | ColorParams color_params; | ||
| 518 | CameraParams camera_params; | 529 | CameraParams camera_params; |
| 519 | RingAnalogParams ring_params; | 530 | RingAnalogParams ring_params; |
| 520 | NfcParams nfc_params; | 531 | NfcParams nfc_params; |
| @@ -525,6 +536,7 @@ private: | |||
| 525 | ControllerMotionDevices motion_devices; | 536 | ControllerMotionDevices motion_devices; |
| 526 | TriggerDevices trigger_devices; | 537 | TriggerDevices trigger_devices; |
| 527 | BatteryDevices battery_devices; | 538 | BatteryDevices battery_devices; |
| 539 | ColorDevices color_devices; | ||
| 528 | CameraDevices camera_devices; | 540 | CameraDevices camera_devices; |
| 529 | RingAnalogDevice ring_analog_device; | 541 | RingAnalogDevice ring_analog_device; |
| 530 | NfcDevices nfc_devices; | 542 | NfcDevices nfc_devices; |
diff --git a/src/core/hid/input_converter.cpp b/src/core/hid/input_converter.cpp index 502692875..d7e253044 100644 --- a/src/core/hid/input_converter.cpp +++ b/src/core/hid/input_converter.cpp | |||
| @@ -304,6 +304,20 @@ Common::Input::NfcStatus TransformToNfc(const Common::Input::CallbackStatus& cal | |||
| 304 | return nfc; | 304 | return nfc; |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | Common::Input::BodyColorStatus TransformToColor(const Common::Input::CallbackStatus& callback) { | ||
| 308 | Common::Input::BodyColorStatus color{}; | ||
| 309 | switch (callback.type) { | ||
| 310 | case Common::Input::InputType::Color: | ||
| 311 | color = callback.color_status; | ||
| 312 | break; | ||
| 313 | default: | ||
| 314 | LOG_ERROR(Input, "Conversion from type {} to color not implemented", callback.type); | ||
| 315 | break; | ||
| 316 | } | ||
| 317 | |||
| 318 | return color; | ||
| 319 | } | ||
| 320 | |||
| 307 | void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value) { | 321 | void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value) { |
| 308 | const auto& properties = analog.properties; | 322 | const auto& properties = analog.properties; |
| 309 | float& raw_value = analog.raw_value; | 323 | float& raw_value = analog.raw_value; |
diff --git a/src/core/hid/input_converter.h b/src/core/hid/input_converter.h index b7eb6e660..c51c03e57 100644 --- a/src/core/hid/input_converter.h +++ b/src/core/hid/input_converter.h | |||
| @@ -88,11 +88,19 @@ Common::Input::CameraStatus TransformToCamera(const Common::Input::CallbackStatu | |||
| 88 | * Converts raw input data into a valid nfc status. | 88 | * Converts raw input data into a valid nfc status. |
| 89 | * | 89 | * |
| 90 | * @param callback Supported callbacks: Nfc. | 90 | * @param callback Supported callbacks: Nfc. |
| 91 | * @return A valid CameraObject object. | 91 | * @return A valid data tag vector. |
| 92 | */ | 92 | */ |
| 93 | Common::Input::NfcStatus TransformToNfc(const Common::Input::CallbackStatus& callback); | 93 | Common::Input::NfcStatus TransformToNfc(const Common::Input::CallbackStatus& callback); |
| 94 | 94 | ||
| 95 | /** | 95 | /** |
| 96 | * Converts raw input data into a valid color status. | ||
| 97 | * | ||
| 98 | * @param callback Supported callbacks: Color. | ||
| 99 | * @return A valid Color object. | ||
| 100 | */ | ||
| 101 | Common::Input::BodyColorStatus TransformToColor(const Common::Input::CallbackStatus& callback); | ||
| 102 | |||
| 103 | /** | ||
| 96 | * Converts raw analog data into a valid analog value | 104 | * Converts raw analog data into a valid analog value |
| 97 | * @param analog An analog object containing raw data and properties | 105 | * @param analog An analog object containing raw data and properties |
| 98 | * @param clamp_value determines if the value needs to be clamped between -1.0f and 1.0f. | 106 | * @param clamp_value determines if the value needs to be clamped between -1.0f and 1.0f. |