diff options
Diffstat (limited to 'src/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 134 |
1 files changed, 129 insertions, 5 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 7f3c08597..75705b67e 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | // Refer to the license.txt file included | ||
| 4 | 3 | ||
| 5 | #include "common/common_types.h" | 4 | #include "common/common_types.h" |
| 6 | #include "common/input.h" | 5 | #include "common/input.h" |
| @@ -470,7 +469,7 @@ public: | |||
| 470 | } | 469 | } |
| 471 | 470 | ||
| 472 | Common::Input::BatteryStatus GetStatus() const { | 471 | Common::Input::BatteryStatus GetStatus() const { |
| 473 | return static_cast<Common::Input::BatteryLevel>(input_engine->GetBattery(identifier)); | 472 | return input_engine->GetBattery(identifier); |
| 474 | } | 473 | } |
| 475 | 474 | ||
| 476 | void ForceUpdate() override { | 475 | void ForceUpdate() override { |
| @@ -665,6 +664,88 @@ private: | |||
| 665 | InputEngine* input_engine; | 664 | InputEngine* input_engine; |
| 666 | }; | 665 | }; |
| 667 | 666 | ||
| 667 | class InputFromCamera final : public Common::Input::InputDevice { | ||
| 668 | public: | ||
| 669 | explicit InputFromCamera(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 670 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 671 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 672 | const InputIdentifier input_identifier{ | ||
| 673 | .identifier = identifier, | ||
| 674 | .type = EngineInputType::Camera, | ||
| 675 | .index = 0, | ||
| 676 | .callback = engine_callback, | ||
| 677 | }; | ||
| 678 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 679 | } | ||
| 680 | |||
| 681 | ~InputFromCamera() override { | ||
| 682 | input_engine->DeleteCallback(callback_key); | ||
| 683 | } | ||
| 684 | |||
| 685 | Common::Input::CameraStatus GetStatus() const { | ||
| 686 | return input_engine->GetCamera(identifier); | ||
| 687 | } | ||
| 688 | |||
| 689 | void ForceUpdate() override { | ||
| 690 | OnChange(); | ||
| 691 | } | ||
| 692 | |||
| 693 | void OnChange() { | ||
| 694 | const Common::Input::CallbackStatus status{ | ||
| 695 | .type = Common::Input::InputType::IrSensor, | ||
| 696 | .camera_status = GetStatus(), | ||
| 697 | }; | ||
| 698 | |||
| 699 | TriggerOnChange(status); | ||
| 700 | } | ||
| 701 | |||
| 702 | private: | ||
| 703 | const PadIdentifier identifier; | ||
| 704 | int callback_key; | ||
| 705 | InputEngine* input_engine; | ||
| 706 | }; | ||
| 707 | |||
| 708 | class InputFromNfc final : public Common::Input::InputDevice { | ||
| 709 | public: | ||
| 710 | explicit InputFromNfc(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 711 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 712 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 713 | const InputIdentifier input_identifier{ | ||
| 714 | .identifier = identifier, | ||
| 715 | .type = EngineInputType::Nfc, | ||
| 716 | .index = 0, | ||
| 717 | .callback = engine_callback, | ||
| 718 | }; | ||
| 719 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 720 | } | ||
| 721 | |||
| 722 | ~InputFromNfc() override { | ||
| 723 | input_engine->DeleteCallback(callback_key); | ||
| 724 | } | ||
| 725 | |||
| 726 | Common::Input::NfcStatus GetStatus() const { | ||
| 727 | return input_engine->GetNfc(identifier); | ||
| 728 | } | ||
| 729 | |||
| 730 | void ForceUpdate() override { | ||
| 731 | OnChange(); | ||
| 732 | } | ||
| 733 | |||
| 734 | void OnChange() { | ||
| 735 | const Common::Input::CallbackStatus status{ | ||
| 736 | .type = Common::Input::InputType::Nfc, | ||
| 737 | .nfc_status = GetStatus(), | ||
| 738 | }; | ||
| 739 | |||
| 740 | TriggerOnChange(status); | ||
| 741 | } | ||
| 742 | |||
| 743 | private: | ||
| 744 | const PadIdentifier identifier; | ||
| 745 | int callback_key; | ||
| 746 | InputEngine* input_engine; | ||
| 747 | }; | ||
| 748 | |||
| 668 | class OutputFromIdentifier final : public Common::Input::OutputDevice { | 749 | class OutputFromIdentifier final : public Common::Input::OutputDevice { |
| 669 | public: | 750 | public: |
| 670 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) | 751 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) |
| @@ -683,6 +764,18 @@ public: | |||
| 683 | return input_engine->SetPollingMode(identifier, polling_mode); | 764 | return input_engine->SetPollingMode(identifier, polling_mode); |
| 684 | } | 765 | } |
| 685 | 766 | ||
| 767 | Common::Input::CameraError SetCameraFormat(Common::Input::CameraFormat camera_format) override { | ||
| 768 | return input_engine->SetCameraFormat(identifier, camera_format); | ||
| 769 | } | ||
| 770 | |||
| 771 | Common::Input::NfcState SupportsNfc() const override { | ||
| 772 | return input_engine->SupportsNfc(identifier); | ||
| 773 | } | ||
| 774 | |||
| 775 | Common::Input::NfcState WriteNfcData(const std::vector<u8>& data) override { | ||
| 776 | return input_engine->WriteNfcData(identifier, data); | ||
| 777 | } | ||
| 778 | |||
| 686 | private: | 779 | private: |
| 687 | const PadIdentifier identifier; | 780 | const PadIdentifier identifier; |
| 688 | InputEngine* input_engine; | 781 | InputEngine* input_engine; |
| @@ -733,7 +826,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice( | |||
| 733 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice( | 826 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice( |
| 734 | const Common::ParamPackage& params) { | 827 | const Common::ParamPackage& params) { |
| 735 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); | 828 | const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); |
| 736 | const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); | 829 | const auto range = std::clamp(params.Get("range", 0.95f), 0.25f, 1.50f); |
| 737 | const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); | 830 | const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); |
| 738 | const PadIdentifier identifier = { | 831 | const PadIdentifier identifier = { |
| 739 | .guid = Common::UUID{params.Get("guid", "")}, | 832 | .guid = Common::UUID{params.Get("guid", "")}, |
| @@ -780,6 +873,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 780 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 873 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), |
| 781 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), | 874 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), |
| 782 | .inverted = params.Get("invert", "+") == "-", | 875 | .inverted = params.Get("invert", "+") == "-", |
| 876 | .toggle = static_cast<bool>(params.Get("toggle", false)), | ||
| 783 | }; | 877 | }; |
| 784 | input_engine->PreSetController(identifier); | 878 | input_engine->PreSetController(identifier); |
| 785 | input_engine->PreSetAxis(identifier, axis); | 879 | input_engine->PreSetAxis(identifier, axis); |
| @@ -921,6 +1015,30 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | |||
| 921 | properties_y, properties_z, input_engine.get()); | 1015 | properties_y, properties_z, input_engine.get()); |
| 922 | } | 1016 | } |
| 923 | 1017 | ||
| 1018 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateCameraDevice( | ||
| 1019 | const Common::ParamPackage& params) { | ||
| 1020 | const PadIdentifier identifier = { | ||
| 1021 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1022 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1023 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1024 | }; | ||
| 1025 | |||
| 1026 | input_engine->PreSetController(identifier); | ||
| 1027 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateNfcDevice( | ||
| 1031 | const Common::ParamPackage& params) { | ||
| 1032 | const PadIdentifier identifier = { | ||
| 1033 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1034 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1035 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1036 | }; | ||
| 1037 | |||
| 1038 | input_engine->PreSetController(identifier); | ||
| 1039 | return std::make_unique<InputFromNfc>(identifier, input_engine.get()); | ||
| 1040 | } | ||
| 1041 | |||
| 924 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) | 1042 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 925 | : input_engine(std::move(input_engine_)) {} | 1043 | : input_engine(std::move(input_engine_)) {} |
| 926 | 1044 | ||
| @@ -929,6 +1047,12 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 929 | if (params.Has("battery")) { | 1047 | if (params.Has("battery")) { |
| 930 | return CreateBatteryDevice(params); | 1048 | return CreateBatteryDevice(params); |
| 931 | } | 1049 | } |
| 1050 | if (params.Has("camera")) { | ||
| 1051 | return CreateCameraDevice(params); | ||
| 1052 | } | ||
| 1053 | if (params.Has("nfc")) { | ||
| 1054 | return CreateNfcDevice(params); | ||
| 1055 | } | ||
| 932 | if (params.Has("button") && params.Has("axis")) { | 1056 | if (params.Has("button") && params.Has("axis")) { |
| 933 | return CreateTriggerDevice(params); | 1057 | return CreateTriggerDevice(params); |
| 934 | } | 1058 | } |