diff options
| author | 2022-12-20 13:23:31 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:20 -0600 | |
| commit | ed5fa10e9729cf55205533f62a428e646aa5ed7c (patch) | |
| tree | fe1fa3882df8a26845f937dbb0a51beb7ac7acc3 /src/input_common/input_poller.cpp | |
| 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/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
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 | } |