1
0
Fork 0
forked from suyu/suyu

core/hid: Documment some files

This commit is contained in:
german77 2021-10-17 00:33:00 -05:00 committed by Narr the Reg
parent e0da5c1bbc
commit 72e5920240
4 changed files with 265 additions and 52 deletions

View file

@ -38,9 +38,10 @@ struct TouchFinger {
Common::Point<float> position{}; Common::Point<float> position{};
u32_le id{}; u32_le id{};
bool pressed{}; bool pressed{};
Core::HID::TouchAttribute attribute{}; TouchAttribute attribute{};
}; };
// Contains all motion related data that is used on the services
struct ConsoleMotion { struct ConsoleMotion {
bool is_at_rest{}; bool is_at_rest{};
Common::Vec3f accel{}; Common::Vec3f accel{};
@ -57,7 +58,7 @@ struct ConsoleStatus {
ConsoleMotionValues motion_values{}; ConsoleMotionValues motion_values{};
TouchValues touch_values{}; TouchValues touch_values{};
// Data for Nintendo devices; // Data for HID services
ConsoleMotion motion_state{}; ConsoleMotion motion_state{};
TouchFingerState touch_state{}; TouchFingerState touch_state{};
}; };
@ -75,52 +76,90 @@ struct ConsoleUpdateCallback {
class EmulatedConsole { class EmulatedConsole {
public: public:
/** /**
* TODO: Write description * Contains all input data related to the console like motion and touch input
*
* @param npad_id_type
*/ */
explicit EmulatedConsole(); EmulatedConsole();
~EmulatedConsole(); ~EmulatedConsole();
YUZU_NON_COPYABLE(EmulatedConsole); YUZU_NON_COPYABLE(EmulatedConsole);
YUZU_NON_MOVEABLE(EmulatedConsole); YUZU_NON_MOVEABLE(EmulatedConsole);
void ReloadFromSettings(); /// Removes all callbacks created from input devices
void ReloadInput();
void UnloadInput(); void UnloadInput();
/// Sets the emulated console into configuring mode. Locking all HID service events from being
/// moddified
void EnableConfiguration(); void EnableConfiguration();
/// Returns the emulated console to the normal behaivour
void DisableConfiguration(); void DisableConfiguration();
/// Returns true if the emulated console is on configuring mode
bool IsConfiguring() const; 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(); void SaveCurrentConfig();
/// Reverts any mapped changes made that weren't saved
void RestoreConfig(); void RestoreConfig();
// Returns the current mapped motion device
Common::ParamPackage GetMotionParam() const; Common::ParamPackage GetMotionParam() const;
/**
* Updates the current mapped motion device
* @param ParamPackage with controller data to be mapped
*/
void SetMotionParam(Common::ParamPackage param); void SetMotionParam(Common::ParamPackage param);
/// Returns the latest status of motion input from the console with parameters
ConsoleMotionValues GetMotionValues() const; ConsoleMotionValues GetMotionValues() const;
/// Returns the latest status of touch input from the console with parameters
TouchValues GetTouchValues() const; TouchValues GetTouchValues() const;
/// Returns the latest status of motion input from the console
ConsoleMotion GetMotion() const; ConsoleMotion GetMotion() const;
/// Returns the latest status of touch input from the console
TouchFingerState GetTouch() const; TouchFingerState GetTouch() const;
/**
* 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(ConsoleUpdateCallback update_callback); int SetCallback(ConsoleUpdateCallback 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); void DeleteCallback(int key);
private: private:
/** /**
* Sets the status of a button. Applies toggle properties to the output. * Updates the motion status of the console
* * @param A CallbackStatus containing gyro and accelerometer data
* @param A CallbackStatus and a button index number
*/ */
void SetMotion(Input::CallbackStatus callback); void SetMotion(Input::CallbackStatus callback);
/**
* Updates the touch status of the console
* @param callback: A CallbackStatus containing the touch position
* @param index: Finger ID to be updated
*/
void SetTouch(Input::CallbackStatus callback, std::size_t index); void SetTouch(Input::CallbackStatus callback, std::size_t index);
/** /**
* Triggers a callback that something has changed * Triggers a callback that something has changed on the console status
* * @param Input type of the event to trigger
* @param Input type of the trigger
*/ */
void TriggerOnChange(ConsoleTriggerType type); void TriggerOnChange(ConsoleTriggerType type);
@ -136,6 +175,8 @@ private:
mutable std::mutex mutex; mutable std::mutex mutex;
std::unordered_map<int, ConsoleUpdateCallback> callback_list; std::unordered_map<int, ConsoleUpdateCallback> callback_list;
int last_callback_key = 0; int last_callback_key = 0;
// Stores the current status of all console input
ConsoleStatus console; ConsoleStatus console;
}; };

View file

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

View file

@ -114,7 +114,7 @@ Common::ParamPackage EmulatedDevices::GetMouseButtonParam(std::size_t index) con
return mouse_button_params[index]; return mouse_button_params[index];
} }
void EmulatedDevices::SetButtonParam(std::size_t index, Common::ParamPackage param) { void EmulatedDevices::SetMouseButtonParam(std::size_t index, Common::ParamPackage param) {
if (index >= mouse_button_params.size()) { if (index >= mouse_button_params.size()) {
return; return;
} }
@ -132,7 +132,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz
auto& current_status = device_status.keyboard_values[index]; auto& current_status = device_status.keyboard_values[index];
current_status.toggle = new_status.toggle; current_status.toggle = new_status.toggle;
// Update button status with current // Update button status with current status
if (!current_status.toggle) { if (!current_status.toggle) {
current_status.locked = false; current_status.locked = false;
if (current_status.value != new_status.value) { if (current_status.value != new_status.value) {
@ -147,7 +147,7 @@ void EmulatedDevices::SetKeyboardButton(Input::CallbackStatus callback, std::siz
value_changed = true; value_changed = true;
} }
// Unlock button ready for next press // Unlock button, ready for next press
if (!new_status.value && current_status.locked) { if (!new_status.value && current_status.locked) {
current_status.locked = false; current_status.locked = false;
} }
@ -303,6 +303,14 @@ void EmulatedDevices::SetMouseButton(Input::CallbackStatus callback, std::size_t
TriggerOnChange(DeviceTriggerType::Mouse); TriggerOnChange(DeviceTriggerType::Mouse);
} }
KeyboardValues EmulatedDevices::GetKeyboardValues() const {
return device_status.keyboard_values;
}
KeyboardModifierValues EmulatedDevices::GetKeyboardModdifierValues() const {
return device_status.keyboard_moddifier_values;
}
MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const { MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const {
return device_status.mouse_button_values; return device_status.mouse_button_values;
} }

View file

@ -45,7 +45,7 @@ struct DeviceStatus {
KeyboardModifierValues keyboard_moddifier_values{}; KeyboardModifierValues keyboard_moddifier_values{};
MouseButtonValues mouse_button_values{}; MouseButtonValues mouse_button_values{};
// Data for Nintendo devices // Data for HID serices
KeyboardKey keyboard_state{}; KeyboardKey keyboard_state{};
KeyboardModifier keyboard_moddifier_state{}; KeyboardModifier keyboard_moddifier_state{};
MouseButton mouse_button_state{}; MouseButton mouse_button_state{};
@ -65,58 +65,108 @@ struct InterfaceUpdateCallback {
class EmulatedDevices { class EmulatedDevices {
public: public:
/** /**
* TODO: Write description * Contains all input data related to external devices that aren't necesarily a controller
* * like keyboard and mouse
* @param npad_id_type
*/ */
explicit EmulatedDevices(); EmulatedDevices();
~EmulatedDevices(); ~EmulatedDevices();
YUZU_NON_COPYABLE(EmulatedDevices); YUZU_NON_COPYABLE(EmulatedDevices);
YUZU_NON_MOVEABLE(EmulatedDevices); YUZU_NON_MOVEABLE(EmulatedDevices);
void ReloadFromSettings(); /// Removes all callbacks created from input devices
void ReloadInput();
void UnloadInput(); void UnloadInput();
/// Sets the emulated console into configuring mode. Locking all HID service events from being
/// moddified
void EnableConfiguration(); void EnableConfiguration();
/// Returns the emulated console to the normal behaivour
void DisableConfiguration(); void DisableConfiguration();
/// Returns true if the emulated device is on configuring mode
bool IsConfiguring() const; 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(); void SaveCurrentConfig();
/// Reverts any mapped changes made that weren't saved
void RestoreConfig(); void RestoreConfig();
std::vector<Common::ParamPackage> GetMappedDevices() const; /// Returns the current mapped motion device
Common::ParamPackage GetMouseButtonParam(std::size_t index) const; Common::ParamPackage GetMouseButtonParam(std::size_t index) const;
void SetButtonParam(std::size_t index, Common::ParamPackage param); /**
* Updates the current mapped mouse button device
* @param ParamPackage with controller data to be mapped
*/
void SetMouseButtonParam(std::size_t index, Common::ParamPackage param);
/// Returns the latest status of button input from the keyboard with parameters
KeyboardValues GetKeyboardValues() const; KeyboardValues GetKeyboardValues() const;
/// Returns the latest status of button input from the keyboard modifiers with parameters
KeyboardModifierValues GetKeyboardModdifierValues() const; KeyboardModifierValues GetKeyboardModdifierValues() const;
/// Returns the latest status of button input from the mouse with parameters
MouseButtonValues GetMouseButtonsValues() const; MouseButtonValues GetMouseButtonsValues() const;
/// Returns the latest status of button input from the keyboard
KeyboardKey GetKeyboard() const; KeyboardKey GetKeyboard() const;
/// Returns the latest status of button input from the keyboard modifiers
KeyboardModifier GetKeyboardModifier() const; KeyboardModifier GetKeyboardModifier() const;
/// Returns the latest status of button input from the mouse
MouseButton GetMouseButtons() const; MouseButton GetMouseButtons() const;
/// Returns the latest mouse coordinates
MousePosition GetMousePosition() const; MousePosition GetMousePosition() const;
/**
* 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(InterfaceUpdateCallback update_callback); int SetCallback(InterfaceUpdateCallback 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); void DeleteCallback(int key);
private: private:
/** /**
* Sets the status of a button. Applies toggle properties to the output. * Updates the touch status of the console
* * @param callback: A CallbackStatus containing the key status
* @param A CallbackStatus and a button index number * @param index: key ID to be updated
*/ */
void SetKeyboardButton(Input::CallbackStatus callback, std::size_t index); void SetKeyboardButton(Input::CallbackStatus callback, std::size_t index);
/**
* Updates the touch status of the console
* @param callback: A CallbackStatus containing the modifier key status
* @param index: modifier key ID to be updated
*/
void SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index); void SetKeyboardModifier(Input::CallbackStatus callback, std::size_t index);
/**
* Updates the touch status of the console
* @param callback: A CallbackStatus containing the button status
* @param index: Button ID of the to be updated
*/
void SetMouseButton(Input::CallbackStatus callback, std::size_t index); void SetMouseButton(Input::CallbackStatus callback, std::size_t index);
/** /**
* Triggers a callback that something has changed * Triggers a callback that something has changed on the device status
* * @param Input type of the event to trigger
* @param Input type of the trigger
*/ */
void TriggerOnChange(DeviceTriggerType type); void TriggerOnChange(DeviceTriggerType type);
@ -131,6 +181,8 @@ private:
mutable std::mutex mutex; mutable std::mutex mutex;
std::unordered_map<int, InterfaceUpdateCallback> callback_list; std::unordered_map<int, InterfaceUpdateCallback> callback_list;
int last_callback_key = 0; int last_callback_key = 0;
// Stores the current status of all external device input
DeviceStatus device_status; DeviceStatus device_status;
}; };