diff options
Diffstat (limited to 'src/input_common/input_poller.cpp')
| -rw-r--r-- | src/input_common/input_poller.cpp | 78 |
1 files changed, 73 insertions, 5 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index fb8be42e2..15cbf7e5f 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -498,6 +498,58 @@ private: | |||
| 498 | InputEngine* input_engine; | 498 | InputEngine* input_engine; |
| 499 | }; | 499 | }; |
| 500 | 500 | ||
| 501 | class InputFromColor final : public Common::Input::InputDevice { | ||
| 502 | public: | ||
| 503 | explicit InputFromColor(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 504 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 505 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 506 | const InputIdentifier input_identifier{ | ||
| 507 | .identifier = identifier, | ||
| 508 | .type = EngineInputType::Color, | ||
| 509 | .index = 0, | ||
| 510 | .callback = engine_callback, | ||
| 511 | }; | ||
| 512 | last_color_value = {}; | ||
| 513 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 514 | } | ||
| 515 | |||
| 516 | ~InputFromColor() override { | ||
| 517 | input_engine->DeleteCallback(callback_key); | ||
| 518 | } | ||
| 519 | |||
| 520 | Common::Input::BodyColorStatus GetStatus() const { | ||
| 521 | return input_engine->GetColor(identifier); | ||
| 522 | } | ||
| 523 | |||
| 524 | void ForceUpdate() override { | ||
| 525 | const Common::Input::CallbackStatus status{ | ||
| 526 | .type = Common::Input::InputType::Color, | ||
| 527 | .color_status = GetStatus(), | ||
| 528 | }; | ||
| 529 | |||
| 530 | last_color_value = status.color_status; | ||
| 531 | TriggerOnChange(status); | ||
| 532 | } | ||
| 533 | |||
| 534 | void OnChange() { | ||
| 535 | const Common::Input::CallbackStatus status{ | ||
| 536 | .type = Common::Input::InputType::Color, | ||
| 537 | .color_status = GetStatus(), | ||
| 538 | }; | ||
| 539 | |||
| 540 | if (status.color_status.body != last_color_value.body) { | ||
| 541 | last_color_value = status.color_status; | ||
| 542 | TriggerOnChange(status); | ||
| 543 | } | ||
| 544 | } | ||
| 545 | |||
| 546 | private: | ||
| 547 | const PadIdentifier identifier; | ||
| 548 | int callback_key; | ||
| 549 | Common::Input::BodyColorStatus last_color_value; | ||
| 550 | InputEngine* input_engine; | ||
| 551 | }; | ||
| 552 | |||
| 501 | class InputFromMotion final : public Common::Input::InputDevice { | 553 | class InputFromMotion final : public Common::Input::InputDevice { |
| 502 | public: | 554 | public: |
| 503 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, | 555 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, |
| @@ -754,11 +806,11 @@ public: | |||
| 754 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) | 806 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) |
| 755 | : identifier(identifier_), input_engine(input_engine_) {} | 807 | : identifier(identifier_), input_engine(input_engine_) {} |
| 756 | 808 | ||
| 757 | void SetLED(const Common::Input::LedStatus& led_status) override { | 809 | Common::Input::DriverResult SetLED(const Common::Input::LedStatus& led_status) override { |
| 758 | input_engine->SetLeds(identifier, led_status); | 810 | return input_engine->SetLeds(identifier, led_status); |
| 759 | } | 811 | } |
| 760 | 812 | ||
| 761 | Common::Input::VibrationError SetVibration( | 813 | Common::Input::DriverResult SetVibration( |
| 762 | const Common::Input::VibrationStatus& vibration_status) override { | 814 | const Common::Input::VibrationStatus& vibration_status) override { |
| 763 | return input_engine->SetVibration(identifier, vibration_status); | 815 | return input_engine->SetVibration(identifier, vibration_status); |
| 764 | } | 816 | } |
| @@ -767,11 +819,12 @@ public: | |||
| 767 | return input_engine->IsVibrationEnabled(identifier); | 819 | return input_engine->IsVibrationEnabled(identifier); |
| 768 | } | 820 | } |
| 769 | 821 | ||
| 770 | Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override { | 822 | Common::Input::DriverResult SetPollingMode(Common::Input::PollingMode polling_mode) override { |
| 771 | return input_engine->SetPollingMode(identifier, polling_mode); | 823 | return input_engine->SetPollingMode(identifier, polling_mode); |
| 772 | } | 824 | } |
| 773 | 825 | ||
| 774 | Common::Input::CameraError SetCameraFormat(Common::Input::CameraFormat camera_format) override { | 826 | Common::Input::DriverResult SetCameraFormat( |
| 827 | Common::Input::CameraFormat camera_format) override { | ||
| 775 | return input_engine->SetCameraFormat(identifier, camera_format); | 828 | return input_engine->SetCameraFormat(identifier, camera_format); |
| 776 | } | 829 | } |
| 777 | 830 | ||
| @@ -966,6 +1019,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice( | |||
| 966 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); | 1019 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); |
| 967 | } | 1020 | } |
| 968 | 1021 | ||
| 1022 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice( | ||
| 1023 | const Common::ParamPackage& params) { | ||
| 1024 | const PadIdentifier identifier = { | ||
| 1025 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1026 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1027 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1028 | }; | ||
| 1029 | |||
| 1030 | input_engine->PreSetController(identifier); | ||
| 1031 | return std::make_unique<InputFromColor>(identifier, input_engine.get()); | ||
| 1032 | } | ||
| 1033 | |||
| 969 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | 1034 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( |
| 970 | Common::ParamPackage params) { | 1035 | Common::ParamPackage params) { |
| 971 | const PadIdentifier identifier = { | 1036 | const PadIdentifier identifier = { |
| @@ -1053,6 +1118,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 1053 | if (params.Has("battery")) { | 1118 | if (params.Has("battery")) { |
| 1054 | return CreateBatteryDevice(params); | 1119 | return CreateBatteryDevice(params); |
| 1055 | } | 1120 | } |
| 1121 | if (params.Has("color")) { | ||
| 1122 | return CreateColorDevice(params); | ||
| 1123 | } | ||
| 1056 | if (params.Has("camera")) { | 1124 | if (params.Has("camera")) { |
| 1057 | return CreateCameraDevice(params); | 1125 | return CreateCameraDevice(params); |
| 1058 | } | 1126 | } |