diff options
Diffstat (limited to 'src/core/hid/emulated_controller.h')
| -rw-r--r-- | src/core/hid/emulated_controller.h | 148 |
1 files changed, 130 insertions, 18 deletions
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 | ||