summaryrefslogtreecommitdiffstats
path: root/src/input_common/drivers
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/drivers/android.cpp48
-rw-r--r--src/input_common/drivers/android.h54
-rw-r--r--src/input_common/drivers/gc_adapter.cpp4
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 @@
+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "input_common/drivers/android.h"
+
+namespace InputCommon {
+
+Android::Android(std::string input_engine_) : InputEngine(std::move(input_engine_)) {}
+
+void Android::RegisterController(std::size_t controller_number) {
+ PreSetController(GetIdentifier(controller_number));
+}
+
+void Android::SetButtonState(std::size_t controller_number, int button_id, bool value) {
+ const auto identifier = GetIdentifier(controller_number);
+ SetButton(identifier, button_id, value);
+}
+
+void Android::SetAxisState(std::size_t controller_number, int axis_id, float value) {
+ const auto identifier = GetIdentifier(controller_number);
+ SetAxis(identifier, axis_id, value);
+}
+
+void Android::SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x,
+ float gyro_y, float gyro_z, float accel_x, float accel_y,
+ float accel_z) {
+ const auto identifier = GetIdentifier(controller_number);
+ const BasicMotion motion_data{
+ .gyro_x = gyro_x,
+ .gyro_y = gyro_y,
+ .gyro_z = gyro_z,
+ .accel_x = accel_x,
+ .accel_y = accel_y,
+ .accel_z = accel_z,
+ .delta_timestamp = delta_timestamp,
+ };
+ SetMotion(identifier, 0, motion_data);
+}
+
+PadIdentifier Android::GetIdentifier(std::size_t controller_number) const {
+ return {
+ .guid = Common::UUID{},
+ .port = controller_number,
+ .pad = 0,
+ };
+}
+
+} // 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 @@
+// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include "input_common/input_engine.h"
+
+namespace InputCommon {
+
+/**
+ * A virtual controller that is always assigned to the game input
+ */
+class Android final : public InputEngine {
+public:
+ explicit Android(std::string input_engine_);
+
+ /**
+ * Registers controller number to accept new inputs
+ * @param controller_number the controller number that will take this action
+ */
+ void RegisterController(std::size_t controller_number);
+
+ /**
+ * Sets the status of all buttons bound with the key to pressed
+ * @param controller_number the controller number that will take this action
+ * @param button_id the id of the button
+ * @param value indicates if the button is pressed or not
+ */
+ void SetButtonState(std::size_t controller_number, int button_id, bool value);
+
+ /**
+ * Sets the status of a analog input to a specific player index
+ * @param controller_number the controller number that will take this action
+ * @param axis_id the id of the axis to move
+ * @param value the analog position of the axis
+ */
+ void SetAxisState(std::size_t controller_number, int axis_id, float value);
+
+ /**
+ * Sets the status of the motion sensor to a specific player index
+ * @param controller_number the controller number that will take this action
+ * @param delta_timestamp time passed since last reading
+ * @param gyro_x,gyro_y,gyro_z the gyro sensor readings
+ * @param accel_x,accel_y,accel_z the accelerometer reading
+ */
+ void SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x,
+ float gyro_y, float gyro_z, float accel_x, float accel_y, float accel_z);
+
+private:
+ /// Returns the correct identifier corresponding to the player index
+ PadIdentifier GetIdentifier(std::size_t controller_number) const;
+};
+
+} // 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
std::tuple{Settings::NativeButton::ZL, PadButton::TriggerL, PadAxes::TriggerLeft},
{Settings::NativeButton::ZR, PadButton::TriggerR, PadAxes::TriggerRight},
};
- for (const auto& [switch_button, gcadapter_buton, gcadapter_axis] : switch_to_gcadapter_axis) {
+ for (const auto& [switch_button, gcadapter_button, gcadapter_axis] : switch_to_gcadapter_axis) {
Common::ParamPackage button_params{};
button_params.Set("engine", GetEngineName());
button_params.Set("port", params.Get("port", 0));
- button_params.Set("button", static_cast<s32>(gcadapter_buton));
+ button_params.Set("button", static_cast<s32>(gcadapter_button));
button_params.Set("axis", static_cast<s32>(gcadapter_axis));
button_params.Set("threshold", 0.5f);
button_params.Set("range", 1.9f);