diff options
| author | 2022-12-20 13:23:31 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:20 -0600 | |
| commit | ed5fa10e9729cf55205533f62a428e646aa5ed7c (patch) | |
| tree | fe1fa3882df8a26845f937dbb0a51beb7ac7acc3 /src | |
| 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')
| -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 | ||||
| -rw-r--r-- | src/input_common/drivers/joycon.cpp | 11 | ||||
| -rw-r--r-- | src/input_common/input_engine.cpp | 37 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 6 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 67 | ||||
| -rw-r--r-- | src/input_common/input_poller.h | 11 |
9 files changed, 246 insertions, 2 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. |
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp index 1fca11d34..c6f78c989 100644 --- a/src/input_common/drivers/joycon.cpp +++ b/src/input_common/drivers/joycon.cpp | |||
| @@ -335,7 +335,16 @@ void Joycons::OnBatteryUpdate(std::size_t port, Joycon::ControllerType type, | |||
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | void Joycons::OnColorUpdate(std::size_t port, Joycon::ControllerType type, | 337 | void Joycons::OnColorUpdate(std::size_t port, Joycon::ControllerType type, |
| 338 | const Joycon::Color& value) {} | 338 | const Joycon::Color& value) { |
| 339 | const auto identifier = GetIdentifier(port, type); | ||
| 340 | Common::Input::BodyColorStatus color{ | ||
| 341 | .body = value.body, | ||
| 342 | .buttons = value.buttons, | ||
| 343 | .left_grip = value.left_grip, | ||
| 344 | .right_grip = value.right_grip, | ||
| 345 | }; | ||
| 346 | SetColor(identifier, color); | ||
| 347 | } | ||
| 339 | 348 | ||
| 340 | void Joycons::OnButtonUpdate(std::size_t port, Joycon::ControllerType type, int id, bool value) { | 349 | void Joycons::OnButtonUpdate(std::size_t port, Joycon::ControllerType type, int id, bool value) { |
| 341 | const auto identifier = GetIdentifier(port, type); | 350 | const auto identifier = GetIdentifier(port, type); |
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 61cfd0911..91aa96aa7 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -79,6 +79,17 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::Bat | |||
| 79 | TriggerOnBatteryChange(identifier, value); | 79 | TriggerOnBatteryChange(identifier, value); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | void InputEngine::SetColor(const PadIdentifier& identifier, Common::Input::BodyColorStatus value) { | ||
| 83 | { | ||
| 84 | std::scoped_lock lock{mutex}; | ||
| 85 | ControllerData& controller = controller_list.at(identifier); | ||
| 86 | if (!configuring) { | ||
| 87 | controller.color = value; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | TriggerOnColorChange(identifier, value); | ||
| 91 | } | ||
| 92 | |||
| 82 | void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) { | 93 | void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) { |
| 83 | { | 94 | { |
| 84 | std::scoped_lock lock{mutex}; | 95 | std::scoped_lock lock{mutex}; |
| @@ -176,6 +187,18 @@ Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identif | |||
| 176 | return controller.battery; | 187 | return controller.battery; |
| 177 | } | 188 | } |
| 178 | 189 | ||
| 190 | Common::Input::BodyColorStatus InputEngine::GetColor(const PadIdentifier& identifier) const { | ||
| 191 | std::scoped_lock lock{mutex}; | ||
| 192 | const auto controller_iter = controller_list.find(identifier); | ||
| 193 | if (controller_iter == controller_list.cend()) { | ||
| 194 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), | ||
| 195 | identifier.pad, identifier.port); | ||
| 196 | return {}; | ||
| 197 | } | ||
| 198 | const ControllerData& controller = controller_iter->second; | ||
| 199 | return controller.color; | ||
| 200 | } | ||
| 201 | |||
| 179 | BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { | 202 | BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { |
| 180 | std::scoped_lock lock{mutex}; | 203 | std::scoped_lock lock{mutex}; |
| 181 | const auto controller_iter = controller_list.find(identifier); | 204 | const auto controller_iter = controller_list.find(identifier); |
| @@ -328,6 +351,20 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, | |||
| 328 | } | 351 | } |
| 329 | } | 352 | } |
| 330 | 353 | ||
| 354 | void InputEngine::TriggerOnColorChange(const PadIdentifier& identifier, | ||
| 355 | [[maybe_unused]] Common::Input::BodyColorStatus value) { | ||
| 356 | std::scoped_lock lock{mutex_callback}; | ||
| 357 | for (const auto& poller_pair : callback_list) { | ||
| 358 | const InputIdentifier& poller = poller_pair.second; | ||
| 359 | if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Color, 0)) { | ||
| 360 | continue; | ||
| 361 | } | ||
| 362 | if (poller.callback.on_change) { | ||
| 363 | poller.callback.on_change(); | ||
| 364 | } | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 331 | void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, | 368 | void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, |
| 332 | const BasicMotion& value) { | 369 | const BasicMotion& value) { |
| 333 | std::scoped_lock lock{mutex_callback}; | 370 | std::scoped_lock lock{mutex_callback}; |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 6cbcf5207..6301c5719 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -40,6 +40,7 @@ enum class EngineInputType { | |||
| 40 | Battery, | 40 | Battery, |
| 41 | Button, | 41 | Button, |
| 42 | Camera, | 42 | Camera, |
| 43 | Color, | ||
| 43 | HatButton, | 44 | HatButton, |
| 44 | Motion, | 45 | Motion, |
| 45 | Nfc, | 46 | Nfc, |
| @@ -199,6 +200,7 @@ public: | |||
| 199 | bool GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const; | 200 | bool GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const; |
| 200 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; | 201 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; |
| 201 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; | 202 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; |
| 203 | Common::Input::BodyColorStatus GetColor(const PadIdentifier& identifier) const; | ||
| 202 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; | 204 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; |
| 203 | Common::Input::CameraStatus GetCamera(const PadIdentifier& identifier) const; | 205 | Common::Input::CameraStatus GetCamera(const PadIdentifier& identifier) const; |
| 204 | Common::Input::NfcStatus GetNfc(const PadIdentifier& identifier) const; | 206 | Common::Input::NfcStatus GetNfc(const PadIdentifier& identifier) const; |
| @@ -212,6 +214,7 @@ protected: | |||
| 212 | void SetHatButton(const PadIdentifier& identifier, int button, u8 value); | 214 | void SetHatButton(const PadIdentifier& identifier, int button, u8 value); |
| 213 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); | 215 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); |
| 214 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); | 216 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 217 | void SetColor(const PadIdentifier& identifier, Common::Input::BodyColorStatus value); | ||
| 215 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); | 218 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); |
| 216 | void SetCamera(const PadIdentifier& identifier, const Common::Input::CameraStatus& value); | 219 | void SetCamera(const PadIdentifier& identifier, const Common::Input::CameraStatus& value); |
| 217 | void SetNfc(const PadIdentifier& identifier, const Common::Input::NfcStatus& value); | 220 | void SetNfc(const PadIdentifier& identifier, const Common::Input::NfcStatus& value); |
| @@ -227,6 +230,7 @@ private: | |||
| 227 | std::unordered_map<int, float> axes; | 230 | std::unordered_map<int, float> axes; |
| 228 | std::unordered_map<int, BasicMotion> motions; | 231 | std::unordered_map<int, BasicMotion> motions; |
| 229 | Common::Input::BatteryLevel battery{}; | 232 | Common::Input::BatteryLevel battery{}; |
| 233 | Common::Input::BodyColorStatus color{}; | ||
| 230 | Common::Input::CameraStatus camera{}; | 234 | Common::Input::CameraStatus camera{}; |
| 231 | Common::Input::NfcStatus nfc{}; | 235 | Common::Input::NfcStatus nfc{}; |
| 232 | }; | 236 | }; |
| @@ -235,6 +239,8 @@ private: | |||
| 235 | void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); | 239 | void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); |
| 236 | void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value); | 240 | void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value); |
| 237 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); | 241 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 242 | void TriggerOnColorChange(const PadIdentifier& identifier, | ||
| 243 | Common::Input::BodyColorStatus value); | ||
| 238 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, | 244 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, |
| 239 | const BasicMotion& value); | 245 | const BasicMotion& value); |
| 240 | void TriggerOnCameraChange(const PadIdentifier& identifier, | 246 | void TriggerOnCameraChange(const PadIdentifier& identifier, |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index fb8be42e2..368ffbdd5 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -498,6 +498,58 @@ private: | |||
| 498 | InputEngine* input_engine; | 498 | InputEngine* input_engine; |
| 499 | }; | 499 | }; |
| 500 | 500 | ||
| 501 | class InputFromColor final : public Common::Input::InputDevice { | ||
| 502 | public: | ||
| 503 | explicit InputFromColor(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 504 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 505 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 506 | const InputIdentifier input_identifier{ | ||
| 507 | .identifier = identifier, | ||
| 508 | .type = EngineInputType::Color, | ||
| 509 | .index = 0, | ||
| 510 | .callback = engine_callback, | ||
| 511 | }; | ||
| 512 | last_color_value = {}; | ||
| 513 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 514 | } | ||
| 515 | |||
| 516 | ~InputFromColor() override { | ||
| 517 | input_engine->DeleteCallback(callback_key); | ||
| 518 | } | ||
| 519 | |||
| 520 | Common::Input::BodyColorStatus GetStatus() const { | ||
| 521 | return input_engine->GetColor(identifier); | ||
| 522 | } | ||
| 523 | |||
| 524 | void ForceUpdate() override { | ||
| 525 | const Common::Input::CallbackStatus status{ | ||
| 526 | .type = Common::Input::InputType::Color, | ||
| 527 | .color_status = GetStatus(), | ||
| 528 | }; | ||
| 529 | |||
| 530 | last_color_value = status.color_status; | ||
| 531 | TriggerOnChange(status); | ||
| 532 | } | ||
| 533 | |||
| 534 | void OnChange() { | ||
| 535 | const Common::Input::CallbackStatus status{ | ||
| 536 | .type = Common::Input::InputType::Color, | ||
| 537 | .color_status = GetStatus(), | ||
| 538 | }; | ||
| 539 | |||
| 540 | if (status.color_status.body != last_color_value.body) { | ||
| 541 | last_color_value = status.color_status; | ||
| 542 | TriggerOnChange(status); | ||
| 543 | } | ||
| 544 | } | ||
| 545 | |||
| 546 | private: | ||
| 547 | const PadIdentifier identifier; | ||
| 548 | int callback_key; | ||
| 549 | Common::Input::BodyColorStatus last_color_value; | ||
| 550 | InputEngine* input_engine; | ||
| 551 | }; | ||
| 552 | |||
| 501 | class InputFromMotion final : public Common::Input::InputDevice { | 553 | class InputFromMotion final : public Common::Input::InputDevice { |
| 502 | public: | 554 | public: |
| 503 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, | 555 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, |
| @@ -966,6 +1018,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice( | |||
| 966 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); | 1018 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); |
| 967 | } | 1019 | } |
| 968 | 1020 | ||
| 1021 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice( | ||
| 1022 | const Common::ParamPackage& params) { | ||
| 1023 | const PadIdentifier identifier = { | ||
| 1024 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1025 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1026 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1027 | }; | ||
| 1028 | |||
| 1029 | input_engine->PreSetController(identifier); | ||
| 1030 | return std::make_unique<InputFromColor>(identifier, input_engine.get()); | ||
| 1031 | } | ||
| 1032 | |||
| 969 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | 1033 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( |
| 970 | Common::ParamPackage params) { | 1034 | Common::ParamPackage params) { |
| 971 | const PadIdentifier identifier = { | 1035 | const PadIdentifier identifier = { |
| @@ -1053,6 +1117,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 1053 | if (params.Has("battery")) { | 1117 | if (params.Has("battery")) { |
| 1054 | return CreateBatteryDevice(params); | 1118 | return CreateBatteryDevice(params); |
| 1055 | } | 1119 | } |
| 1120 | if (params.Has("color")) { | ||
| 1121 | return CreateColorDevice(params); | ||
| 1122 | } | ||
| 1056 | if (params.Has("camera")) { | 1123 | if (params.Has("camera")) { |
| 1057 | return CreateCameraDevice(params); | 1124 | return CreateCameraDevice(params); |
| 1058 | } | 1125 | } |
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h index d7db13ce4..e097e254c 100644 --- a/src/input_common/input_poller.h +++ b/src/input_common/input_poller.h | |||
| @@ -191,6 +191,17 @@ private: | |||
| 191 | const Common::ParamPackage& params); | 191 | const Common::ParamPackage& params); |
| 192 | 192 | ||
| 193 | /** | 193 | /** |
| 194 | * Creates a color device from the parameters given. | ||
| 195 | * @param params contains parameters for creating the device: | ||
| 196 | * - "guid": text string for identifying controllers | ||
| 197 | * - "port": port of the connected device | ||
| 198 | * - "pad": slot of the connected controller | ||
| 199 | * @returns a unique input device with the parameters specified | ||
| 200 | */ | ||
| 201 | std::unique_ptr<Common::Input::InputDevice> CreateColorDevice( | ||
| 202 | const Common::ParamPackage& params); | ||
| 203 | |||
| 204 | /** | ||
| 194 | * Creates a motion device from the parameters given. | 205 | * Creates a motion device from the parameters given. |
| 195 | * @param params contains parameters for creating the device: | 206 | * @param params contains parameters for creating the device: |
| 196 | * - "axis_x": the controller horizontal axis id to bind with the input | 207 | * - "axis_x": the controller horizontal axis id to bind with the input |