diff options
Diffstat (limited to 'src/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index ffb9b945e..ccc3076ca 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -691,9 +691,56 @@ public: | |||
| 691 | } | 691 | } |
| 692 | 692 | ||
| 693 | void OnChange() { | 693 | void OnChange() { |
| 694 | const auto camera_status = GetStatus(); | ||
| 695 | |||
| 694 | const Common::Input::CallbackStatus status{ | 696 | const Common::Input::CallbackStatus status{ |
| 695 | .type = Common::Input::InputType::IrSensor, | 697 | .type = Common::Input::InputType::IrSensor, |
| 696 | .camera_status = GetStatus(), | 698 | .camera_status = camera_status.format, |
| 699 | .raw_data = camera_status.data, | ||
| 700 | }; | ||
| 701 | |||
| 702 | TriggerOnChange(status); | ||
| 703 | } | ||
| 704 | |||
| 705 | private: | ||
| 706 | const PadIdentifier identifier; | ||
| 707 | int callback_key; | ||
| 708 | InputEngine* input_engine; | ||
| 709 | }; | ||
| 710 | |||
| 711 | class InputFromNfc final : public Common::Input::InputDevice { | ||
| 712 | public: | ||
| 713 | explicit InputFromNfc(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 714 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 715 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 716 | const InputIdentifier input_identifier{ | ||
| 717 | .identifier = identifier, | ||
| 718 | .type = EngineInputType::Nfc, | ||
| 719 | .index = 0, | ||
| 720 | .callback = engine_callback, | ||
| 721 | }; | ||
| 722 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 723 | } | ||
| 724 | |||
| 725 | ~InputFromNfc() override { | ||
| 726 | input_engine->DeleteCallback(callback_key); | ||
| 727 | } | ||
| 728 | |||
| 729 | Common::Input::NfcStatus GetStatus() const { | ||
| 730 | return input_engine->GetNfc(identifier); | ||
| 731 | } | ||
| 732 | |||
| 733 | void ForceUpdate() override { | ||
| 734 | OnChange(); | ||
| 735 | } | ||
| 736 | |||
| 737 | void OnChange() { | ||
| 738 | const auto nfc_status = GetStatus(); | ||
| 739 | |||
| 740 | const Common::Input::CallbackStatus status{ | ||
| 741 | .type = Common::Input::InputType::Nfc, | ||
| 742 | .nfc_status = nfc_status.state, | ||
| 743 | .raw_data = nfc_status.data, | ||
| 697 | }; | 744 | }; |
| 698 | 745 | ||
| 699 | TriggerOnChange(status); | 746 | TriggerOnChange(status); |
| @@ -727,6 +774,14 @@ public: | |||
| 727 | return input_engine->SetCameraFormat(identifier, camera_format); | 774 | return input_engine->SetCameraFormat(identifier, camera_format); |
| 728 | } | 775 | } |
| 729 | 776 | ||
| 777 | Common::Input::NfcState SupportsNfc() const override { | ||
| 778 | return input_engine->SupportsNfc(identifier); | ||
| 779 | } | ||
| 780 | |||
| 781 | Common::Input::NfcState WriteNfcData(const std::vector<u8>& data) override { | ||
| 782 | return input_engine->WriteNfcData(identifier, data); | ||
| 783 | } | ||
| 784 | |||
| 730 | private: | 785 | private: |
| 731 | const PadIdentifier identifier; | 786 | const PadIdentifier identifier; |
| 732 | InputEngine* input_engine; | 787 | InputEngine* input_engine; |
| @@ -742,8 +797,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice( | |||
| 742 | 797 | ||
| 743 | const auto button_id = params.Get("button", 0); | 798 | const auto button_id = params.Get("button", 0); |
| 744 | const auto keyboard_key = params.Get("code", 0); | 799 | const auto keyboard_key = params.Get("code", 0); |
| 745 | const auto toggle = params.Get("toggle", false); | 800 | const auto toggle = params.Get("toggle", false) != 0; |
| 746 | const auto inverted = params.Get("inverted", false); | 801 | const auto inverted = params.Get("inverted", false) != 0; |
| 747 | input_engine->PreSetController(identifier); | 802 | input_engine->PreSetController(identifier); |
| 748 | input_engine->PreSetButton(identifier, button_id); | 803 | input_engine->PreSetButton(identifier, button_id); |
| 749 | input_engine->PreSetButton(identifier, keyboard_key); | 804 | input_engine->PreSetButton(identifier, keyboard_key); |
| @@ -765,8 +820,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice( | |||
| 765 | 820 | ||
| 766 | const auto button_id = params.Get("hat", 0); | 821 | const auto button_id = params.Get("hat", 0); |
| 767 | const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); | 822 | const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); |
| 768 | const auto toggle = params.Get("toggle", false); | 823 | const auto toggle = params.Get("toggle", false) != 0; |
| 769 | const auto inverted = params.Get("inverted", false); | 824 | const auto inverted = params.Get("inverted", false) != 0; |
| 770 | 825 | ||
| 771 | input_engine->PreSetController(identifier); | 826 | input_engine->PreSetController(identifier); |
| 772 | input_engine->PreSetHatButton(identifier, button_id); | 827 | input_engine->PreSetHatButton(identifier, button_id); |
| @@ -824,7 +879,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 824 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 879 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), |
| 825 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), | 880 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), |
| 826 | .inverted = params.Get("invert", "+") == "-", | 881 | .inverted = params.Get("invert", "+") == "-", |
| 827 | .toggle = static_cast<bool>(params.Get("toggle", false)), | 882 | .toggle = params.Get("toggle", false) != 0, |
| 828 | }; | 883 | }; |
| 829 | input_engine->PreSetController(identifier); | 884 | input_engine->PreSetController(identifier); |
| 830 | input_engine->PreSetAxis(identifier, axis); | 885 | input_engine->PreSetAxis(identifier, axis); |
| @@ -840,8 +895,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTriggerDevice( | |||
| 840 | }; | 895 | }; |
| 841 | 896 | ||
| 842 | const auto button = params.Get("button", 0); | 897 | const auto button = params.Get("button", 0); |
| 843 | const auto toggle = params.Get("toggle", false); | 898 | const auto toggle = params.Get("toggle", false) != 0; |
| 844 | const auto inverted = params.Get("inverted", false); | 899 | const auto inverted = params.Get("inverted", false) != 0; |
| 845 | 900 | ||
| 846 | const auto axis = params.Get("axis", 0); | 901 | const auto axis = params.Get("axis", 0); |
| 847 | const Common::Input::AnalogProperties properties = { | 902 | const Common::Input::AnalogProperties properties = { |
| @@ -871,8 +926,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice( | |||
| 871 | }; | 926 | }; |
| 872 | 927 | ||
| 873 | const auto button = params.Get("button", 0); | 928 | const auto button = params.Get("button", 0); |
| 874 | const auto toggle = params.Get("toggle", false); | 929 | const auto toggle = params.Get("toggle", false) != 0; |
| 875 | const auto inverted = params.Get("inverted", false); | 930 | const auto inverted = params.Get("inverted", false) != 0; |
| 876 | 931 | ||
| 877 | const auto axis_x = params.Get("axis_x", 0); | 932 | const auto axis_x = params.Get("axis_x", 0); |
| 878 | const Common::Input::AnalogProperties properties_x = { | 933 | const Common::Input::AnalogProperties properties_x = { |
| @@ -978,6 +1033,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateCameraDevice( | |||
| 978 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); | 1033 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); |
| 979 | } | 1034 | } |
| 980 | 1035 | ||
| 1036 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateNfcDevice( | ||
| 1037 | const Common::ParamPackage& params) { | ||
| 1038 | const PadIdentifier identifier = { | ||
| 1039 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1040 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1041 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1042 | }; | ||
| 1043 | |||
| 1044 | input_engine->PreSetController(identifier); | ||
| 1045 | return std::make_unique<InputFromNfc>(identifier, input_engine.get()); | ||
| 1046 | } | ||
| 1047 | |||
| 981 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) | 1048 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 982 | : input_engine(std::move(input_engine_)) {} | 1049 | : input_engine(std::move(input_engine_)) {} |
| 983 | 1050 | ||
| @@ -989,6 +1056,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 989 | if (params.Has("camera")) { | 1056 | if (params.Has("camera")) { |
| 990 | return CreateCameraDevice(params); | 1057 | return CreateCameraDevice(params); |
| 991 | } | 1058 | } |
| 1059 | if (params.Has("nfc")) { | ||
| 1060 | return CreateNfcDevice(params); | ||
| 1061 | } | ||
| 992 | if (params.Has("button") && params.Has("axis")) { | 1062 | if (params.Has("button") && params.Has("axis")) { |
| 993 | return CreateTriggerDevice(params); | 1063 | return CreateTriggerDevice(params); |
| 994 | } | 1064 | } |