summaryrefslogtreecommitdiff
path: root/src/common/input.h
diff options
context:
space:
mode:
authorGravatar german772021-11-03 22:35:45 -0600
committerGravatar Narr the Reg2021-11-24 20:30:27 -0600
commit84c58666a4dbb6d46e132514e4d91437fb689fa0 (patch)
tree4d6196522922374c927f9139bd22c28ea8cad279 /src/common/input.h
parentinput_common: Fix motion from 3 axis (diff)
downloadyuzu-84c58666a4dbb6d46e132514e4d91437fb689fa0.tar.gz
yuzu-84c58666a4dbb6d46e132514e4d91437fb689fa0.tar.xz
yuzu-84c58666a4dbb6d46e132514e4d91437fb689fa0.zip
config: Cleanup and documentation
Diffstat (limited to 'src/common/input.h')
-rw-r--r--src/common/input.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/common/input.h b/src/common/input.h
index f21872b0a..d997853c6 100644
--- a/src/common/input.h
+++ b/src/common/input.h
@@ -15,6 +15,7 @@
15 15
16namespace Common::Input { 16namespace Common::Input {
17 17
18// Type of data that is expected to recieve or send
18enum class InputType { 19enum class InputType {
19 None, 20 None,
20 Battery, 21 Battery,
@@ -30,6 +31,7 @@ enum class InputType {
30 Ir, 31 Ir,
31}; 32};
32 33
34// Internal battery charge level
33enum class BatteryLevel : u32 { 35enum class BatteryLevel : u32 {
34 None, 36 None,
35 Empty, 37 Empty,
@@ -41,13 +43,17 @@ enum class BatteryLevel : u32 {
41}; 43};
42 44
43enum class PollingMode { 45enum class PollingMode {
46 // Constant polling of buttons, analogs and motion data
44 Active, 47 Active,
48 // Only update on button change, digital analogs
45 Pasive, 49 Pasive,
46 Camera, 50 // Enable near field communication polling
47 NCF, 51 NFC,
52 // Enable infrared camera polling
48 IR, 53 IR,
49}; 54};
50 55
56// Vibration reply from the controller
51enum class VibrationError { 57enum class VibrationError {
52 None, 58 None,
53 NotSupported, 59 NotSupported,
@@ -55,6 +61,7 @@ enum class VibrationError {
55 Unknown, 61 Unknown,
56}; 62};
57 63
64// Polling mode reply from the controller
58enum class PollingError { 65enum class PollingError {
59 None, 66 None,
60 NotSupported, 67 NotSupported,
@@ -67,20 +74,28 @@ enum class VibrationAmplificationType {
67 Exponential, 74 Exponential,
68}; 75};
69 76
77// Analog properties for calibration
70struct AnalogProperties { 78struct AnalogProperties {
79 // Anything below this value will be detected as zero
71 float deadzone{}; 80 float deadzone{};
81 // Anyting above this values will be detected as one
72 float range{1.0f}; 82 float range{1.0f};
83 // Minimum value to be detected as active
73 float threshold{0.5f}; 84 float threshold{0.5f};
85 // Drift correction applied to the raw data
74 float offset{}; 86 float offset{};
87 // Invert direction of the sensor data
75 bool inverted{}; 88 bool inverted{};
76}; 89};
77 90
91// Single analog sensor data
78struct AnalogStatus { 92struct AnalogStatus {
79 float value{}; 93 float value{};
80 float raw_value{}; 94 float raw_value{};
81 AnalogProperties properties{}; 95 AnalogProperties properties{};
82}; 96};
83 97
98// Button data
84struct ButtonStatus { 99struct ButtonStatus {
85 Common::UUID uuid{}; 100 Common::UUID uuid{};
86 bool value{}; 101 bool value{};
@@ -89,8 +104,10 @@ struct ButtonStatus {
89 bool locked{}; 104 bool locked{};
90}; 105};
91 106
107// Internal battery data
92using BatteryStatus = BatteryLevel; 108using BatteryStatus = BatteryLevel;
93 109
110// Analog and digital joystick data
94struct StickStatus { 111struct StickStatus {
95 Common::UUID uuid{}; 112 Common::UUID uuid{};
96 AnalogStatus x{}; 113 AnalogStatus x{};
@@ -101,18 +118,21 @@ struct StickStatus {
101 bool down{}; 118 bool down{};
102}; 119};
103 120
121// Analog and digital trigger data
104struct TriggerStatus { 122struct TriggerStatus {
105 Common::UUID uuid{}; 123 Common::UUID uuid{};
106 AnalogStatus analog{}; 124 AnalogStatus analog{};
107 ButtonStatus pressed{}; 125 ButtonStatus pressed{};
108}; 126};
109 127
128// 3D vector representing motion input
110struct MotionSensor { 129struct MotionSensor {
111 AnalogStatus x{}; 130 AnalogStatus x{};
112 AnalogStatus y{}; 131 AnalogStatus y{};
113 AnalogStatus z{}; 132 AnalogStatus z{};
114}; 133};
115 134
135// Motion data used to calculate controller orientation
116struct MotionStatus { 136struct MotionStatus {
117 // Gyroscope vector measurement in radians/s. 137 // Gyroscope vector measurement in radians/s.
118 MotionSensor gyro{}; 138 MotionSensor gyro{};
@@ -124,6 +144,7 @@ struct MotionStatus {
124 bool force_update{}; 144 bool force_update{};
125}; 145};
126 146
147// Data of a single point on a touch screen
127struct TouchStatus { 148struct TouchStatus {
128 ButtonStatus pressed{}; 149 ButtonStatus pressed{};
129 AnalogStatus x{}; 150 AnalogStatus x{};
@@ -131,11 +152,13 @@ struct TouchStatus {
131 int id{}; 152 int id{};
132}; 153};
133 154
155// Physical controller color in RGB format
134struct BodyColorStatus { 156struct BodyColorStatus {
135 u32 body{}; 157 u32 body{};
136 u32 buttons{}; 158 u32 buttons{};
137}; 159};
138 160
161// HD rumble data
139struct VibrationStatus { 162struct VibrationStatus {
140 f32 low_amplitude{}; 163 f32 low_amplitude{};
141 f32 low_frequency{}; 164 f32 low_frequency{};
@@ -144,6 +167,7 @@ struct VibrationStatus {
144 VibrationAmplificationType type; 167 VibrationAmplificationType type;
145}; 168};
146 169
170// Physical controller LED pattern
147struct LedStatus { 171struct LedStatus {
148 bool led_1{}; 172 bool led_1{};
149 bool led_2{}; 173 bool led_2{};
@@ -151,6 +175,7 @@ struct LedStatus {
151 bool led_4{}; 175 bool led_4{};
152}; 176};
153 177
178// Callback data consisting of an input type and the equivalent data status
154struct CallbackStatus { 179struct CallbackStatus {
155 InputType type{InputType::None}; 180 InputType type{InputType::None};
156 ButtonStatus button_status{}; 181 ButtonStatus button_status{};
@@ -164,6 +189,7 @@ struct CallbackStatus {
164 VibrationStatus vibration_status{}; 189 VibrationStatus vibration_status{};
165}; 190};
166 191
192// Triggered once every input change
167struct InputCallback { 193struct InputCallback {
168 std::function<void(CallbackStatus)> on_change; 194 std::function<void(CallbackStatus)> on_change;
169}; 195};
@@ -178,15 +204,17 @@ public:
178 return; 204 return;
179 } 205 }
180 206
181 // Force input device to update data regarless of the current state 207 // Force input device to update data regardless of the current state
182 virtual void ForceUpdate() { 208 virtual void ForceUpdate() {
183 return; 209 return;
184 } 210 }
185 211
212 // Sets the function to be triggered when input changes
186 void SetCallback(InputCallback callback_) { 213 void SetCallback(InputCallback callback_) {
187 callback = std::move(callback_); 214 callback = std::move(callback_);
188 } 215 }
189 216
217 // Triggers the function set in the callback
190 void TriggerOnChange(CallbackStatus status) { 218 void TriggerOnChange(CallbackStatus status) {
191 if (callback.on_change) { 219 if (callback.on_change) {
192 callback.on_change(status); 220 callback.on_change(status);