diff options
| author | 2021-10-17 00:33:00 -0500 | |
|---|---|---|
| committer | 2021-11-24 20:30:24 -0600 | |
| commit | 72e5920240381cbe775dc38fcdff88cf46b55101 (patch) | |
| tree | 3f981ca452357b19ae104fdde3692c8ad4a3bf0f | |
| parent | kraken: Fix errors from rebase and format files (diff) | |
| download | yuzu-72e5920240381cbe775dc38fcdff88cf46b55101.tar.gz yuzu-72e5920240381cbe775dc38fcdff88cf46b55101.tar.xz yuzu-72e5920240381cbe775dc38fcdff88cf46b55101.zip | |
core/hid: Documment some files
| -rw-r--r-- | src/core/hid/emulated_console.h | 69 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.h | 148 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.cpp | 16 | ||||
| -rw-r--r-- | src/core/hid/emulated_devices.h | 84 |
4 files changed, 265 insertions, 52 deletions
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h index d9e275042..7d6cf9506 100644 --- a/src/core/hid/emulated_console.h +++ b/src/core/hid/emulated_console.h | |||
| @@ -38,9 +38,10 @@ struct TouchFinger { | |||
| 38 | Common::Point<float> position{}; | 38 | Common::Point<float> position{}; |
| 39 | u32_le id{}; | 39 | u32_le id{}; |
| 40 | bool pressed{}; | 40 | bool pressed{}; |
| 41 | Core::HID::TouchAttribute attribute{}; | 41 | TouchAttribute attribute{}; |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | // Contains all motion related data that is used on the services | ||
| 44 | struct ConsoleMotion { | 45 | struct ConsoleMotion { |
| 45 | bool is_at_rest{}; | 46 | bool is_at_rest{}; |
| 46 | Common::Vec3f accel{}; | 47 | Common::Vec3f accel{}; |
| @@ -57,7 +58,7 @@ struct ConsoleStatus { | |||
| 57 | ConsoleMotionValues motion_values{}; | 58 | ConsoleMotionValues motion_values{}; |
| 58 | TouchValues touch_values{}; | 59 | TouchValues touch_values{}; |
| 59 | 60 | ||
| 60 | // Data for Nintendo devices; | 61 | // Data for HID services |
| 61 | ConsoleMotion motion_state{}; | 62 | ConsoleMotion motion_state{}; |
| 62 | TouchFingerState touch_state{}; | 63 | TouchFingerState touch_state{}; |
| 63 | }; | 64 | }; |
| @@ -75,52 +76,90 @@ struct ConsoleUpdateCallback { | |||
| 75 | class EmulatedConsole { | 76 | class EmulatedConsole { |
| 76 | public: | 77 | public: |
| 77 | /** | 78 | /** |
| 78 | * TODO: Write description | 79 | * Contains all input data related to the console like motion and touch input |
| 79 | * | ||
| 80 | * @param npad_id_type | ||
| 81 | */ | 80 | */ |
| 82 | explicit EmulatedConsole(); | 81 | EmulatedConsole(); |
| 83 | ~EmulatedConsole(); | 82 | ~EmulatedConsole(); |
| 84 | 83 | ||
| 85 | YUZU_NON_COPYABLE(EmulatedConsole); | 84 | YUZU_NON_COPYABLE(EmulatedConsole); |
| 86 | YUZU_NON_MOVEABLE(EmulatedConsole); | 85 | YUZU_NON_MOVEABLE(EmulatedConsole); |
| 87 | 86 | ||
| 88 | void ReloadFromSettings(); | 87 | /// Removes all callbacks created from input devices |
| 89 | void ReloadInput(); | ||
| 90 | void UnloadInput(); | 88 | void UnloadInput(); |
| 91 | 89 | ||
| 90 | /// Sets the emulated console into configuring mode. Locking all HID service events from being | ||
| 91 | /// moddified | ||
| 92 | void EnableConfiguration(); | 92 | void EnableConfiguration(); |
| 93 | |||
| 94 | /// Returns the emulated console to the normal behaivour | ||
| 93 | void DisableConfiguration(); | 95 | void DisableConfiguration(); |
| 96 | |||
| 97 | /// Returns true if the emulated console is on configuring mode | ||
| 94 | bool IsConfiguring() const; | 98 | bool IsConfiguring() const; |
| 99 | |||
| 100 | /// Reload all input devices | ||
| 101 | void ReloadInput(); | ||
| 102 | |||
| 103 | /// Overrides current mapped devices with the stored configuration and reloads all input devices | ||
| 104 | void ReloadFromSettings(); | ||
| 105 | |||
| 106 | /// Saves the current mapped configuration | ||
| 95 | void SaveCurrentConfig(); | 107 | void SaveCurrentConfig(); |
| 108 | |||
| 109 | /// Reverts any mapped changes made that weren't saved | ||
| 96 | void RestoreConfig(); | 110 | void RestoreConfig(); |
| 97 | 111 | ||
| 112 | // Returns the current mapped motion device | ||
| 98 | Common::ParamPackage GetMotionParam() const; | 113 | Common::ParamPackage GetMotionParam() const; |
| 99 | 114 | ||
| 115 | /** | ||
| 116 | * Updates the current mapped motion device | ||
| 117 | * @param ParamPackage with controller data to be mapped | ||
| 118 | */ | ||
| 100 | void SetMotionParam(Common::ParamPackage param); | 119 | void SetMotionParam(Common::ParamPackage param); |
| 101 | 120 | ||
| 121 | /// Returns the latest status of motion input from the console with parameters | ||
| 102 | ConsoleMotionValues GetMotionValues() const; | 122 | ConsoleMotionValues GetMotionValues() const; |
| 123 | |||
| 124 | /// Returns the latest status of touch input from the console with parameters | ||
| 103 | TouchValues GetTouchValues() const; | 125 | TouchValues GetTouchValues() const; |
| 104 | 126 | ||
| 127 | /// Returns the latest status of motion input from the console | ||
| 105 | ConsoleMotion GetMotion() const; | 128 | ConsoleMotion GetMotion() const; |
| 129 | |||
| 130 | /// Returns the latest status of touch input from the console | ||
| 106 | TouchFingerState GetTouch() const; | 131 | TouchFingerState GetTouch() const; |
| 107 | 132 | ||
| 133 | /** | ||
| 134 | * Adds a callback to the list of events | ||
| 135 | * @param ConsoleUpdateCallback that will be triggered | ||
| 136 | * @return an unique key corresponding to the callback index in the list | ||
| 137 | */ | ||
| 108 | int SetCallback(ConsoleUpdateCallback update_callback); | 138 | int SetCallback(ConsoleUpdateCallback update_callback); |
| 139 | |||
| 140 | /** | ||
| 141 | * Removes a callback from the list stopping any future events to this object | ||
| 142 | * @param Key corresponding to the callback index in the list | ||
| 143 | */ | ||
| 109 | void DeleteCallback(int key); | 144 | void DeleteCallback(int key); |
| 110 | 145 | ||
| 111 | private: | 146 | private: |
| 112 | /** | 147 | /** |
| 113 | * Sets the status of a button. Applies toggle properties to the output. | 148 | * Updates the motion status of the console |
| 114 | * | 149 | * @param A CallbackStatus containing gyro and accelerometer data |
| 115 | * @param A CallbackStatus and a button index number | ||
| 116 | */ | 150 | */ |
| 117 | void SetMotion(Input::CallbackStatus callback); | 151 | void SetMotion(Input::CallbackStatus callback); |
| 152 | |||
| 153 | /** | ||
| 154 | * Updates the touch status of the console | ||
| 155 | * @param callback: A CallbackStatus containing the touch position | ||
| 156 | * @param index: Finger ID to be updated | ||
| 157 | */ | ||
| 118 | void SetTouch(Input::CallbackStatus callback, std::size_t index); | 158 | void SetTouch(Input::CallbackStatus callback, std::size_t index); |
| 119 | 159 | ||
| 120 | /** | 160 | /** |
| 121 | * Triggers a callback that something has changed | 161 | * Triggers a callback that something has changed on the console status |
| 122 | * | 162 | * @param Input type of the event to trigger |
| 123 | * @param Input type of the trigger | ||
| 124 | */ | 163 | */ |
| 125 | void TriggerOnChange(ConsoleTriggerType type); | 164 | void TriggerOnChange(ConsoleTriggerType type); |
| 126 | 165 | ||
| @@ -136,6 +175,8 @@ private: | |||
| 136 | mutable std::mutex mutex; | 175 | mutable std::mutex mutex; |
| 137 | std::unordered_map<int, ConsoleUpdateCallback> callback_list; | 176 | std::unordered_map<int, ConsoleUpdateCallback> callback_list; |
| 138 | int last_callback_key = 0; | 177 | int last_callback_key = 0; |
| 178 | |||
| 179 | // Stores the current status of all console input | ||
| 139 | ConsoleStatus console; | 180 | ConsoleStatus console; |
| 140 | }; | 181 | }; |
| 141 | 182 | ||
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 322d2cab0..096fe1705 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h | |||
| @@ -87,7 +87,7 @@ struct ControllerStatus { | |||
| 87 | BatteryValues battery_values{}; | 87 | BatteryValues battery_values{}; |
| 88 | VibrationValues vibration_values{}; | 88 | VibrationValues vibration_values{}; |
| 89 | 89 | ||
| 90 | // Data for Nintendo devices | 90 | // Data for HID serices |
| 91 | NpadButtonState npad_button_state{}; | 91 | NpadButtonState npad_button_state{}; |
| 92 | DebugPadButton debug_pad_button_state{}; | 92 | DebugPadButton debug_pad_button_state{}; |
| 93 | AnalogSticks analog_stick_state{}; | 93 | AnalogSticks analog_stick_state{}; |
| @@ -118,9 +118,8 @@ struct ControllerUpdateCallback { | |||
| 118 | class EmulatedController { | 118 | class EmulatedController { |
| 119 | public: | 119 | public: |
| 120 | /** | 120 | /** |
| 121 | * TODO: Write description | 121 | * Contains all input data related to this controller. Like buttons, joysticks, motion. |
| 122 | * | 122 | * @param Npad id type for this specific controller |
| 123 | * @param npad_id_type | ||
| 124 | */ | 123 | */ |
| 125 | explicit EmulatedController(NpadIdType npad_id_type_); | 124 | explicit EmulatedController(NpadIdType npad_id_type_); |
| 126 | ~EmulatedController(); | 125 | ~EmulatedController(); |
| @@ -128,86 +127,197 @@ public: | |||
| 128 | YUZU_NON_COPYABLE(EmulatedController); | 127 | YUZU_NON_COPYABLE(EmulatedController); |
| 129 | YUZU_NON_MOVEABLE(EmulatedController); | 128 | YUZU_NON_MOVEABLE(EmulatedController); |
| 130 | 129 | ||
| 130 | /// Converts the controller type from settings to npad type | ||
| 131 | static NpadType MapSettingsTypeToNPad(Settings::ControllerType type); | 131 | static NpadType MapSettingsTypeToNPad(Settings::ControllerType type); |
| 132 | |||
| 133 | /// Converts npad type to the equivalent of controller type from settings | ||
| 132 | static Settings::ControllerType MapNPadToSettingsType(NpadType type); | 134 | static Settings::ControllerType MapNPadToSettingsType(NpadType type); |
| 133 | 135 | ||
| 134 | /// Gets the NpadIdType for this controller. | 136 | /// Gets the NpadIdType for this controller |
| 135 | NpadIdType GetNpadIdType() const; | 137 | NpadIdType GetNpadIdType() const; |
| 136 | 138 | ||
| 137 | /// Sets the NpadType for this controller. | 139 | /// Sets the NpadType for this controller |
| 138 | void SetNpadType(NpadType npad_type_); | 140 | void SetNpadType(NpadType npad_type_); |
| 139 | 141 | ||
| 140 | /// Gets the NpadType for this controller. | 142 | /// Gets the NpadType for this controller |
| 141 | NpadType GetNpadType() const; | 143 | NpadType GetNpadType() const; |
| 142 | 144 | ||
| 143 | /// Gets the NpadType for this controller. | 145 | /// Sets the connected status to true |
| 144 | LedPattern GetLedPattern() const; | ||
| 145 | |||
| 146 | void Connect(); | 146 | void Connect(); |
| 147 | |||
| 148 | /// Sets the connected status to false | ||
| 147 | void Disconnect(); | 149 | void Disconnect(); |
| 148 | 150 | ||
| 151 | /// Returns true if the controller has the connected status | ||
| 149 | bool IsConnected() const; | 152 | bool IsConnected() const; |
| 153 | |||
| 154 | /// Returns true if vibration is enabled | ||
| 150 | bool IsVibrationEnabled() const; | 155 | bool IsVibrationEnabled() const; |
| 151 | 156 | ||
| 152 | void ReloadFromSettings(); | 157 | /// Removes all callbacks created from input devices |
| 153 | void ReloadInput(); | ||
| 154 | void UnloadInput(); | 158 | void UnloadInput(); |
| 155 | 159 | ||
| 160 | /// Sets the emulated console into configuring mode. Locking all HID service events from being | ||
| 161 | /// moddified | ||
| 156 | void EnableConfiguration(); | 162 | void EnableConfiguration(); |
| 163 | |||
| 164 | /// Returns the emulated console to the normal behaivour | ||
| 157 | void DisableConfiguration(); | 165 | void DisableConfiguration(); |
| 166 | |||
| 167 | /// Returns true if the emulated device is on configuring mode | ||
| 158 | bool IsConfiguring() const; | 168 | bool IsConfiguring() const; |
| 169 | |||
| 170 | /// Reload all input devices | ||
| 171 | void ReloadInput(); | ||
| 172 | |||
| 173 | /// Overrides current mapped devices with the stored configuration and reloads all input devices | ||
| 174 | void ReloadFromSettings(); | ||
| 175 | |||
| 176 | /// Saves the current mapped configuration | ||
| 159 | void SaveCurrentConfig(); | 177 | void SaveCurrentConfig(); |
| 178 | |||
| 179 | /// Reverts any mapped changes made that weren't saved | ||
| 160 | void RestoreConfig(); | 180 | void RestoreConfig(); |
| 161 | 181 | ||
| 182 | /// Returns a vector of mapped devices from the mapped button and stick parameters | ||
| 162 | std::vector<Common::ParamPackage> GetMappedDevices() const; | 183 | std::vector<Common::ParamPackage> GetMappedDevices() const; |
| 163 | 184 | ||
| 185 | // Returns the current mapped button device | ||
| 164 | Common::ParamPackage GetButtonParam(std::size_t index) const; | 186 | Common::ParamPackage GetButtonParam(std::size_t index) const; |
| 187 | |||
| 188 | // Returns the current mapped stick device | ||
| 165 | Common::ParamPackage GetStickParam(std::size_t index) const; | 189 | Common::ParamPackage GetStickParam(std::size_t index) const; |
| 190 | |||
| 191 | // Returns the current mapped motion device | ||
| 166 | Common::ParamPackage GetMotionParam(std::size_t index) const; | 192 | Common::ParamPackage GetMotionParam(std::size_t index) const; |
| 167 | 193 | ||
| 194 | /** | ||
| 195 | * Updates the current mapped button device | ||
| 196 | * @param ParamPackage with controller data to be mapped | ||
| 197 | */ | ||
| 168 | void SetButtonParam(std::size_t index, Common::ParamPackage param); | 198 | void SetButtonParam(std::size_t index, Common::ParamPackage param); |
| 199 | |||
| 200 | /** | ||
| 201 | * Updates the current mapped stick device | ||
| 202 | * @param ParamPackage with controller data to be mapped | ||
| 203 | */ | ||
| 169 | void SetStickParam(std::size_t index, Common::ParamPackage param); | 204 | void SetStickParam(std::size_t index, Common::ParamPackage param); |
| 205 | |||
| 206 | /** | ||
| 207 | * Updates the current mapped motion device | ||
| 208 | * @param ParamPackage with controller data to be mapped | ||
| 209 | */ | ||
| 170 | void SetMotionParam(std::size_t index, Common::ParamPackage param); | 210 | void SetMotionParam(std::size_t index, Common::ParamPackage param); |
| 171 | 211 | ||
| 212 | /// Returns the latest button status from the controller with parameters | ||
| 172 | ButtonValues GetButtonsValues() const; | 213 | ButtonValues GetButtonsValues() const; |
| 214 | |||
| 215 | /// Returns the latest analog stick status from the controller with parameters | ||
| 173 | SticksValues GetSticksValues() const; | 216 | SticksValues GetSticksValues() const; |
| 217 | |||
| 218 | /// Returns the latest trigger status from the controller with parameters | ||
| 174 | TriggerValues GetTriggersValues() const; | 219 | TriggerValues GetTriggersValues() const; |
| 220 | |||
| 221 | /// Returns the latest motion status from the controller with parameters | ||
| 175 | ControllerMotionValues GetMotionValues() const; | 222 | ControllerMotionValues GetMotionValues() const; |
| 223 | |||
| 224 | /// Returns the latest color status from the controller with parameters | ||
| 176 | ColorValues GetColorsValues() const; | 225 | ColorValues GetColorsValues() const; |
| 226 | |||
| 227 | /// Returns the latest battery status from the controller with parameters | ||
| 177 | BatteryValues GetBatteryValues() const; | 228 | BatteryValues GetBatteryValues() const; |
| 178 | 229 | ||
| 230 | /// Returns the latest status of button input for the npad service | ||
| 179 | NpadButtonState GetNpadButtons() const; | 231 | NpadButtonState GetNpadButtons() const; |
| 232 | |||
| 233 | /// Returns the latest status of button input for the debug pad service | ||
| 180 | DebugPadButton GetDebugPadButtons() const; | 234 | DebugPadButton GetDebugPadButtons() const; |
| 235 | |||
| 236 | /// Returns the latest status of stick input from the mouse | ||
| 181 | AnalogSticks GetSticks() const; | 237 | AnalogSticks GetSticks() const; |
| 238 | |||
| 239 | /// Returns the latest status of trigger input from the mouse | ||
| 182 | NpadGcTriggerState GetTriggers() const; | 240 | NpadGcTriggerState GetTriggers() const; |
| 241 | |||
| 242 | /// Returns the latest status of motion input from the mouse | ||
| 183 | MotionState GetMotions() const; | 243 | MotionState GetMotions() const; |
| 244 | |||
| 245 | /// Returns the latest color value from the controller | ||
| 184 | ControllerColors GetColors() const; | 246 | ControllerColors GetColors() const; |
| 247 | |||
| 248 | /// Returns the latest battery status from the controller | ||
| 185 | BatteryLevelState GetBattery() const; | 249 | BatteryLevelState GetBattery() const; |
| 186 | 250 | ||
| 251 | /* | ||
| 252 | * Sends a specific vibration to the output device | ||
| 253 | * @return returns true if vibration had no errors | ||
| 254 | */ | ||
| 187 | bool SetVibration(std::size_t device_index, VibrationValue vibration); | 255 | bool SetVibration(std::size_t device_index, VibrationValue vibration); |
| 256 | |||
| 257 | /* | ||
| 258 | * Sends a small vibration to the output device | ||
| 259 | * @return returns true if SetVibration was successfull | ||
| 260 | */ | ||
| 188 | bool TestVibration(std::size_t device_index); | 261 | bool TestVibration(std::size_t device_index); |
| 189 | 262 | ||
| 263 | /// Returns the led pattern corresponding to this emulated controller | ||
| 264 | LedPattern GetLedPattern() const; | ||
| 265 | |||
| 266 | /// Asks the output device to change the player led pattern | ||
| 190 | void SetLedPattern(); | 267 | void SetLedPattern(); |
| 191 | 268 | ||
| 269 | /** | ||
| 270 | * Adds a callback to the list of events | ||
| 271 | * @param ConsoleUpdateCallback that will be triggered | ||
| 272 | * @return an unique key corresponding to the callback index in the list | ||
| 273 | */ | ||
| 192 | int SetCallback(ControllerUpdateCallback update_callback); | 274 | int SetCallback(ControllerUpdateCallback update_callback); |
| 275 | |||
| 276 | /** | ||
| 277 | * Removes a callback from the list stopping any future events to this object | ||
| 278 | * @param Key corresponding to the callback index in the list | ||
| 279 | */ | ||
| 193 | void DeleteCallback(int key); | 280 | void DeleteCallback(int key); |
| 194 | 281 | ||
| 195 | private: | 282 | private: |
| 196 | /** | 283 | /** |
| 197 | * Sets the status of a button. Applies toggle properties to the output. | 284 | * Updates the button status of the controller |
| 198 | * | 285 | * @param callback: A CallbackStatus containing the button status |
| 199 | * @param A CallbackStatus and a button index number | 286 | * @param index: Button ID of the to be updated |
| 200 | */ | 287 | */ |
| 201 | void SetButton(Input::CallbackStatus callback, std::size_t index); | 288 | void SetButton(Input::CallbackStatus callback, std::size_t index); |
| 289 | |||
| 290 | /** | ||
| 291 | * Updates the analog stick status of the controller | ||
| 292 | * @param callback: A CallbackStatus containing the analog stick status | ||
| 293 | * @param index: stick ID of the to be updated | ||
| 294 | */ | ||
| 202 | void SetStick(Input::CallbackStatus callback, std::size_t index); | 295 | void SetStick(Input::CallbackStatus callback, std::size_t index); |
| 296 | |||
| 297 | /** | ||
| 298 | * Updates the trigger status of the controller | ||
| 299 | * @param callback: A CallbackStatus containing the trigger status | ||
| 300 | * @param index: trigger ID of the to be updated | ||
| 301 | */ | ||
| 203 | void SetTrigger(Input::CallbackStatus callback, std::size_t index); | 302 | void SetTrigger(Input::CallbackStatus callback, std::size_t index); |
| 303 | |||
| 304 | /** | ||
| 305 | * Updates the motion status of the controller | ||
| 306 | * @param callback: A CallbackStatus containing gyro and accelerometer data | ||
| 307 | * @param index: motion ID of the to be updated | ||
| 308 | */ | ||
| 204 | void SetMotion(Input::CallbackStatus callback, std::size_t index); | 309 | void SetMotion(Input::CallbackStatus callback, std::size_t index); |
| 310 | |||
| 311 | /** | ||
| 312 | * Updates the battery status of the controller | ||
| 313 | * @param callback: A CallbackStatus containing the battery status | ||
| 314 | * @param index: Button ID of the to be updated | ||
| 315 | */ | ||
| 205 | void SetBattery(Input::CallbackStatus callback, std::size_t index); | 316 | void SetBattery(Input::CallbackStatus callback, std::size_t index); |
| 206 | 317 | ||
| 207 | /** | 318 | /** |
| 208 | * Triggers a callback that something has changed | 319 | * Triggers a callback that something has changed on the controller status |
| 209 | * | 320 | * @param Input type of the event to trigger |
| 210 | * @param Input type of the trigger | ||
| 211 | */ | 321 | */ |
| 212 | void TriggerOnChange(ControllerTriggerType type); | 322 | void TriggerOnChange(ControllerTriggerType type); |
| 213 | 323 | ||
| @@ -235,6 +345,8 @@ private: | |||
| 235 | mutable std::mutex mutex; | 345 | mutable std::mutex mutex; |
| 236 | std::unordered_map<int, ControllerUpdateCallback> callback_list; | 346 | std::unordered_map<int, ControllerUpdateCallback> callback_list; |
| 237 | int last_callback_key = 0; | 347 | int last_callback_key = 0; |
| 348 | |||
| 349 | // Stores the current status of all controller input | ||
| 238 | ControllerStatus controller; | 350 | ControllerStatus controller; |
| 239 | }; | 351 | }; |
| 240 | 352 | ||
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp index 3caf90714..54a753d8a 100644 --- a/src/core/hid/emulated_devices.cpp +++ b/src/core/hid/emulated_devices.cpp | |||
| @@ -114,7 +114,7 @@ Common::ParamPackage EmulatedDevices::GetMouseButtonParam(std::size_t index) con | |||
| 114 | return mouse_button_params[index]; | 114 | return mouse_button_params[index]; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | void EmulatedDevices::SetButtonParam(std::size_t index, Common::ParamPackage param) { | 117 | void EmulatedDevices::SetMouseButtonParam(std::size_t index, Common::ParamPackage param) { |
| 118 | if (index >= mouse_button_params.size()) { | 118 | if (index >= mouse_button_params.size()) { |
| 119 | return; | 119 | return; |
| 120 | } | 120 | } |
| @@ -132,7 +132,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz | |||
| 132 | auto& current_status = device_status.keyboard_values[index]; | 132 | auto& current_status = device_status.keyboard_values[index]; |
| 133 | current_status.toggle = new_status.toggle; | 133 | current_status.toggle = new_status.toggle; |
| 134 | 134 | ||
| 135 | // Update button status with current | 135 | // Update button status with current status |
| 136 | if (!current_status.toggle) { | 136 | if (!current_status.toggle) { |
| 137 | current_status.locked = false; | 137 | current_status.locked = false; |
| 138 | if (current_status.value != new_status.value) { | 138 | if (current_status.value != new_status.value) { |
| @@ -147,7 +147,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz | |||
| 147 | value_changed = true; | 147 | value_changed = true; |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | // Unlock button ready for next press | 150 | // Unlock button, ready for next press |
| 151 | if (!new_status.value && current_status.locked) { | 151 | if (!new_status.value && current_status.locked) { |
| 152 | current_status.locked = false; | 152 | current_status.locked = false; |
| 153 | } | 153 | } |
| @@ -168,7 +168,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz | |||
| 168 | // interface_status.keyboard_state.a.Assign(current_status.value); | 168 | // interface_status.keyboard_state.a.Assign(current_status.value); |
| 169 | // break; | 169 | // break; |
| 170 | // .... | 170 | // .... |
| 171 | //} | 171 | // } |
| 172 | 172 | ||
| 173 | TriggerOnChange(DeviceTriggerType::Keyboard); | 173 | TriggerOnChange(DeviceTriggerType::Keyboard); |
| 174 | } | 174 | } |
| @@ -303,6 +303,14 @@ void EmulatedDevices::SetMouseButton(Input::CallbackStatus callback, std::size_t | |||
| 303 | TriggerOnChange(DeviceTriggerType::Mouse); | 303 | TriggerOnChange(DeviceTriggerType::Mouse); |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | KeyboardValues EmulatedDevices::GetKeyboardValues() const { | ||
| 307 | return device_status.keyboard_values; | ||
| 308 | } | ||
| 309 | |||
| 310 | KeyboardModifierValues EmulatedDevices::GetKeyboardModdifierValues() const { | ||
| 311 | return device_status.keyboard_moddifier_values; | ||
| 312 | } | ||
| 313 | |||
| 306 | MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const { | 314 | MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const { |
| 307 | return device_status.mouse_button_values; | 315 | return device_status.mouse_button_values; |
| 308 | } | 316 | } |
diff --git a/src/core/hid/emulated_devices.h b/src/core/hid/emulated_devices.h index 6f728eff5..c6c19fae4 100644 --- a/src/core/hid/emulated_devices.h +++ b/src/core/hid/emulated_devices.h | |||
| @@ -45,7 +45,7 @@ struct DeviceStatus { | |||
| 45 | KeyboardModifierValues keyboard_moddifier_values{}; | 45 | KeyboardModifierValues keyboard_moddifier_values{}; |
| 46 | MouseButtonValues mouse_button_values{}; | 46 | MouseButtonValues mouse_button_values{}; |
| 47 | 47 | ||
| 48 | // Data for Nintendo devices | 48 | // Data for HID serices |
| 49 | KeyboardKey keyboard_state{}; | 49 | KeyboardKey keyboard_state{}; |
| 50 | KeyboardModifier keyboard_moddifier_state{}; | 50 | KeyboardModifier keyboard_moddifier_state{}; |
| 51 | MouseButton mouse_button_state{}; | 51 | MouseButton mouse_button_state{}; |
| @@ -65,58 +65,108 @@ struct InterfaceUpdateCallback { | |||
| 65 | class EmulatedDevices { | 65 | class EmulatedDevices { |
| 66 | public: | 66 | public: |
| 67 | /** | 67 | /** |
| 68 | * TODO: Write description | 68 | * Contains all input data related to external devices that aren't necesarily a controller |
| 69 | * | 69 | * like keyboard and mouse |
| 70 | * @param npad_id_type | ||
| 71 | */ | 70 | */ |
| 72 | explicit EmulatedDevices(); | 71 | EmulatedDevices(); |
| 73 | ~EmulatedDevices(); | 72 | ~EmulatedDevices(); |
| 74 | 73 | ||
| 75 | YUZU_NON_COPYABLE(EmulatedDevices); | 74 | YUZU_NON_COPYABLE(EmulatedDevices); |
| 76 | YUZU_NON_MOVEABLE(EmulatedDevices); | 75 | YUZU_NON_MOVEABLE(EmulatedDevices); |
| 77 | 76 | ||
| 78 | void ReloadFromSettings(); | 77 | /// Removes all callbacks created from input devices |
| 79 | void ReloadInput(); | ||
| 80 | void UnloadInput(); | 78 | void UnloadInput(); |
| 81 | 79 | ||
| 80 | /// Sets the emulated console into configuring mode. Locking all HID service events from being | ||
| 81 | /// moddified | ||
| 82 | void EnableConfiguration(); | 82 | void EnableConfiguration(); |
| 83 | |||
| 84 | /// Returns the emulated console to the normal behaivour | ||
| 83 | void DisableConfiguration(); | 85 | void DisableConfiguration(); |
| 86 | |||
| 87 | /// Returns true if the emulated device is on configuring mode | ||
| 84 | bool IsConfiguring() const; | 88 | bool IsConfiguring() const; |
| 89 | |||
| 90 | /// Reload all input devices | ||
| 91 | void ReloadInput(); | ||
| 92 | |||
| 93 | /// Overrides current mapped devices with the stored configuration and reloads all input devices | ||
| 94 | void ReloadFromSettings(); | ||
| 95 | |||
| 96 | /// Saves the current mapped configuration | ||
| 85 | void SaveCurrentConfig(); | 97 | void SaveCurrentConfig(); |
| 86 | void RestoreConfig(); | ||
| 87 | 98 | ||
| 88 | std::vector<Common::ParamPackage> GetMappedDevices() const; | 99 | /// Reverts any mapped changes made that weren't saved |
| 100 | void RestoreConfig(); | ||
| 89 | 101 | ||
| 102 | /// Returns the current mapped motion device | ||
| 90 | Common::ParamPackage GetMouseButtonParam(std::size_t index) const; | 103 | Common::ParamPackage GetMouseButtonParam(std::size_t index) const; |
| 91 | 104 | ||
| 92 | void SetButtonParam(std::size_t index, Common::ParamPackage param); | 105 | /** |
| 106 | * Updates the current mapped mouse button device | ||
| 107 | * @param ParamPackage with controller data to be mapped | ||
| 108 | */ | ||
| 109 | void SetMouseButtonParam(std::size_t index, Common::ParamPackage param); | ||
| 93 | 110 | ||
| 111 | /// Returns the latest status of button input from the keyboard with parameters | ||
| 94 | KeyboardValues GetKeyboardValues() const; | 112 | KeyboardValues GetKeyboardValues() const; |
| 113 | |||
| 114 | /// Returns the latest status of button input from the keyboard modifiers with parameters | ||
| 95 | KeyboardModifierValues GetKeyboardModdifierValues() const; | 115 | KeyboardModifierValues GetKeyboardModdifierValues() const; |
| 116 | |||
| 117 | /// Returns the latest status of button input from the mouse with parameters | ||
| 96 | MouseButtonValues GetMouseButtonsValues() const; | 118 | MouseButtonValues GetMouseButtonsValues() const; |
| 97 | 119 | ||
| 120 | /// Returns the latest status of button input from the keyboard | ||
| 98 | KeyboardKey GetKeyboard() const; | 121 | KeyboardKey GetKeyboard() const; |
| 122 | |||
| 123 | /// Returns the latest status of button input from the keyboard modifiers | ||
| 99 | KeyboardModifier GetKeyboardModifier() const; | 124 | KeyboardModifier GetKeyboardModifier() const; |
| 125 | |||
| 126 | /// Returns the latest status of button input from the mouse | ||
| 100 | MouseButton GetMouseButtons() const; | 127 | MouseButton GetMouseButtons() const; |
| 128 | |||
| 129 | /// Returns the latest mouse coordinates | ||
| 101 | MousePosition GetMousePosition() const; | 130 | MousePosition GetMousePosition() const; |
| 102 | 131 | ||
| 132 | /** | ||
| 133 | * Adds a callback to the list of events | ||
| 134 | * @param ConsoleUpdateCallback that will be triggered | ||
| 135 | * @return an unique key corresponding to the callback index in the list | ||
| 136 | */ | ||
| 103 | int SetCallback(InterfaceUpdateCallback update_callback); | 137 | int SetCallback(InterfaceUpdateCallback update_callback); |
| 138 | |||
| 139 | /** | ||
| 140 | * Removes a callback from the list stopping any future events to this object | ||
| 141 | * @param Key corresponding to the callback index in the list | ||
| 142 | */ | ||
| 104 | void DeleteCallback(int key); | 143 | void DeleteCallback(int key); |
| 105 | 144 | ||
| 106 | private: | 145 | private: |
| 107 | /** | 146 | /** |
| 108 | * Sets the status of a button. Applies toggle properties to the output. | 147 | * Updates the touch status of the console |
| 109 | * | 148 | * @param callback: A CallbackStatus containing the key status |
| 110 | * @param A CallbackStatus and a button index number | 149 | * @param index: key ID to be updated |
| 111 | */ | 150 | */ |
| 112 | void SetKeyboardButton(Input::CallbackStatus callback, std::size_t index); | 151 | void SetKeyboardButton(Input::CallbackStatus callback, std::size_t index); |
| 152 | |||
| 153 | /** | ||
| 154 | * Updates the touch status of the console | ||
| 155 | * @param callback: A CallbackStatus containing the modifier key status | ||
| 156 | * @param index: modifier key ID to be updated | ||
| 157 | */ | ||
| 113 | void SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index); | 158 | void SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index); |
| 159 | |||
| 160 | /** | ||
| 161 | * Updates the touch status of the console | ||
| 162 | * @param callback: A CallbackStatus containing the button status | ||
| 163 | * @param index: Button ID of the to be updated | ||
| 164 | */ | ||
| 114 | void SetMouseButton(Input::CallbackStatus callback, std::size_t index); | 165 | void SetMouseButton(Input::CallbackStatus callback, std::size_t index); |
| 115 | 166 | ||
| 116 | /** | 167 | /** |
| 117 | * Triggers a callback that something has changed | 168 | * Triggers a callback that something has changed on the device status |
| 118 | * | 169 | * @param Input type of the event to trigger |
| 119 | * @param Input type of the trigger | ||
| 120 | */ | 170 | */ |
| 121 | void TriggerOnChange(DeviceTriggerType type); | 171 | void TriggerOnChange(DeviceTriggerType type); |
| 122 | 172 | ||
| @@ -131,6 +181,8 @@ private: | |||
| 131 | mutable std::mutex mutex; | 181 | mutable std::mutex mutex; |
| 132 | std::unordered_map<int, InterfaceUpdateCallback> callback_list; | 182 | std::unordered_map<int, InterfaceUpdateCallback> callback_list; |
| 133 | int last_callback_key = 0; | 183 | int last_callback_key = 0; |
| 184 | |||
| 185 | // Stores the current status of all external device input | ||
| 134 | DeviceStatus device_status; | 186 | DeviceStatus device_status; |
| 135 | }; | 187 | }; |
| 136 | 188 | ||