diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/camera.cpp | 82 | ||||
| -rw-r--r-- | src/input_common/drivers/camera.h | 29 | ||||
| -rw-r--r-- | src/input_common/input_engine.cpp | 38 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 19 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 60 | ||||
| -rw-r--r-- | src/input_common/input_poller.h | 11 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 21 | ||||
| -rw-r--r-- | src/input_common/main.h | 9 |
9 files changed, 267 insertions, 4 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 48e799cf5..90dd629c6 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | add_library(input_common STATIC | 1 | add_library(input_common STATIC |
| 2 | drivers/camera.cpp | ||
| 3 | drivers/camera.h | ||
| 2 | drivers/gc_adapter.cpp | 4 | drivers/gc_adapter.cpp |
| 3 | drivers/gc_adapter.h | 5 | drivers/gc_adapter.h |
| 4 | drivers/keyboard.cpp | 6 | drivers/keyboard.cpp |
diff --git a/src/input_common/drivers/camera.cpp b/src/input_common/drivers/camera.cpp new file mode 100644 index 000000000..dceea67e0 --- /dev/null +++ b/src/input_common/drivers/camera.cpp | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include <fmt/format.h> | ||
| 5 | |||
| 6 | #include "common/param_package.h" | ||
| 7 | #include "input_common/drivers/camera.h" | ||
| 8 | |||
| 9 | namespace InputCommon { | ||
| 10 | constexpr PadIdentifier identifier = { | ||
| 11 | .guid = Common::UUID{}, | ||
| 12 | .port = 0, | ||
| 13 | .pad = 0, | ||
| 14 | }; | ||
| 15 | |||
| 16 | Camera::Camera(std::string input_engine_) : InputEngine(std::move(input_engine_)) { | ||
| 17 | PreSetController(identifier); | ||
| 18 | } | ||
| 19 | |||
| 20 | void Camera::SetCameraData(std::size_t width, std::size_t height, std::vector<u32> data) { | ||
| 21 | const std::size_t desired_width = getImageWidth(); | ||
| 22 | const std::size_t desired_height = getImageHeight(); | ||
| 23 | status.data.resize(desired_width * desired_height); | ||
| 24 | |||
| 25 | // Resize image to desired format | ||
| 26 | for (std::size_t y = 0; y < desired_height; y++) { | ||
| 27 | for (std::size_t x = 0; x < desired_width; x++) { | ||
| 28 | const std::size_t pixel_index = y * desired_width + x; | ||
| 29 | const std::size_t old_x = width * x / desired_width; | ||
| 30 | const std::size_t old_y = height * y / desired_height; | ||
| 31 | const std::size_t data_pixel_index = old_y * width + old_x; | ||
| 32 | status.data[pixel_index] = static_cast<u8>(data[data_pixel_index] & 0xFF); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | SetCamera(identifier, status); | ||
| 37 | } | ||
| 38 | |||
| 39 | std::size_t Camera::getImageWidth() const { | ||
| 40 | switch (status.format) { | ||
| 41 | case Common::Input::CameraFormat::Size320x240: | ||
| 42 | return 320; | ||
| 43 | case Common::Input::CameraFormat::Size160x120: | ||
| 44 | return 160; | ||
| 45 | case Common::Input::CameraFormat::Size80x60: | ||
| 46 | return 80; | ||
| 47 | case Common::Input::CameraFormat::Size40x30: | ||
| 48 | return 40; | ||
| 49 | case Common::Input::CameraFormat::Size20x15: | ||
| 50 | return 20; | ||
| 51 | case Common::Input::CameraFormat::None: | ||
| 52 | default: | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | std::size_t Camera::getImageHeight() const { | ||
| 58 | switch (status.format) { | ||
| 59 | case Common::Input::CameraFormat::Size320x240: | ||
| 60 | return 240; | ||
| 61 | case Common::Input::CameraFormat::Size160x120: | ||
| 62 | return 120; | ||
| 63 | case Common::Input::CameraFormat::Size80x60: | ||
| 64 | return 60; | ||
| 65 | case Common::Input::CameraFormat::Size40x30: | ||
| 66 | return 30; | ||
| 67 | case Common::Input::CameraFormat::Size20x15: | ||
| 68 | return 15; | ||
| 69 | case Common::Input::CameraFormat::None: | ||
| 70 | default: | ||
| 71 | return 0; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | Common::Input::CameraError Camera::SetCameraFormat( | ||
| 76 | [[maybe_unused]] const PadIdentifier& identifier_, | ||
| 77 | const Common::Input::CameraFormat camera_format) { | ||
| 78 | status.format = camera_format; | ||
| 79 | return Common::Input::CameraError::None; | ||
| 80 | } | ||
| 81 | |||
| 82 | } // namespace InputCommon | ||
diff --git a/src/input_common/drivers/camera.h b/src/input_common/drivers/camera.h new file mode 100644 index 000000000..b8a7c75e5 --- /dev/null +++ b/src/input_common/drivers/camera.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "input_common/input_engine.h" | ||
| 7 | |||
| 8 | namespace InputCommon { | ||
| 9 | |||
| 10 | /** | ||
| 11 | * A button device factory representing a keyboard. It receives keyboard events and forward them | ||
| 12 | * to all button devices it created. | ||
| 13 | */ | ||
| 14 | class Camera final : public InputEngine { | ||
| 15 | public: | ||
| 16 | explicit Camera(std::string input_engine_); | ||
| 17 | |||
| 18 | void SetCameraData(std::size_t width, std::size_t height, std::vector<u32> data); | ||
| 19 | |||
| 20 | std::size_t getImageWidth() const; | ||
| 21 | std::size_t getImageHeight() const; | ||
| 22 | |||
| 23 | Common::Input::CameraError SetCameraFormat(const PadIdentifier& identifier_, | ||
| 24 | Common::Input::CameraFormat camera_format) override; | ||
| 25 | |||
| 26 | Common::Input::CameraStatus status{}; | ||
| 27 | }; | ||
| 28 | |||
| 29 | } // namespace InputCommon | ||
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 12214d146..6ede0e4b0 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -90,6 +90,18 @@ void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const B | |||
| 90 | TriggerOnMotionChange(identifier, motion, value); | 90 | TriggerOnMotionChange(identifier, motion, value); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | void InputEngine::SetCamera(const PadIdentifier& identifier, | ||
| 94 | const Common::Input::CameraStatus& value) { | ||
| 95 | { | ||
| 96 | std::scoped_lock lock{mutex}; | ||
| 97 | ControllerData& controller = controller_list.at(identifier); | ||
| 98 | if (!configuring) { | ||
| 99 | controller.camera = value; | ||
| 100 | } | ||
| 101 | } | ||
| 102 | TriggerOnCameraChange(identifier, value); | ||
| 103 | } | ||
| 104 | |||
| 93 | bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { | 105 | bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { |
| 94 | std::scoped_lock lock{mutex}; | 106 | std::scoped_lock lock{mutex}; |
| 95 | const auto controller_iter = controller_list.find(identifier); | 107 | const auto controller_iter = controller_list.find(identifier); |
| @@ -165,6 +177,18 @@ BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) | |||
| 165 | return controller.motions.at(motion); | 177 | return controller.motions.at(motion); |
| 166 | } | 178 | } |
| 167 | 179 | ||
| 180 | Common::Input::CameraStatus InputEngine::GetCamera(const PadIdentifier& identifier) const { | ||
| 181 | std::scoped_lock lock{mutex}; | ||
| 182 | const auto controller_iter = controller_list.find(identifier); | ||
| 183 | if (controller_iter == controller_list.cend()) { | ||
| 184 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), | ||
| 185 | identifier.pad, identifier.port); | ||
| 186 | return {}; | ||
| 187 | } | ||
| 188 | const ControllerData& controller = controller_iter->second; | ||
| 189 | return controller.camera; | ||
| 190 | } | ||
| 191 | |||
| 168 | void InputEngine::ResetButtonState() { | 192 | void InputEngine::ResetButtonState() { |
| 169 | for (const auto& controller : controller_list) { | 193 | for (const auto& controller : controller_list) { |
| 170 | for (const auto& button : controller.second.buttons) { | 194 | for (const auto& button : controller.second.buttons) { |
| @@ -317,6 +341,20 @@ void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int mot | |||
| 317 | }); | 341 | }); |
| 318 | } | 342 | } |
| 319 | 343 | ||
| 344 | void InputEngine::TriggerOnCameraChange(const PadIdentifier& identifier, | ||
| 345 | [[maybe_unused]] const Common::Input::CameraStatus& value) { | ||
| 346 | std::scoped_lock lock{mutex_callback}; | ||
| 347 | for (const auto& poller_pair : callback_list) { | ||
| 348 | const InputIdentifier& poller = poller_pair.second; | ||
| 349 | if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Camera, 0)) { | ||
| 350 | continue; | ||
| 351 | } | ||
| 352 | if (poller.callback.on_change) { | ||
| 353 | poller.callback.on_change(); | ||
| 354 | } | ||
| 355 | } | ||
| 356 | } | ||
| 357 | |||
| 320 | bool InputEngine::IsInputIdentifierEqual(const InputIdentifier& input_identifier, | 358 | bool InputEngine::IsInputIdentifierEqual(const InputIdentifier& input_identifier, |
| 321 | const PadIdentifier& identifier, EngineInputType type, | 359 | const PadIdentifier& identifier, EngineInputType type, |
| 322 | int index) const { | 360 | int index) const { |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 13295bd49..f6b3c4610 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -36,11 +36,12 @@ struct BasicMotion { | |||
| 36 | // Types of input that are stored in the engine | 36 | // Types of input that are stored in the engine |
| 37 | enum class EngineInputType { | 37 | enum class EngineInputType { |
| 38 | None, | 38 | None, |
| 39 | Analog, | ||
| 40 | Battery, | ||
| 39 | Button, | 41 | Button, |
| 42 | Camera, | ||
| 40 | HatButton, | 43 | HatButton, |
| 41 | Analog, | ||
| 42 | Motion, | 44 | Motion, |
| 43 | Battery, | ||
| 44 | }; | 45 | }; |
| 45 | 46 | ||
| 46 | namespace std { | 47 | namespace std { |
| @@ -115,10 +116,17 @@ public: | |||
| 115 | // Sets polling mode to a controller | 116 | // Sets polling mode to a controller |
| 116 | virtual Common::Input::PollingError SetPollingMode( | 117 | virtual Common::Input::PollingError SetPollingMode( |
| 117 | [[maybe_unused]] const PadIdentifier& identifier, | 118 | [[maybe_unused]] const PadIdentifier& identifier, |
| 118 | [[maybe_unused]] const Common::Input::PollingMode vibration) { | 119 | [[maybe_unused]] const Common::Input::PollingMode polling_mode) { |
| 119 | return Common::Input::PollingError::NotSupported; | 120 | return Common::Input::PollingError::NotSupported; |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 123 | // Sets camera format to a controller | ||
| 124 | virtual Common::Input::CameraError SetCameraFormat( | ||
| 125 | [[maybe_unused]] const PadIdentifier& identifier, | ||
| 126 | [[maybe_unused]] Common::Input::CameraFormat camera_format) { | ||
| 127 | return Common::Input::CameraError::NotSupported; | ||
| 128 | } | ||
| 129 | |||
| 122 | // Returns the engine name | 130 | // Returns the engine name |
| 123 | [[nodiscard]] const std::string& GetEngineName() const; | 131 | [[nodiscard]] const std::string& GetEngineName() const; |
| 124 | 132 | ||
| @@ -174,6 +182,7 @@ public: | |||
| 174 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; | 182 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; |
| 175 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; | 183 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; |
| 176 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; | 184 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; |
| 185 | Common::Input::CameraStatus GetCamera(const PadIdentifier& identifier) const; | ||
| 177 | 186 | ||
| 178 | int SetCallback(InputIdentifier input_identifier); | 187 | int SetCallback(InputIdentifier input_identifier); |
| 179 | void SetMappingCallback(MappingCallback callback); | 188 | void SetMappingCallback(MappingCallback callback); |
| @@ -185,6 +194,7 @@ protected: | |||
| 185 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); | 194 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); |
| 186 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); | 195 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 187 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); | 196 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); |
| 197 | void SetCamera(const PadIdentifier& identifier, const Common::Input::CameraStatus& value); | ||
| 188 | 198 | ||
| 189 | virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { | 199 | virtual std::string GetHatButtonName([[maybe_unused]] u8 direction_value) const { |
| 190 | return "Unknown"; | 200 | return "Unknown"; |
| @@ -197,6 +207,7 @@ private: | |||
| 197 | std::unordered_map<int, float> axes; | 207 | std::unordered_map<int, float> axes; |
| 198 | std::unordered_map<int, BasicMotion> motions; | 208 | std::unordered_map<int, BasicMotion> motions; |
| 199 | Common::Input::BatteryLevel battery{}; | 209 | Common::Input::BatteryLevel battery{}; |
| 210 | Common::Input::CameraStatus camera{}; | ||
| 200 | }; | 211 | }; |
| 201 | 212 | ||
| 202 | void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); | 213 | void TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value); |
| @@ -205,6 +216,8 @@ private: | |||
| 205 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); | 216 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 206 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, | 217 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, |
| 207 | const BasicMotion& value); | 218 | const BasicMotion& value); |
| 219 | void TriggerOnCameraChange(const PadIdentifier& identifier, | ||
| 220 | const Common::Input::CameraStatus& value); | ||
| 208 | 221 | ||
| 209 | bool IsInputIdentifierEqual(const InputIdentifier& input_identifier, | 222 | bool IsInputIdentifierEqual(const InputIdentifier& input_identifier, |
| 210 | const PadIdentifier& identifier, EngineInputType type, | 223 | const PadIdentifier& identifier, EngineInputType type, |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 49ccb4422..133422d5c 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -664,6 +664,47 @@ private: | |||
| 664 | InputEngine* input_engine; | 664 | InputEngine* input_engine; |
| 665 | }; | 665 | }; |
| 666 | 666 | ||
| 667 | class InputFromCamera final : public Common::Input::InputDevice { | ||
| 668 | public: | ||
| 669 | explicit InputFromCamera(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 670 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 671 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 672 | const InputIdentifier input_identifier{ | ||
| 673 | .identifier = identifier, | ||
| 674 | .type = EngineInputType::Camera, | ||
| 675 | .index = 0, | ||
| 676 | .callback = engine_callback, | ||
| 677 | }; | ||
| 678 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 679 | } | ||
| 680 | |||
| 681 | ~InputFromCamera() override { | ||
| 682 | input_engine->DeleteCallback(callback_key); | ||
| 683 | } | ||
| 684 | |||
| 685 | Common::Input::CameraStatus GetStatus() const { | ||
| 686 | return input_engine->GetCamera(identifier); | ||
| 687 | } | ||
| 688 | |||
| 689 | void ForceUpdate() override { | ||
| 690 | OnChange(); | ||
| 691 | } | ||
| 692 | |||
| 693 | void OnChange() { | ||
| 694 | const Common::Input::CallbackStatus status{ | ||
| 695 | .type = Common::Input::InputType::IrSensor, | ||
| 696 | .camera_status = GetStatus(), | ||
| 697 | }; | ||
| 698 | |||
| 699 | TriggerOnChange(status); | ||
| 700 | } | ||
| 701 | |||
| 702 | private: | ||
| 703 | const PadIdentifier identifier; | ||
| 704 | int callback_key; | ||
| 705 | InputEngine* input_engine; | ||
| 706 | }; | ||
| 707 | |||
| 667 | class OutputFromIdentifier final : public Common::Input::OutputDevice { | 708 | class OutputFromIdentifier final : public Common::Input::OutputDevice { |
| 668 | public: | 709 | public: |
| 669 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) | 710 | explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) |
| @@ -682,6 +723,10 @@ public: | |||
| 682 | return input_engine->SetPollingMode(identifier, polling_mode); | 723 | return input_engine->SetPollingMode(identifier, polling_mode); |
| 683 | } | 724 | } |
| 684 | 725 | ||
| 726 | Common::Input::CameraError SetCameraFormat(Common::Input::CameraFormat camera_format) override { | ||
| 727 | return input_engine->SetCameraFormat(identifier, camera_format); | ||
| 728 | } | ||
| 729 | |||
| 685 | private: | 730 | private: |
| 686 | const PadIdentifier identifier; | 731 | const PadIdentifier identifier; |
| 687 | InputEngine* input_engine; | 732 | InputEngine* input_engine; |
| @@ -920,6 +965,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | |||
| 920 | properties_y, properties_z, input_engine.get()); | 965 | properties_y, properties_z, input_engine.get()); |
| 921 | } | 966 | } |
| 922 | 967 | ||
| 968 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateCameraDevice( | ||
| 969 | const Common::ParamPackage& params) { | ||
| 970 | const PadIdentifier identifier = { | ||
| 971 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 972 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 973 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 974 | }; | ||
| 975 | |||
| 976 | input_engine->PreSetController(identifier); | ||
| 977 | return std::make_unique<InputFromCamera>(identifier, input_engine.get()); | ||
| 978 | } | ||
| 979 | |||
| 923 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) | 980 | InputFactory::InputFactory(std::shared_ptr<InputEngine> input_engine_) |
| 924 | : input_engine(std::move(input_engine_)) {} | 981 | : input_engine(std::move(input_engine_)) {} |
| 925 | 982 | ||
| @@ -928,6 +985,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 928 | if (params.Has("battery")) { | 985 | if (params.Has("battery")) { |
| 929 | return CreateBatteryDevice(params); | 986 | return CreateBatteryDevice(params); |
| 930 | } | 987 | } |
| 988 | if (params.Has("camera")) { | ||
| 989 | return CreateCameraDevice(params); | ||
| 990 | } | ||
| 931 | if (params.Has("button") && params.Has("axis")) { | 991 | if (params.Has("button") && params.Has("axis")) { |
| 932 | return CreateTriggerDevice(params); | 992 | return CreateTriggerDevice(params); |
| 933 | } | 993 | } |
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h index 6ebe0dbf5..4410a8415 100644 --- a/src/input_common/input_poller.h +++ b/src/input_common/input_poller.h | |||
| @@ -211,6 +211,17 @@ private: | |||
| 211 | */ | 211 | */ |
| 212 | std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params); | 212 | std::unique_ptr<Common::Input::InputDevice> CreateMotionDevice(Common::ParamPackage params); |
| 213 | 213 | ||
| 214 | /** | ||
| 215 | * Creates a camera device from the parameters given. | ||
| 216 | * @param params contains parameters for creating the device: | ||
| 217 | * - "guid": text string for identifying controllers | ||
| 218 | * - "port": port of the connected device | ||
| 219 | * - "pad": slot of the connected controller | ||
| 220 | * @returns a unique input device with the parameters specified | ||
| 221 | */ | ||
| 222 | std::unique_ptr<Common::Input::InputDevice> CreateCameraDevice( | ||
| 223 | const Common::ParamPackage& params); | ||
| 224 | |||
| 214 | std::shared_ptr<InputEngine> input_engine; | 225 | std::shared_ptr<InputEngine> input_engine; |
| 215 | }; | 226 | }; |
| 216 | } // namespace InputCommon | 227 | } // namespace InputCommon |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 21834fb6b..ca1cb9542 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | #include "common/input.h" | 6 | #include "common/input.h" |
| 7 | #include "common/param_package.h" | 7 | #include "common/param_package.h" |
| 8 | #include "input_common/drivers/camera.h" | ||
| 8 | #include "input_common/drivers/gc_adapter.h" | 9 | #include "input_common/drivers/gc_adapter.h" |
| 9 | #include "input_common/drivers/keyboard.h" | 10 | #include "input_common/drivers/keyboard.h" |
| 10 | #include "input_common/drivers/mouse.h" | 11 | #include "input_common/drivers/mouse.h" |
| @@ -78,6 +79,15 @@ struct InputSubsystem::Impl { | |||
| 78 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(), | 79 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(tas_input->GetEngineName(), |
| 79 | tas_output_factory); | 80 | tas_output_factory); |
| 80 | 81 | ||
| 82 | camera = std::make_shared<Camera>("camera"); | ||
| 83 | camera->SetMappingCallback(mapping_callback); | ||
| 84 | camera_input_factory = std::make_shared<InputFactory>(camera); | ||
| 85 | camera_output_factory = std::make_shared<OutputFactory>(camera); | ||
| 86 | Common::Input::RegisterFactory<Common::Input::InputDevice>(camera->GetEngineName(), | ||
| 87 | camera_input_factory); | ||
| 88 | Common::Input::RegisterFactory<Common::Input::OutputDevice>(camera->GetEngineName(), | ||
| 89 | camera_output_factory); | ||
| 90 | |||
| 81 | #ifdef HAVE_SDL2 | 91 | #ifdef HAVE_SDL2 |
| 82 | sdl = std::make_shared<SDLDriver>("sdl"); | 92 | sdl = std::make_shared<SDLDriver>("sdl"); |
| 83 | sdl->SetMappingCallback(mapping_callback); | 93 | sdl->SetMappingCallback(mapping_callback); |
| @@ -317,6 +327,7 @@ struct InputSubsystem::Impl { | |||
| 317 | std::shared_ptr<TouchScreen> touch_screen; | 327 | std::shared_ptr<TouchScreen> touch_screen; |
| 318 | std::shared_ptr<TasInput::Tas> tas_input; | 328 | std::shared_ptr<TasInput::Tas> tas_input; |
| 319 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; | 329 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; |
| 330 | std::shared_ptr<Camera> camera; | ||
| 320 | 331 | ||
| 321 | std::shared_ptr<InputFactory> keyboard_factory; | 332 | std::shared_ptr<InputFactory> keyboard_factory; |
| 322 | std::shared_ptr<InputFactory> mouse_factory; | 333 | std::shared_ptr<InputFactory> mouse_factory; |
| @@ -324,12 +335,14 @@ struct InputSubsystem::Impl { | |||
| 324 | std::shared_ptr<InputFactory> touch_screen_factory; | 335 | std::shared_ptr<InputFactory> touch_screen_factory; |
| 325 | std::shared_ptr<InputFactory> udp_client_input_factory; | 336 | std::shared_ptr<InputFactory> udp_client_input_factory; |
| 326 | std::shared_ptr<InputFactory> tas_input_factory; | 337 | std::shared_ptr<InputFactory> tas_input_factory; |
| 338 | std::shared_ptr<InputFactory> camera_input_factory; | ||
| 327 | 339 | ||
| 328 | std::shared_ptr<OutputFactory> keyboard_output_factory; | 340 | std::shared_ptr<OutputFactory> keyboard_output_factory; |
| 329 | std::shared_ptr<OutputFactory> mouse_output_factory; | 341 | std::shared_ptr<OutputFactory> mouse_output_factory; |
| 330 | std::shared_ptr<OutputFactory> gcadapter_output_factory; | 342 | std::shared_ptr<OutputFactory> gcadapter_output_factory; |
| 331 | std::shared_ptr<OutputFactory> udp_client_output_factory; | 343 | std::shared_ptr<OutputFactory> udp_client_output_factory; |
| 332 | std::shared_ptr<OutputFactory> tas_output_factory; | 344 | std::shared_ptr<OutputFactory> tas_output_factory; |
| 345 | std::shared_ptr<OutputFactory> camera_output_factory; | ||
| 333 | 346 | ||
| 334 | #ifdef HAVE_SDL2 | 347 | #ifdef HAVE_SDL2 |
| 335 | std::shared_ptr<SDLDriver> sdl; | 348 | std::shared_ptr<SDLDriver> sdl; |
| @@ -382,6 +395,14 @@ const TasInput::Tas* InputSubsystem::GetTas() const { | |||
| 382 | return impl->tas_input.get(); | 395 | return impl->tas_input.get(); |
| 383 | } | 396 | } |
| 384 | 397 | ||
| 398 | Camera* InputSubsystem::GetCamera() { | ||
| 399 | return impl->camera.get(); | ||
| 400 | } | ||
| 401 | |||
| 402 | const Camera* InputSubsystem::GetCamera() const { | ||
| 403 | return impl->camera.get(); | ||
| 404 | } | ||
| 405 | |||
| 385 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { | 406 | std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { |
| 386 | return impl->GetInputDevices(); | 407 | return impl->GetInputDevices(); |
| 387 | } | 408 | } |
diff --git a/src/input_common/main.h b/src/input_common/main.h index 147c310c4..b756bb5c6 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -30,6 +30,7 @@ enum Values : int; | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | namespace InputCommon { | 32 | namespace InputCommon { |
| 33 | class Camera; | ||
| 33 | class Keyboard; | 34 | class Keyboard; |
| 34 | class Mouse; | 35 | class Mouse; |
| 35 | class TouchScreen; | 36 | class TouchScreen; |
| @@ -92,9 +93,15 @@ public: | |||
| 92 | /// Retrieves the underlying tas input device. | 93 | /// Retrieves the underlying tas input device. |
| 93 | [[nodiscard]] TasInput::Tas* GetTas(); | 94 | [[nodiscard]] TasInput::Tas* GetTas(); |
| 94 | 95 | ||
| 95 | /// Retrieves the underlying tas input device. | 96 | /// Retrieves the underlying tas input device. |
| 96 | [[nodiscard]] const TasInput::Tas* GetTas() const; | 97 | [[nodiscard]] const TasInput::Tas* GetTas() const; |
| 97 | 98 | ||
| 99 | /// Retrieves the underlying camera input device. | ||
| 100 | [[nodiscard]] Camera* GetCamera(); | ||
| 101 | |||
| 102 | /// Retrieves the underlying camera input device. | ||
| 103 | [[nodiscard]] const Camera* GetCamera() const; | ||
| 104 | |||
| 98 | /** | 105 | /** |
| 99 | * Returns all available input devices that this Factory can create a new device with. | 106 | * Returns all available input devices that this Factory can create a new device with. |
| 100 | * Each returned ParamPackage should have a `display` field used for display, a `engine` field | 107 | * Each returned ParamPackage should have a `display` field used for display, a `engine` field |