diff options
| author | 2021-11-03 22:35:45 -0600 | |
|---|---|---|
| committer | 2021-11-24 20:30:27 -0600 | |
| commit | 84c58666a4dbb6d46e132514e4d91437fb689fa0 (patch) | |
| tree | 4d6196522922374c927f9139bd22c28ea8cad279 /src/common/input.h | |
| parent | input_common: Fix motion from 3 axis (diff) | |
| download | yuzu-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.h | 34 |
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 | ||
| 16 | namespace Common::Input { | 16 | namespace Common::Input { |
| 17 | 17 | ||
| 18 | // Type of data that is expected to recieve or send | ||
| 18 | enum class InputType { | 19 | enum 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 | ||
| 33 | enum class BatteryLevel : u32 { | 35 | enum class BatteryLevel : u32 { |
| 34 | None, | 36 | None, |
| 35 | Empty, | 37 | Empty, |
| @@ -41,13 +43,17 @@ enum class BatteryLevel : u32 { | |||
| 41 | }; | 43 | }; |
| 42 | 44 | ||
| 43 | enum class PollingMode { | 45 | enum 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 | ||
| 51 | enum class VibrationError { | 57 | enum 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 | ||
| 58 | enum class PollingError { | 65 | enum 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 | ||
| 70 | struct AnalogProperties { | 78 | struct 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 | ||
| 78 | struct AnalogStatus { | 92 | struct 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 | ||
| 84 | struct ButtonStatus { | 99 | struct 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 | ||
| 92 | using BatteryStatus = BatteryLevel; | 108 | using BatteryStatus = BatteryLevel; |
| 93 | 109 | ||
| 110 | // Analog and digital joystick data | ||
| 94 | struct StickStatus { | 111 | struct 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 | ||
| 104 | struct TriggerStatus { | 122 | struct 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 | ||
| 110 | struct MotionSensor { | 129 | struct 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 | ||
| 116 | struct MotionStatus { | 136 | struct 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 | ||
| 127 | struct TouchStatus { | 148 | struct 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 | ||
| 134 | struct BodyColorStatus { | 156 | struct BodyColorStatus { |
| 135 | u32 body{}; | 157 | u32 body{}; |
| 136 | u32 buttons{}; | 158 | u32 buttons{}; |
| 137 | }; | 159 | }; |
| 138 | 160 | ||
| 161 | // HD rumble data | ||
| 139 | struct VibrationStatus { | 162 | struct 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 | ||
| 147 | struct LedStatus { | 171 | struct 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 | ||
| 154 | struct CallbackStatus { | 179 | struct 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 | ||
| 167 | struct InputCallback { | 193 | struct 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); |