diff options
Diffstat (limited to 'src/input_common/drivers')
| -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/drivers/gc_adapter.cpp | 4 |
3 files changed, 104 insertions, 2 deletions
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/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 1ff296af5..f1184a5fa 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp | |||
| @@ -451,11 +451,11 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p | |||
| 451 | std::tuple{Settings::NativeButton::ZL, PadButton::TriggerL, PadAxes::TriggerLeft}, | 451 | std::tuple{Settings::NativeButton::ZL, PadButton::TriggerL, PadAxes::TriggerLeft}, |
| 452 | {Settings::NativeButton::ZR, PadButton::TriggerR, PadAxes::TriggerRight}, | 452 | {Settings::NativeButton::ZR, PadButton::TriggerR, PadAxes::TriggerRight}, |
| 453 | }; | 453 | }; |
| 454 | for (const auto& [switch_button, gcadapter_buton, gcadapter_axis] : switch_to_gcadapter_axis) { | 454 | for (const auto& [switch_button, gcadapter_button, gcadapter_axis] : switch_to_gcadapter_axis) { |
| 455 | Common::ParamPackage button_params{}; | 455 | Common::ParamPackage button_params{}; |
| 456 | button_params.Set("engine", GetEngineName()); | 456 | button_params.Set("engine", GetEngineName()); |
| 457 | button_params.Set("port", params.Get("port", 0)); | 457 | button_params.Set("port", params.Get("port", 0)); |
| 458 | button_params.Set("button", static_cast<s32>(gcadapter_buton)); | 458 | button_params.Set("button", static_cast<s32>(gcadapter_button)); |
| 459 | button_params.Set("axis", static_cast<s32>(gcadapter_axis)); | 459 | button_params.Set("axis", static_cast<s32>(gcadapter_axis)); |
| 460 | button_params.Set("threshold", 0.5f); | 460 | button_params.Set("threshold", 0.5f); |
| 461 | button_params.Set("range", 1.9f); | 461 | button_params.Set("range", 1.9f); |