|
|
|
@ -87,7 +87,7 @@ struct ControllerStatus {
|
|
|
|
|
BatteryValues battery_values{};
|
|
|
|
|
VibrationValues vibration_values{};
|
|
|
|
|
|
|
|
|
|
// Data for Nintendo devices
|
|
|
|
|
// Data for HID serices
|
|
|
|
|
NpadButtonState npad_button_state{};
|
|
|
|
|
DebugPadButton debug_pad_button_state{};
|
|
|
|
|
AnalogSticks analog_stick_state{};
|
|
|
|
@ -118,9 +118,8 @@ struct ControllerUpdateCallback {
|
|
|
|
|
class EmulatedController {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* TODO: Write description
|
|
|
|
|
*
|
|
|
|
|
* @param npad_id_type
|
|
|
|
|
* Contains all input data related to this controller. Like buttons, joysticks, motion.
|
|
|
|
|
* @param Npad id type for this specific controller
|
|
|
|
|
*/
|
|
|
|
|
explicit EmulatedController(NpadIdType npad_id_type_);
|
|
|
|
|
~EmulatedController();
|
|
|
|
@ -128,86 +127,197 @@ public:
|
|
|
|
|
YUZU_NON_COPYABLE(EmulatedController);
|
|
|
|
|
YUZU_NON_MOVEABLE(EmulatedController);
|
|
|
|
|
|
|
|
|
|
/// Converts the controller type from settings to npad type
|
|
|
|
|
static NpadType MapSettingsTypeToNPad(Settings::ControllerType type);
|
|
|
|
|
|
|
|
|
|
/// Converts npad type to the equivalent of controller type from settings
|
|
|
|
|
static Settings::ControllerType MapNPadToSettingsType(NpadType type);
|
|
|
|
|
|
|
|
|
|
/// Gets the NpadIdType for this controller.
|
|
|
|
|
/// Gets the NpadIdType for this controller
|
|
|
|
|
NpadIdType GetNpadIdType() const;
|
|
|
|
|
|
|
|
|
|
/// Sets the NpadType for this controller.
|
|
|
|
|
/// Sets the NpadType for this controller
|
|
|
|
|
void SetNpadType(NpadType npad_type_);
|
|
|
|
|
|
|
|
|
|
/// Gets the NpadType for this controller.
|
|
|
|
|
/// Gets the NpadType for this controller
|
|
|
|
|
NpadType GetNpadType() const;
|
|
|
|
|
|
|
|
|
|
/// Gets the NpadType for this controller.
|
|
|
|
|
LedPattern GetLedPattern() const;
|
|
|
|
|
|
|
|
|
|
/// Sets the connected status to true
|
|
|
|
|
void Connect();
|
|
|
|
|
|
|
|
|
|
/// Sets the connected status to false
|
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
|
|
/// Returns true if the controller has the connected status
|
|
|
|
|
bool IsConnected() const;
|
|
|
|
|
|
|
|
|
|
/// Returns true if vibration is enabled
|
|
|
|
|
bool IsVibrationEnabled() const;
|
|
|
|
|
|
|
|
|
|
void ReloadFromSettings();
|
|
|
|
|
void ReloadInput();
|
|
|
|
|
/// Removes all callbacks created from input devices
|
|
|
|
|
void UnloadInput();
|
|
|
|
|
|
|
|
|
|
/// Sets the emulated console into configuring mode. Locking all HID service events from being
|
|
|
|
|
/// moddified
|
|
|
|
|
void EnableConfiguration();
|
|
|
|
|
|
|
|
|
|
/// Returns the emulated console to the normal behaivour
|
|
|
|
|
void DisableConfiguration();
|
|
|
|
|
|
|
|
|
|
/// Returns true if the emulated device is on configuring mode
|
|
|
|
|
bool IsConfiguring() const;
|
|
|
|
|
|
|
|
|
|
/// Reload all input devices
|
|
|
|
|
void ReloadInput();
|
|
|
|
|
|
|
|
|
|
/// Overrides current mapped devices with the stored configuration and reloads all input devices
|
|
|
|
|
void ReloadFromSettings();
|
|
|
|
|
|
|
|
|
|
/// Saves the current mapped configuration
|
|
|
|
|
void SaveCurrentConfig();
|
|
|
|
|
|
|
|
|
|
/// Reverts any mapped changes made that weren't saved
|
|
|
|
|
void RestoreConfig();
|
|
|
|
|
|
|
|
|
|
/// Returns a vector of mapped devices from the mapped button and stick parameters
|
|
|
|
|
std::vector<Common::ParamPackage> GetMappedDevices() const;
|
|
|
|
|
|
|
|
|
|
// Returns the current mapped button device
|
|
|
|
|
Common::ParamPackage GetButtonParam(std::size_t index) const;
|
|
|
|
|
|
|
|
|
|
// Returns the current mapped stick device
|
|
|
|
|
Common::ParamPackage GetStickParam(std::size_t index) const;
|
|
|
|
|
|
|
|
|
|
// Returns the current mapped motion device
|
|
|
|
|
Common::ParamPackage GetMotionParam(std::size_t index) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the current mapped button device
|
|
|
|
|
* @param ParamPackage with controller data to be mapped
|
|
|
|
|
*/
|
|
|
|
|
void SetButtonParam(std::size_t index, Common::ParamPackage param);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the current mapped stick device
|
|
|
|
|
* @param ParamPackage with controller data to be mapped
|
|
|
|
|
*/
|
|
|
|
|
void SetStickParam(std::size_t index, Common::ParamPackage param);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the current mapped motion device
|
|
|
|
|
* @param ParamPackage with controller data to be mapped
|
|
|
|
|
*/
|
|
|
|
|
void SetMotionParam(std::size_t index, Common::ParamPackage param);
|
|
|
|
|
|
|
|
|
|
/// Returns the latest button status from the controller with parameters
|
|
|
|
|
ButtonValues GetButtonsValues() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest analog stick status from the controller with parameters
|
|
|
|
|
SticksValues GetSticksValues() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest trigger status from the controller with parameters
|
|
|
|
|
TriggerValues GetTriggersValues() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest motion status from the controller with parameters
|
|
|
|
|
ControllerMotionValues GetMotionValues() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest color status from the controller with parameters
|
|
|
|
|
ColorValues GetColorsValues() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest battery status from the controller with parameters
|
|
|
|
|
BatteryValues GetBatteryValues() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest status of button input for the npad service
|
|
|
|
|
NpadButtonState GetNpadButtons() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest status of button input for the debug pad service
|
|
|
|
|
DebugPadButton GetDebugPadButtons() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest status of stick input from the mouse
|
|
|
|
|
AnalogSticks GetSticks() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest status of trigger input from the mouse
|
|
|
|
|
NpadGcTriggerState GetTriggers() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest status of motion input from the mouse
|
|
|
|
|
MotionState GetMotions() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest color value from the controller
|
|
|
|
|
ControllerColors GetColors() const;
|
|
|
|
|
|
|
|
|
|
/// Returns the latest battery status from the controller
|
|
|
|
|
BatteryLevelState GetBattery() const;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sends a specific vibration to the output device
|
|
|
|
|
* @return returns true if vibration had no errors
|
|
|
|
|
*/
|
|
|
|
|
bool SetVibration(std::size_t device_index, VibrationValue vibration);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sends a small vibration to the output device
|
|
|
|
|
* @return returns true if SetVibration was successfull
|
|
|
|
|
*/
|
|
|
|
|
bool TestVibration(std::size_t device_index);
|
|
|
|
|
|
|
|
|
|
/// Returns the led pattern corresponding to this emulated controller
|
|
|
|
|
LedPattern GetLedPattern() const;
|
|
|
|
|
|
|
|
|
|
/// Asks the output device to change the player led pattern
|
|
|
|
|
void SetLedPattern();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a callback to the list of events
|
|
|
|
|
* @param ConsoleUpdateCallback that will be triggered
|
|
|
|
|
* @return an unique key corresponding to the callback index in the list
|
|
|
|
|
*/
|
|
|
|
|
int SetCallback(ControllerUpdateCallback update_callback);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes a callback from the list stopping any future events to this object
|
|
|
|
|
* @param Key corresponding to the callback index in the list
|
|
|
|
|
*/
|
|
|
|
|
void DeleteCallback(int key);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/**
|
|
|
|
|
* Sets the status of a button. Applies toggle properties to the output.
|
|
|
|
|
*
|
|
|
|
|
* @param A CallbackStatus and a button index number
|
|
|
|
|
* Updates the button status of the controller
|
|
|
|
|
* @param callback: A CallbackStatus containing the button status
|
|
|
|
|
* @param index: Button ID of the to be updated
|
|
|
|
|
*/
|
|
|
|
|
void SetButton(Input::CallbackStatus callback, std::size_t index);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the analog stick status of the controller
|
|
|
|
|
* @param callback: A CallbackStatus containing the analog stick status
|
|
|
|
|
* @param index: stick ID of the to be updated
|
|
|
|
|
*/
|
|
|
|
|
void SetStick(Input::CallbackStatus callback, std::size_t index);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the trigger status of the controller
|
|
|
|
|
* @param callback: A CallbackStatus containing the trigger status
|
|
|
|
|
* @param index: trigger ID of the to be updated
|
|
|
|
|
*/
|
|
|
|
|
void SetTrigger(Input::CallbackStatus callback, std::size_t index);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the motion status of the controller
|
|
|
|
|
* @param callback: A CallbackStatus containing gyro and accelerometer data
|
|
|
|
|
* @param index: motion ID of the to be updated
|
|
|
|
|
*/
|
|
|
|
|
void SetMotion(Input::CallbackStatus callback, std::size_t index);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates the battery status of the controller
|
|
|
|
|
* @param callback: A CallbackStatus containing the battery status
|
|
|
|
|
* @param index: Button ID of the to be updated
|
|
|
|
|
*/
|
|
|
|
|
void SetBattery(Input::CallbackStatus callback, std::size_t index);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Triggers a callback that something has changed
|
|
|
|
|
*
|
|
|
|
|
* @param Input type of the trigger
|
|
|
|
|
* Triggers a callback that something has changed on the controller status
|
|
|
|
|
* @param Input type of the event to trigger
|
|
|
|
|
*/
|
|
|
|
|
void TriggerOnChange(ControllerTriggerType type);
|
|
|
|
|
|
|
|
|
@ -235,6 +345,8 @@ private:
|
|
|
|
|
mutable std::mutex mutex;
|
|
|
|
|
std::unordered_map<int, ControllerUpdateCallback> callback_list;
|
|
|
|
|
int last_callback_key = 0;
|
|
|
|
|
|
|
|
|
|
// Stores the current status of all controller input
|
|
|
|
|
ControllerStatus controller;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|