diff options
Diffstat (limited to 'src/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 108 |
1 files changed, 91 insertions, 17 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index fb8be42e2..8c6a6521a 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -16,10 +16,10 @@ public: | |||
| 16 | 16 | ||
| 17 | class InputFromButton final : public Common::Input::InputDevice { | 17 | class InputFromButton final : public Common::Input::InputDevice { |
| 18 | public: | 18 | public: |
| 19 | explicit InputFromButton(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_, | 19 | explicit InputFromButton(PadIdentifier identifier_, int button_, bool turbo_, bool toggle_, |
| 20 | InputEngine* input_engine_) | 20 | bool inverted_, InputEngine* input_engine_) |
| 21 | : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), | 21 | : identifier(identifier_), button(button_), turbo(turbo_), toggle(toggle_), |
| 22 | input_engine(input_engine_) { | 22 | inverted(inverted_), input_engine(input_engine_) { |
| 23 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | 23 | UpdateCallback engine_callback{[this]() { OnChange(); }}; |
| 24 | const InputIdentifier input_identifier{ | 24 | const InputIdentifier input_identifier{ |
| 25 | .identifier = identifier, | 25 | .identifier = identifier, |
| @@ -40,6 +40,7 @@ public: | |||
| 40 | .value = input_engine->GetButton(identifier, button), | 40 | .value = input_engine->GetButton(identifier, button), |
| 41 | .inverted = inverted, | 41 | .inverted = inverted, |
| 42 | .toggle = toggle, | 42 | .toggle = toggle, |
| 43 | .turbo = turbo, | ||
| 43 | }; | 44 | }; |
| 44 | } | 45 | } |
| 45 | 46 | ||
| @@ -68,6 +69,7 @@ public: | |||
| 68 | private: | 69 | private: |
| 69 | const PadIdentifier identifier; | 70 | const PadIdentifier identifier; |
| 70 | const int button; | 71 | const int button; |
| 72 | const bool turbo; | ||
| 71 | const bool toggle; | 73 | const bool toggle; |
| 72 | const bool inverted; | 74 | const bool inverted; |
| 73 | int callback_key; | 75 | int callback_key; |
| @@ -77,10 +79,10 @@ private: | |||
| 77 | 79 | ||
| 78 | class InputFromHatButton final : public Common::Input::InputDevice { | 80 | class InputFromHatButton final : public Common::Input::InputDevice { |
| 79 | public: | 81 | public: |
| 80 | explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool toggle_, | 82 | explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool turbo_, |
| 81 | bool inverted_, InputEngine* input_engine_) | 83 | bool toggle_, bool inverted_, InputEngine* input_engine_) |
| 82 | : identifier(identifier_), button(button_), direction(direction_), toggle(toggle_), | 84 | : identifier(identifier_), button(button_), direction(direction_), turbo(turbo_), |
| 83 | inverted(inverted_), input_engine(input_engine_) { | 85 | toggle(toggle_), inverted(inverted_), input_engine(input_engine_) { |
| 84 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | 86 | UpdateCallback engine_callback{[this]() { OnChange(); }}; |
| 85 | const InputIdentifier input_identifier{ | 87 | const InputIdentifier input_identifier{ |
| 86 | .identifier = identifier, | 88 | .identifier = identifier, |
| @@ -101,6 +103,7 @@ public: | |||
| 101 | .value = input_engine->GetHatButton(identifier, button, direction), | 103 | .value = input_engine->GetHatButton(identifier, button, direction), |
| 102 | .inverted = inverted, | 104 | .inverted = inverted, |
| 103 | .toggle = toggle, | 105 | .toggle = toggle, |
| 106 | .turbo = turbo, | ||
| 104 | }; | 107 | }; |
| 105 | } | 108 | } |
| 106 | 109 | ||
| @@ -130,6 +133,7 @@ private: | |||
| 130 | const PadIdentifier identifier; | 133 | const PadIdentifier identifier; |
| 131 | const int button; | 134 | const int button; |
| 132 | const u8 direction; | 135 | const u8 direction; |
| 136 | const bool turbo; | ||
| 133 | const bool toggle; | 137 | const bool toggle; |
| 134 | const bool inverted; | 138 | const bool inverted; |
| 135 | int callback_key; | 139 | int callback_key; |
| @@ -498,6 +502,58 @@ private: | |||
| 498 | InputEngine* input_engine; | 502 | InputEngine* input_engine; |
| 499 | }; | 503 | }; |
| 500 | 504 | ||
| 505 | class InputFromColor final : public Common::Input::InputDevice { | ||
| 506 | public: | ||
| 507 | explicit InputFromColor(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 508 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 509 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 510 | const InputIdentifier input_identifier{ | ||
| 511 | .identifier = identifier, | ||
| 512 | .type = EngineInputType::Color, | ||
| 513 | .index = 0, | ||
| 514 | .callback = engine_callback, | ||
| 515 | }; | ||
| 516 | last_color_value = {}; | ||
| 517 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 518 | } | ||
| 519 | |||
| 520 | ~InputFromColor() override { | ||
| 521 | input_engine->DeleteCallback(callback_key); | ||
| 522 | } | ||
| 523 | |||
| 524 | Common::Input::BodyColorStatus GetStatus() const { | ||
| 525 | return input_engine->GetColor(identifier); | ||
| 526 | } | ||
| 527 | |||
| 528 | void ForceUpdate() override { | ||
| 529 | const Common::Input::CallbackStatus status{ | ||
| 530 | .type = Common::Input::InputType::Color, | ||
| 531 | .color_status = GetStatus(), | ||
| 532 | }; | ||
| 533 | |||
| 534 | last_color_value = status.color_status; | ||
| 535 | TriggerOnChange(status); | ||
| 536 | } | ||
| 537 | |||
| 538 | void OnChange() { | ||
| 539 | const Common::Input::CallbackStatus status{ | ||
| 540 | .type = Common::Input::InputType::Color, | ||
| 541 | .color_status = GetStatus(), | ||
| 542 | }; | ||
| 543 | |||
| 544 | if (status.color_status.body != last_color_value.body) { | ||
| 545 | last_color_value = status.color_status; | ||
| 546 | TriggerOnChange(status); | ||
| 547 | } | ||
| 548 | } | ||
| 549 | |||
| 550 | private: | ||
| 551 | const PadIdentifier identifier; | ||
| 552 | int callback_key; | ||
| 553 | Common::Input::BodyColorStatus last_color_value; | ||
| 554 | InputEngine* input_engine; | ||
| 555 | }; | ||
| 556 | |||
| 501 | class InputFromMotion final : public Common::Input::InputDevice { | 557 | class InputFromMotion final : public Common::Input::InputDevice { |
| 502 | public: | 558 | public: |
| 503 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, | 559 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, |
| @@ -754,11 +810,11 @@ public: | |||
| 754 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) | 810 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) |
| 755 | : identifier(identifier_), input_engine(input_engine_) {} | 811 | : identifier(identifier_), input_engine(input_engine_) {} |
| 756 | 812 | ||
| 757 | void SetLED(const Common::Input::LedStatus& led_status) override { | 813 | Common::Input::DriverResult SetLED(const Common::Input::LedStatus& led_status) override { |
| 758 | input_engine->SetLeds(identifier, led_status); | 814 | return input_engine->SetLeds(identifier, led_status); |
| 759 | } | 815 | } |
| 760 | 816 | ||
| 761 | Common::Input::VibrationError SetVibration( | 817 | Common::Input::DriverResult SetVibration( |
| 762 | const Common::Input::VibrationStatus& vibration_status) override { | 818 | const Common::Input::VibrationStatus& vibration_status) override { |
| 763 | return input_engine->SetVibration(identifier, vibration_status); | 819 | return input_engine->SetVibration(identifier, vibration_status); |
| 764 | } | 820 | } |
| @@ -767,11 +823,12 @@ public: | |||
| 767 | return input_engine->IsVibrationEnabled(identifier); | 823 | return input_engine->IsVibrationEnabled(identifier); |
| 768 | } | 824 | } |
| 769 | 825 | ||
| 770 | Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override { | 826 | Common::Input::DriverResult SetPollingMode(Common::Input::PollingMode polling_mode) override { |
| 771 | return input_engine->SetPollingMode(identifier, polling_mode); | 827 | return input_engine->SetPollingMode(identifier, polling_mode); |
| 772 | } | 828 | } |
| 773 | 829 | ||
| 774 | Common::Input::CameraError SetCameraFormat(Common::Input::CameraFormat camera_format) override { | 830 | Common::Input::DriverResult SetCameraFormat( |
| 831 | Common::Input::CameraFormat camera_format) override { | ||
| 775 | return input_engine->SetCameraFormat(identifier, camera_format); | 832 | return input_engine->SetCameraFormat(identifier, camera_format); |
| 776 | } | 833 | } |
| 777 | 834 | ||
| @@ -800,14 +857,15 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice( | |||
| 800 | const auto keyboard_key = params.Get("code", 0); | 857 | const auto keyboard_key = params.Get("code", 0); |
| 801 | const auto toggle = params.Get("toggle", false) != 0; | 858 | const auto toggle = params.Get("toggle", false) != 0; |
| 802 | const auto inverted = params.Get("inverted", false) != 0; | 859 | const auto inverted = params.Get("inverted", false) != 0; |
| 860 | const auto turbo = params.Get("turbo", false) != 0; | ||
| 803 | input_engine->PreSetController(identifier); | 861 | input_engine->PreSetController(identifier); |
| 804 | input_engine->PreSetButton(identifier, button_id); | 862 | input_engine->PreSetButton(identifier, button_id); |
| 805 | input_engine->PreSetButton(identifier, keyboard_key); | 863 | input_engine->PreSetButton(identifier, keyboard_key); |
| 806 | if (keyboard_key != 0) { | 864 | if (keyboard_key != 0) { |
| 807 | return std::make_unique<InputFromButton>(identifier, keyboard_key, toggle, inverted, | 865 | return std::make_unique<InputFromButton>(identifier, keyboard_key, turbo, toggle, inverted, |
| 808 | input_engine.get()); | 866 | input_engine.get()); |
| 809 | } | 867 | } |
| 810 | return std::make_unique<InputFromButton>(identifier, button_id, toggle, inverted, | 868 | return std::make_unique<InputFromButton>(identifier, button_id, turbo, toggle, inverted, |
| 811 | input_engine.get()); | 869 | input_engine.get()); |
| 812 | } | 870 | } |
| 813 | 871 | ||
| @@ -823,11 +881,12 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice( | |||
| 823 | const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); | 881 | const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); |
| 824 | const auto toggle = params.Get("toggle", false) != 0; | 882 | const auto toggle = params.Get("toggle", false) != 0; |
| 825 | const auto inverted = params.Get("inverted", false) != 0; | 883 | const auto inverted = params.Get("inverted", false) != 0; |
| 884 | const auto turbo = params.Get("turbo", false) != 0; | ||
| 826 | 885 | ||
| 827 | input_engine->PreSetController(identifier); | 886 | input_engine->PreSetController(identifier); |
| 828 | input_engine->PreSetHatButton(identifier, button_id); | 887 | input_engine->PreSetHatButton(identifier, button_id); |
| 829 | return std::make_unique<InputFromHatButton>(identifier, button_id, direction, toggle, inverted, | 888 | return std::make_unique<InputFromHatButton>(identifier, button_id, direction, turbo, toggle, |
| 830 | input_engine.get()); | 889 | inverted, input_engine.get()); |
| 831 | } | 890 | } |
| 832 | 891 | ||
| 833 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice( | 892 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice( |
| @@ -966,6 +1025,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice( | |||
| 966 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); | 1025 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); |
| 967 | } | 1026 | } |
| 968 | 1027 | ||
| 1028 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice( | ||
| 1029 | const Common::ParamPackage& params) { | ||
| 1030 | const PadIdentifier identifier = { | ||
| 1031 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1032 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1033 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1034 | }; | ||
| 1035 | |||
| 1036 | input_engine->PreSetController(identifier); | ||
| 1037 | return std::make_unique<InputFromColor>(identifier, input_engine.get()); | ||
| 1038 | } | ||
| 1039 | |||
| 969 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | 1040 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( |
| 970 | Common::ParamPackage params) { | 1041 | Common::ParamPackage params) { |
| 971 | const PadIdentifier identifier = { | 1042 | const PadIdentifier identifier = { |
| @@ -1053,6 +1124,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 1053 | if (params.Has("battery")) { | 1124 | if (params.Has("battery")) { |
| 1054 | return CreateBatteryDevice(params); | 1125 | return CreateBatteryDevice(params); |
| 1055 | } | 1126 | } |
| 1127 | if (params.Has("color")) { | ||
| 1128 | return CreateColorDevice(params); | ||
| 1129 | } | ||
| 1056 | if (params.Has("camera")) { | 1130 | if (params.Has("camera")) { |
| 1057 | return CreateCameraDevice(params); | 1131 | return CreateCameraDevice(params); |
| 1058 | } | 1132 | } |