summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/android.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/drivers/android.h123
1 files changed, 103 insertions, 20 deletions
diff --git a/src/input_common/drivers/android.h b/src/input_common/drivers/android.h
index 3f01817f6..ac60e3598 100644
--- a/src/input_common/drivers/android.h
+++ b/src/input_common/drivers/android.h
@@ -3,6 +3,8 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <set>
7#include <jni.h>
6#include "input_common/input_engine.h" 8#include "input_common/input_engine.h"
7 9
8namespace InputCommon { 10namespace InputCommon {
@@ -15,40 +17,121 @@ public:
15 explicit Android(std::string input_engine_); 17 explicit Android(std::string input_engine_);
16 18
17 /** 19 /**
18 * Registers controller number to accept new inputs 20 * Registers controller number to accept new inputs.
19 * @param controller_number the controller number that will take this action 21 * @param j_input_device YuzuInputDevice object from the Android frontend to register.
20 */ 22 */
21 void RegisterController(std::size_t controller_number); 23 void RegisterController(jobject j_input_device);
22 24
23 /** 25 /**
24 * Sets the status of all buttons bound with the key to pressed 26 * Sets the status of a button on a specific controller.
25 * @param controller_number the controller number that will take this action 27 * @param guid 32 character hexadecimal string consisting of the controller's PID+VID.
26 * @param button_id the id of the button 28 * @param port Port determined by controller connection order.
27 * @param value indicates if the button is pressed or not 29 * @param button_id The Android Keycode corresponding to this event.
30 * @param value Whether the button is pressed or not.
28 */ 31 */
29 void SetButtonState(std::size_t controller_number, int button_id, bool value); 32 void SetButtonState(std::string guid, size_t port, int button_id, bool value);
30 33
31 /** 34 /**
32 * Sets the status of a analog input to a specific player index 35 * Sets the status of an axis on a specific controller.
33 * @param controller_number the controller number that will take this action 36 * @param guid 32 character hexadecimal string consisting of the controller's PID+VID.
34 * @param axis_id the id of the axis to move 37 * @param port Port determined by controller connection order.
35 * @param value the analog position of the axis 38 * @param axis_id The Android axis ID corresponding to this event.
39 * @param value Value along the given axis.
36 */ 40 */
37 void SetAxisState(std::size_t controller_number, int axis_id, float value); 41 void SetAxisPosition(std::string guid, size_t port, int axis_id, float value);
38 42
39 /** 43 /**
40 * Sets the status of the motion sensor to a specific player index 44 * Sets the status of the motion sensor on a specific controller
41 * @param controller_number the controller number that will take this action 45 * @param guid 32 character hexadecimal string consisting of the controller's PID+VID.
42 * @param delta_timestamp time passed since last reading 46 * @param port Port determined by controller connection order.
43 * @param gyro_x,gyro_y,gyro_z the gyro sensor readings 47 * @param delta_timestamp Time passed since the last read.
44 * @param accel_x,accel_y,accel_z the accelerometer reading 48 * @param gyro_x,gyro_y,gyro_z Gyro sensor readings.
49 * @param accel_x,accel_y,accel_z Accelerometer sensor readings.
45 */ 50 */
46 void SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x, 51 void SetMotionState(std::string guid, size_t port, u64 delta_timestamp, float gyro_x,
47 float gyro_y, float gyro_z, float accel_x, float accel_y, float accel_z); 52 float gyro_y, float gyro_z, float accel_x, float accel_y, float accel_z);
48 53
54 Common::Input::DriverResult SetVibration(
55 const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
56
57 bool IsVibrationEnabled(const PadIdentifier& identifier) override;
58
59 std::vector<Common::ParamPackage> GetInputDevices() const override;
60
61 /**
62 * Gets the axes reported by the YuzuInputDevice.
63 * @param env JNI environment pointer.
64 * @param j_device YuzuInputDevice from the Android frontend.
65 * @return Set of the axes reported by the underlying Android InputDevice
66 */
67 std::set<s32> GetDeviceAxes(JNIEnv* env, jobject& j_device) const;
68
69 Common::ParamPackage BuildParamPackageForAnalog(PadIdentifier identifier, int axis_x,
70 int axis_y) const;
71
72 Common::ParamPackage BuildAnalogParamPackageForButton(PadIdentifier identifier, s32 axis,
73 bool invert) const;
74
75 Common::ParamPackage BuildButtonParamPackageForButton(PadIdentifier identifier,
76 s32 button) const;
77
78 bool MatchVID(Common::UUID device, const std::vector<std::string>& vids) const;
79
80 AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;
81
82 ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override;
83
84 Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
85
49private: 86private:
87 std::unordered_map<PadIdentifier, jobject> input_devices;
88
50 /// Returns the correct identifier corresponding to the player index 89 /// Returns the correct identifier corresponding to the player index
51 PadIdentifier GetIdentifier(std::size_t controller_number) const; 90 PadIdentifier GetIdentifier(const std::string& guid, size_t port) const;
91
92 static constexpr s32 AXIS_X = 0;
93 static constexpr s32 AXIS_Y = 1;
94 static constexpr s32 AXIS_Z = 11;
95 static constexpr s32 AXIS_RX = 12;
96 static constexpr s32 AXIS_RY = 13;
97 static constexpr s32 AXIS_RZ = 14;
98 static constexpr s32 AXIS_HAT_X = 15;
99 static constexpr s32 AXIS_HAT_Y = 16;
100 static constexpr s32 AXIS_LTRIGGER = 17;
101 static constexpr s32 AXIS_RTRIGGER = 18;
102
103 static constexpr s32 KEYCODE_DPAD_UP = 19;
104 static constexpr s32 KEYCODE_DPAD_DOWN = 20;
105 static constexpr s32 KEYCODE_DPAD_LEFT = 21;
106 static constexpr s32 KEYCODE_DPAD_RIGHT = 22;
107 static constexpr s32 KEYCODE_BUTTON_A = 96;
108 static constexpr s32 KEYCODE_BUTTON_B = 97;
109 static constexpr s32 KEYCODE_BUTTON_X = 99;
110 static constexpr s32 KEYCODE_BUTTON_Y = 100;
111 static constexpr s32 KEYCODE_BUTTON_L1 = 102;
112 static constexpr s32 KEYCODE_BUTTON_R1 = 103;
113 static constexpr s32 KEYCODE_BUTTON_L2 = 104;
114 static constexpr s32 KEYCODE_BUTTON_R2 = 105;
115 static constexpr s32 KEYCODE_BUTTON_THUMBL = 106;
116 static constexpr s32 KEYCODE_BUTTON_THUMBR = 107;
117 static constexpr s32 KEYCODE_BUTTON_START = 108;
118 static constexpr s32 KEYCODE_BUTTON_SELECT = 109;
119 const std::vector<s32> keycode_ids{
120 KEYCODE_DPAD_UP, KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT,
121 KEYCODE_BUTTON_A, KEYCODE_BUTTON_B, KEYCODE_BUTTON_X, KEYCODE_BUTTON_Y,
122 KEYCODE_BUTTON_L1, KEYCODE_BUTTON_R1, KEYCODE_BUTTON_L2, KEYCODE_BUTTON_R2,
123 KEYCODE_BUTTON_THUMBL, KEYCODE_BUTTON_THUMBR, KEYCODE_BUTTON_START, KEYCODE_BUTTON_SELECT,
124 };
125
126 const std::string sony_vid{"054c"};
127 const std::string nintendo_vid{"057e"};
128 const std::string razer_vid{"1532"};
129 const std::string redmagic_vid{"3537"};
130 const std::string backbone_labs_vid{"358a"};
131 const std::vector<std::string> flipped_ab_vids{sony_vid, nintendo_vid, razer_vid, redmagic_vid,
132 backbone_labs_vid};
133 const std::vector<std::string> flipped_xy_vids{sony_vid, razer_vid, redmagic_vid,
134 backbone_labs_vid};
52}; 135};
53 136
54} // namespace InputCommon 137} // namespace InputCommon