diff options
Diffstat (limited to 'src/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 96 |
1 files changed, 85 insertions, 11 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index ffb9b945e..4ac182147 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); |
| @@ -716,7 +763,11 @@ public: | |||
| 716 | 763 | ||
| 717 | Common::Input::VibrationError SetVibration( | 764 | Common::Input::VibrationError SetVibration( |
| 718 | const Common::Input::VibrationStatus& vibration_status) override { | 765 | const Common::Input::VibrationStatus& vibration_status) override { |
| 719 | return input_engine->SetRumble(identifier, vibration_status); | 766 | return input_engine->SetVibration(identifier, vibration_status); |
| 767 | } | ||
| 768 | |||
| 769 | bool IsVibrationEnabled() override { | ||
| 770 | return input_engine->IsVibrationEnabled(identifier); | ||
| 720 | } | 771 | } |
| 721 | 772 | ||
| 722 | Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override { | 773 | Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override { |
| @@ -727,6 +778,14 @@ public: | |||
| 727 | return input_engine->SetCameraFormat(identifier, camera_format); | 778 | return input_engine->SetCameraFormat(identifier, camera_format); |
| 728 | } | 779 | } |
| 729 | 780 | ||
| 781 | Common::Input::NfcState SupportsNfc() const override { | ||
| 782 | return input_engine->SupportsNfc(identifier); | ||
| 783 | } | ||
| 784 | |||
| 785 | Common::Input::NfcState WriteNfcData(const std::vector<u8>& data) override { | ||
| 786 | return input_engine->WriteNfcData(identifier, data); | ||
| 787 | } | ||
| 788 | |||
| 730 | private: | 789 | private: |
| 731 | const PadIdentifier identifier; | 790 | const PadIdentifier identifier; |
| 732 | InputEngine* input_engine; | 791 | InputEngine* input_engine; |
| @@ -742,8 +801,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice( | |||
| 742 | 801 | ||
| 743 | const auto button_id = params.Get("button", 0); | 802 | const auto button_id = params.Get("button", 0); |
| 744 | const auto keyboard_key = params.Get("code", 0); | 803 | const auto keyboard_key = params.Get("code", 0); |
| 745 | const auto toggle = params.Get("toggle", false); | 804 | const auto toggle = params.Get("toggle", false) != 0; |
| 746 | const auto inverted = params.Get("inverted", false); | 805 | const auto inverted = params.Get("inverted", false) != 0; |
| 747 | input_engine->PreSetController(identifier); | 806 | input_engine->PreSetController(identifier); |
| 748 | input_engine->PreSetButton(identifier, button_id); | 807 | input_engine->PreSetButton(identifier, button_id); |
| 749 | input_engine->PreSetButton(identifier, keyboard_key); | 808 | input_engine->PreSetButton(identifier, keyboard_key); |
| @@ -765,8 +824,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice( | |||
| 765 | 824 | ||
| 766 | const auto button_id = params.Get("hat", 0); | 825 | const auto button_id = params.Get("hat", 0); |
| 767 | const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); | 826 | const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); |
| 768 | const auto toggle = params.Get("toggle", false); | 827 | const auto toggle = params.Get("toggle", false) != 0; |
| 769 | const auto inverted = params.Get("inverted", false); | 828 | const auto inverted = params.Get("inverted", false) != 0; |
| 770 | 829 | ||
| 771 | input_engine->PreSetController(identifier); | 830 | input_engine->PreSetController(identifier); |
| 772 | input_engine->PreSetHatButton(identifier, button_id); | 831 | input_engine->PreSetHatButton(identifier, button_id); |
| @@ -824,7 +883,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( | |||
| 824 | .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), | 883 | .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), | 884 | .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), |
| 826 | .inverted = params.Get("invert", "+") == "-", | 885 | .inverted = params.Get("invert", "+") == "-", |
| 827 | .toggle = static_cast<bool>(params.Get("toggle", false)), | 886 | .toggle = params.Get("toggle", false) != 0, |
| 828 | }; | 887 | }; |
| 829 | input_engine->PreSetController(identifier); | 888 | input_engine->PreSetController(identifier); |
| 830 | input_engine->PreSetAxis(identifier, axis); | 889 | input_engine->PreSetAxis(identifier, axis); |
| @@ -840,8 +899,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTriggerDevice( | |||
| 840 | }; | 899 | }; |
| 841 | 900 | ||
| 842 | const auto button = params.Get("button", 0); | 901 | const auto button = params.Get("button", 0); |
| 843 | const auto toggle = params.Get("toggle", false); | 902 | const auto toggle = params.Get("toggle", false) != 0; |
| 844 | const auto inverted = params.Get("inverted", false); | 903 | const auto inverted = params.Get("inverted", false) != 0; |
| 845 | 904 | ||
| 846 | const auto axis = params.Get("axis", 0); | 905 | const auto axis = params.Get("axis", 0); |
| 847 | const Common::Input::AnalogProperties properties = { | 906 | const Common::Input::AnalogProperties properties = { |
| @@ -871,8 +930,8 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateTouchDevice( | |||
| 871 | }; | 930 | }; |
| 872 | 931 | ||
| 873 | const auto button = params.Get("button", 0); | 932 | const auto button = params.Get("button", 0); |
| 874 | const auto toggle = params.Get("toggle", false); | 933 | const auto toggle = params.Get("toggle", false) != 0; |
| 875 | const auto inverted = params.Get("inverted", false); | 934 | const auto inverted = params.Get("inverted", false) != 0; |
| 876 | 935 | ||
| 877 | const auto axis_x = params.Get("axis_x", 0); | 936 | const auto axis_x = params.Get("axis_x", 0); |
| 878 | const Common::Input::AnalogProperties properties_x = { | 937 | const Common::Input::AnalogProperties properties_x = { |
| @@ -978,6 +1037,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateCameraDevice( | |||
| 978 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); | 1037 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); |
| 979 | } | 1038 | } |
| 980 | 1039 | ||
| 1040 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateNfcDevice( | ||
| 1041 | const Common::ParamPackage& params) { | ||
| 1042 | const PadIdentifier identifier = { | ||
| 1043 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1044 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1045 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1046 | }; | ||
| 1047 | |||
| 1048 | input_engine->PreSetController(identifier); | ||
| 1049 | return std::make_unique<InputFromNfc>(identifier, input_engine.get()); | ||
| 1050 | } | ||
| 1051 | |||
| 981 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) | 1052 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 982 | : input_engine(std::move(input_engine_)) {} | 1053 | : input_engine(std::move(input_engine_)) {} |
| 983 | 1054 | ||
| @@ -989,6 +1060,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 989 | if (params.Has("camera")) { | 1060 | if (params.Has("camera")) { |
| 990 | return CreateCameraDevice(params); | 1061 | return CreateCameraDevice(params); |
| 991 | } | 1062 | } |
| 1063 | if (params.Has("nfc")) { | ||
| 1064 | return CreateNfcDevice(params); | ||
| 1065 | } | ||
| 992 | if (params.Has("button") && params.Has("axis")) { | 1066 | if (params.Has("button") && params.Has("axis")) { |
| 993 | return CreateTriggerDevice(params); | 1067 | return CreateTriggerDevice(params); |
| 994 | } | 1068 | } |