diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/input_poller.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index ffb9b945e..75705b67e 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -705,6 +705,47 @@ private: | |||
| 705 | InputEngine* input_engine; | 705 | InputEngine* input_engine; |
| 706 | }; | 706 | }; |
| 707 | 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 | |||
| 708 | class OutputFromIdentifier final : public Common::Input::OutputDevice { | 749 | class OutputFromIdentifier final : public Common::Input::OutputDevice { |
| 709 | public: | 750 | public: |
| 710 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) | 751 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) |
| @@ -727,6 +768,14 @@ public: | |||
| 727 | return input_engine->SetCameraFormat(identifier, camera_format); | 768 | return input_engine->SetCameraFormat(identifier, camera_format); |
| 728 | } | 769 | } |
| 729 | 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 | |||
| 730 | private: | 779 | private: |
| 731 | const PadIdentifier identifier; | 780 | const PadIdentifier identifier; |
| 732 | InputEngine* input_engine; | 781 | InputEngine* input_engine; |
| @@ -978,6 +1027,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateCameraDevice( | |||
| 978 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); | 1027 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); |
| 979 | } | 1028 | } |
| 980 | 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 | |||
| 981 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) | 1042 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 982 | : input_engine(std::move(input_engine_)) {} | 1043 | : input_engine(std::move(input_engine_)) {} |
| 983 | 1044 | ||
| @@ -989,6 +1050,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 989 | if (params.Has("camera")) { | 1050 | if (params.Has("camera")) { |
| 990 | return CreateCameraDevice(params); | 1051 | return CreateCameraDevice(params); |
| 991 | } | 1052 | } |
| 1053 | if (params.Has("nfc")) { | ||
| 1054 | return CreateNfcDevice(params); | ||
| 1055 | } | ||
| 992 | if (params.Has("button") && params.Has("axis")) { | 1056 | if (params.Has("button") && params.Has("axis")) { |
| 993 | return CreateTriggerDevice(params); | 1057 | return CreateTriggerDevice(params); |
| 994 | } | 1058 | } |