diff options
| -rw-r--r-- | src/input_common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/input_common/drivers/android.cpp | 48 | ||||
| -rw-r--r-- | src/input_common/drivers/android.h | 54 | ||||
| -rw-r--r-- | src/input_common/input_mapping.cpp | 3 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 22 | ||||
| -rw-r--r-- | src/input_common/main.h | 7 |
6 files changed, 136 insertions, 0 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index d2fbea488..d0a71a15b 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | # SPDX-License-Identifier: GPL-2.0-or-later | 2 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | add_library(input_common STATIC | 4 | add_library(input_common STATIC |
| 5 | drivers/android.cpp | ||
| 6 | drivers/android.h | ||
| 5 | drivers/camera.cpp | 7 | drivers/camera.cpp |
| 6 | drivers/camera.h | 8 | drivers/camera.h |
| 7 | drivers/keyboard.cpp | 9 | drivers/keyboard.cpp |
diff --git a/src/input_common/drivers/android.cpp b/src/input_common/drivers/android.cpp new file mode 100644 index 000000000..b6a03fdc0 --- /dev/null +++ b/src/input_common/drivers/android.cpp | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "input_common/drivers/android.h" | ||
| 5 | |||
| 6 | namespace InputCommon { | ||
| 7 | |||
| 8 | Android::Android(std::string input_engine_) : InputEngine(std::move(input_engine_)) {} | ||
| 9 | |||
| 10 | void Android::RegisterController(std::size_t controller_number) { | ||
| 11 | PreSetController(GetIdentifier(controller_number)); | ||
| 12 | } | ||
| 13 | |||
| 14 | void Android::SetButtonState(std::size_t controller_number, int button_id, bool value) { | ||
| 15 | const auto identifier = GetIdentifier(controller_number); | ||
| 16 | SetButton(identifier, button_id, value); | ||
| 17 | } | ||
| 18 | |||
| 19 | void Android::SetAxisState(std::size_t controller_number, int axis_id, float value) { | ||
| 20 | const auto identifier = GetIdentifier(controller_number); | ||
| 21 | SetAxis(identifier, axis_id, value); | ||
| 22 | } | ||
| 23 | |||
| 24 | void Android::SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x, | ||
| 25 | float gyro_y, float gyro_z, float accel_x, float accel_y, | ||
| 26 | float accel_z) { | ||
| 27 | const auto identifier = GetIdentifier(controller_number); | ||
| 28 | const BasicMotion motion_data{ | ||
| 29 | .gyro_x = gyro_x, | ||
| 30 | .gyro_y = gyro_y, | ||
| 31 | .gyro_z = gyro_z, | ||
| 32 | .accel_x = accel_x, | ||
| 33 | .accel_y = accel_y, | ||
| 34 | .accel_z = accel_z, | ||
| 35 | .delta_timestamp = delta_timestamp, | ||
| 36 | }; | ||
| 37 | SetMotion(identifier, 0, motion_data); | ||
| 38 | } | ||
| 39 | |||
| 40 | PadIdentifier Android::GetIdentifier(std::size_t controller_number) const { | ||
| 41 | return { | ||
| 42 | .guid = Common::UUID{}, | ||
| 43 | .port = controller_number, | ||
| 44 | .pad = 0, | ||
| 45 | }; | ||
| 46 | } | ||
| 47 | |||
| 48 | } // namespace InputCommon | ||
diff --git a/src/input_common/drivers/android.h b/src/input_common/drivers/android.h new file mode 100644 index 000000000..3f01817f6 --- /dev/null +++ b/src/input_common/drivers/android.h | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include "input_common/input_engine.h" | ||
| 7 | |||
| 8 | namespace InputCommon { | ||
| 9 | |||
| 10 | /** | ||
| 11 | * A virtual controller that is always assigned to the game input | ||
| 12 | */ | ||
| 13 | class Android final : public InputEngine { | ||
| 14 | public: | ||
| 15 | explicit Android(std::string input_engine_); | ||
| 16 | |||
| 17 | /** | ||
| 18 | * Registers controller number to accept new inputs | ||
| 19 | * @param controller_number the controller number that will take this action | ||
| 20 | */ | ||
| 21 | void RegisterController(std::size_t controller_number); | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Sets the status of all buttons bound with the key to pressed | ||
| 25 | * @param controller_number the controller number that will take this action | ||
| 26 | * @param button_id the id of the button | ||
| 27 | * @param value indicates if the button is pressed or not | ||
| 28 | */ | ||
| 29 | void SetButtonState(std::size_t controller_number, int button_id, bool value); | ||
| 30 | |||
| 31 | /** | ||
| 32 | * Sets the status of a analog input to a specific player index | ||
| 33 | * @param controller_number the controller number that will take this action | ||
| 34 | * @param axis_id the id of the axis to move | ||
| 35 | * @param value the analog position of the axis | ||
| 36 | */ | ||
| 37 | void SetAxisState(std::size_t controller_number, int axis_id, float value); | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Sets the status of the motion sensor to a specific player index | ||
| 41 | * @param controller_number the controller number that will take this action | ||
| 42 | * @param delta_timestamp time passed since last reading | ||
| 43 | * @param gyro_x,gyro_y,gyro_z the gyro sensor readings | ||
| 44 | * @param accel_x,accel_y,accel_z the accelerometer reading | ||
| 45 | */ | ||
| 46 | void SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x, | ||
| 47 | float gyro_y, float gyro_z, float accel_x, float accel_y, float accel_z); | ||
| 48 | |||
| 49 | private: | ||
| 50 | /// Returns the correct identifier corresponding to the player index | ||
| 51 | PadIdentifier GetIdentifier(std::size_t controller_number) const; | ||
| 52 | }; | ||
| 53 | |||
| 54 | } // namespace InputCommon | ||
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 8c2ee4eb3..f1a1d7398 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp | |||
| @@ -210,6 +210,9 @@ bool MappingFactory::IsDriverValid(const MappingData& data) const { | |||
| 210 | if (data.engine == "analog_from_button") { | 210 | if (data.engine == "analog_from_button") { |
| 211 | return false; | 211 | return false; |
| 212 | } | 212 | } |
| 213 | if (data.engine == "virtual_gamepad") { | ||
| 214 | return false; | ||
| 215 | } | ||
| 213 | return true; | 216 | return true; |
| 214 | } | 217 | } |
| 215 | 218 | ||
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index c77fc04ee..f8749ebbf 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include <memory> | 4 | #include <memory> |
| 5 | #include "common/input.h" | 5 | #include "common/input.h" |
| 6 | #include "common/param_package.h" | 6 | #include "common/param_package.h" |
| 7 | #include "input_common/drivers/android.h" | ||
| 7 | #include "input_common/drivers/camera.h" | 8 | #include "input_common/drivers/camera.h" |
| 8 | #include "input_common/drivers/keyboard.h" | 9 | #include "input_common/drivers/keyboard.h" |
| 9 | #include "input_common/drivers/mouse.h" | 10 | #include "input_common/drivers/mouse.h" |
| @@ -78,6 +79,7 @@ struct InputSubsystem::Impl { | |||
| 78 | RegisterEngine("cemuhookudp", udp_client); | 79 | RegisterEngine("cemuhookudp", udp_client); |
| 79 | RegisterEngine("tas", tas_input); | 80 | RegisterEngine("tas", tas_input); |
| 80 | RegisterEngine("camera", camera); | 81 | RegisterEngine("camera", camera); |
| 82 | RegisterEngine("android", android); | ||
| 81 | RegisterEngine("virtual_amiibo", virtual_amiibo); | 83 | RegisterEngine("virtual_amiibo", virtual_amiibo); |
| 82 | RegisterEngine("virtual_gamepad", virtual_gamepad); | 84 | RegisterEngine("virtual_gamepad", virtual_gamepad); |
| 83 | #ifdef HAVE_SDL2 | 85 | #ifdef HAVE_SDL2 |
| @@ -109,6 +111,7 @@ struct InputSubsystem::Impl { | |||
| 109 | UnregisterEngine(udp_client); | 111 | UnregisterEngine(udp_client); |
| 110 | UnregisterEngine(tas_input); | 112 | UnregisterEngine(tas_input); |
| 111 | UnregisterEngine(camera); | 113 | UnregisterEngine(camera); |
| 114 | UnregisterEngine(android); | ||
| 112 | UnregisterEngine(virtual_amiibo); | 115 | UnregisterEngine(virtual_amiibo); |
| 113 | UnregisterEngine(virtual_gamepad); | 116 | UnregisterEngine(virtual_gamepad); |
| 114 | #ifdef HAVE_SDL2 | 117 | #ifdef HAVE_SDL2 |
| @@ -129,6 +132,8 @@ struct InputSubsystem::Impl { | |||
| 129 | devices.insert(devices.end(), keyboard_devices.begin(), keyboard_devices.end()); | 132 | devices.insert(devices.end(), keyboard_devices.begin(), keyboard_devices.end()); |
| 130 | auto mouse_devices = mouse->GetInputDevices(); | 133 | auto mouse_devices = mouse->GetInputDevices(); |
| 131 | devices.insert(devices.end(), mouse_devices.begin(), mouse_devices.end()); | 134 | devices.insert(devices.end(), mouse_devices.begin(), mouse_devices.end()); |
| 135 | auto android_devices = android->GetInputDevices(); | ||
| 136 | devices.insert(devices.end(), android_devices.begin(), android_devices.end()); | ||
| 132 | #ifdef HAVE_LIBUSB | 137 | #ifdef HAVE_LIBUSB |
| 133 | auto gcadapter_devices = gcadapter->GetInputDevices(); | 138 | auto gcadapter_devices = gcadapter->GetInputDevices(); |
| 134 | devices.insert(devices.end(), gcadapter_devices.begin(), gcadapter_devices.end()); | 139 | devices.insert(devices.end(), gcadapter_devices.begin(), gcadapter_devices.end()); |
| @@ -157,6 +162,9 @@ struct InputSubsystem::Impl { | |||
| 157 | if (engine == mouse->GetEngineName()) { | 162 | if (engine == mouse->GetEngineName()) { |
| 158 | return mouse; | 163 | return mouse; |
| 159 | } | 164 | } |
| 165 | if (engine == android->GetEngineName()) { | ||
| 166 | return android; | ||
| 167 | } | ||
| 160 | #ifdef HAVE_LIBUSB | 168 | #ifdef HAVE_LIBUSB |
| 161 | if (engine == gcadapter->GetEngineName()) { | 169 | if (engine == gcadapter->GetEngineName()) { |
| 162 | return gcadapter; | 170 | return gcadapter; |
| @@ -237,6 +245,9 @@ struct InputSubsystem::Impl { | |||
| 237 | if (engine == mouse->GetEngineName()) { | 245 | if (engine == mouse->GetEngineName()) { |
| 238 | return true; | 246 | return true; |
| 239 | } | 247 | } |
| 248 | if (engine == android->GetEngineName()) { | ||
| 249 | return true; | ||
| 250 | } | ||
| 240 | #ifdef HAVE_LIBUSB | 251 | #ifdef HAVE_LIBUSB |
| 241 | if (engine == gcadapter->GetEngineName()) { | 252 | if (engine == gcadapter->GetEngineName()) { |
| 242 | return true; | 253 | return true; |
| @@ -265,6 +276,7 @@ struct InputSubsystem::Impl { | |||
| 265 | void BeginConfiguration() { | 276 | void BeginConfiguration() { |
| 266 | keyboard->BeginConfiguration(); | 277 | keyboard->BeginConfiguration(); |
| 267 | mouse->BeginConfiguration(); | 278 | mouse->BeginConfiguration(); |
| 279 | android->BeginConfiguration(); | ||
| 268 | #ifdef HAVE_LIBUSB | 280 | #ifdef HAVE_LIBUSB |
| 269 | gcadapter->BeginConfiguration(); | 281 | gcadapter->BeginConfiguration(); |
| 270 | #endif | 282 | #endif |
| @@ -278,6 +290,7 @@ struct InputSubsystem::Impl { | |||
| 278 | void EndConfiguration() { | 290 | void EndConfiguration() { |
| 279 | keyboard->EndConfiguration(); | 291 | keyboard->EndConfiguration(); |
| 280 | mouse->EndConfiguration(); | 292 | mouse->EndConfiguration(); |
| 293 | android->EndConfiguration(); | ||
| 281 | #ifdef HAVE_LIBUSB | 294 | #ifdef HAVE_LIBUSB |
| 282 | gcadapter->EndConfiguration(); | 295 | gcadapter->EndConfiguration(); |
| 283 | #endif | 296 | #endif |
| @@ -308,6 +321,7 @@ struct InputSubsystem::Impl { | |||
| 308 | std::shared_ptr<TasInput::Tas> tas_input; | 321 | std::shared_ptr<TasInput::Tas> tas_input; |
| 309 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; | 322 | std::shared_ptr<CemuhookUDP::UDPClient> udp_client; |
| 310 | std::shared_ptr<Camera> camera; | 323 | std::shared_ptr<Camera> camera; |
| 324 | std::shared_ptr<Android> android; | ||
| 311 | std::shared_ptr<VirtualAmiibo> virtual_amiibo; | 325 | std::shared_ptr<VirtualAmiibo> virtual_amiibo; |
| 312 | std::shared_ptr<VirtualGamepad> virtual_gamepad; | 326 | std::shared_ptr<VirtualGamepad> virtual_gamepad; |
| 313 | 327 | ||
| @@ -373,6 +387,14 @@ const Camera* InputSubsystem::GetCamera() const { | |||
| 373 | return impl->camera.get(); | 387 | return impl->camera.get(); |
| 374 | } | 388 | } |
| 375 | 389 | ||
| 390 | Android* InputSubsystem::GetAndroid() { | ||
| 391 | return impl->android.get(); | ||
| 392 | } | ||
| 393 | |||
| 394 | const Android* InputSubsystem::GetAndroid() const { | ||
| 395 | return impl->android.get(); | ||
| 396 | } | ||
| 397 | |||
| 376 | VirtualAmiibo* InputSubsystem::GetVirtualAmiibo() { | 398 | VirtualAmiibo* InputSubsystem::GetVirtualAmiibo() { |
| 377 | return impl->virtual_amiibo.get(); | 399 | return impl->virtual_amiibo.get(); |
| 378 | } | 400 | } |
diff --git a/src/input_common/main.h b/src/input_common/main.h index d64a6cb4c..1d19019ee 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -29,6 +29,7 @@ enum Values : int; | |||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | namespace InputCommon { | 31 | namespace InputCommon { |
| 32 | class Android; | ||
| 32 | class Camera; | 33 | class Camera; |
| 33 | class Keyboard; | 34 | class Keyboard; |
| 34 | class Mouse; | 35 | class Mouse; |
| @@ -103,6 +104,12 @@ public: | |||
| 103 | /// Retrieves the underlying camera input device. | 104 | /// Retrieves the underlying camera input device. |
| 104 | [[nodiscard]] const Camera* GetCamera() const; | 105 | [[nodiscard]] const Camera* GetCamera() const; |
| 105 | 106 | ||
| 107 | /// Retrieves the underlying android input device. | ||
| 108 | [[nodiscard]] Android* GetAndroid(); | ||
| 109 | |||
| 110 | /// Retrieves the underlying android input device. | ||
| 111 | [[nodiscard]] const Android* GetAndroid() const; | ||
| 112 | |||
| 106 | /// Retrieves the underlying virtual amiibo input device. | 113 | /// Retrieves the underlying virtual amiibo input device. |
| 107 | [[nodiscard]] VirtualAmiibo* GetVirtualAmiibo(); | 114 | [[nodiscard]] VirtualAmiibo* GetVirtualAmiibo(); |
| 108 | 115 | ||