summaryrefslogtreecommitdiff
path: root/src/input_common/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/drivers')
-rw-r--r--src/input_common/drivers/android.cpp48
-rw-r--r--src/input_common/drivers/android.h54
2 files changed, 102 insertions, 0 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
6namespace InputCommon {
7
8Android::Android(std::string input_engine_) : InputEngine(std::move(input_engine_)) {}
9
10void Android::RegisterController(std::size_t controller_number) {
11 PreSetController(GetIdentifier(controller_number));
12}
13
14void 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
19void 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
24void 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
40PadIdentifier 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
8namespace InputCommon {
9
10/**
11 * A virtual controller that is always assigned to the game input
12 */
13class Android final : public InputEngine {
14public:
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
49private:
50 /// Returns the correct identifier corresponding to the player index
51 PadIdentifier GetIdentifier(std::size_t controller_number) const;
52};
53
54} // namespace InputCommon