summaryrefslogtreecommitdiffstats
path: root/src/core/hid
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_console.h28
-rw-r--r--src/core/hid/emulated_controller.h58
-rw-r--r--src/core/hid/emulated_devices.h40
-rw-r--r--src/core/hid/hid_core.cpp26
-rw-r--r--src/core/hid/hid_core.h6
-rw-r--r--src/core/hid/hid_types.h2
-rw-r--r--src/core/hid/input_converter.h23
-rw-r--r--src/core/hid/input_interpreter.cpp16
-rw-r--r--src/core/hid/input_interpreter.h2
9 files changed, 121 insertions, 80 deletions
diff --git a/src/core/hid/emulated_console.h b/src/core/hid/emulated_console.h
index 25c183eee..bb3d7ab90 100644
--- a/src/core/hid/emulated_console.h
+++ b/src/core/hid/emulated_console.h
@@ -78,9 +78,9 @@ struct ConsoleUpdateCallback {
class EmulatedConsole {
public:
/**
- * Contains all input data related to the console like motion and touch input
+ * Contains all input data within the emulated switch console tablet such as touch and motion
*/
- EmulatedConsole();
+ explicit EmulatedConsole();
~EmulatedConsole();
YUZU_NON_COPYABLE(EmulatedConsole);
@@ -89,14 +89,16 @@ public:
/// Removes all callbacks created from input devices
void UnloadInput();
- /// Sets the emulated console into configuring mode. Locking all HID service events from being
- /// moddified
+ /**
+ * Sets the emulated console into configuring mode
+ * This prevents the modification of the HID state of the emulated console by input commands
+ */
void EnableConfiguration();
- /// Returns the emulated console to the normal behaivour
+ /// Returns the emulated console into normal mode, allowing the modification of the HID state
void DisableConfiguration();
- /// Returns true if the emulated console is on configuring mode
+ /// Returns true if the emulated console is in configuring mode
bool IsConfiguring() const;
/// Reload all input devices
@@ -116,7 +118,7 @@ public:
/**
* Updates the current mapped motion device
- * @param ParamPackage with controller data to be mapped
+ * @param param ParamPackage with controller data to be mapped
*/
void SetMotionParam(Common::ParamPackage param);
@@ -134,14 +136,14 @@ public:
/**
* Adds a callback to the list of events
- * @param ConsoleUpdateCallback that will be triggered
+ * @param update_callback A ConsoleUpdateCallback that will be triggered
* @return an unique key corresponding to the callback index in the list
*/
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
+ * @param key Key corresponding to the callback index in the list
*/
void DeleteCallback(int key);
@@ -151,20 +153,20 @@ private:
/**
* Updates the motion status of the console
- * @param A CallbackStatus containing gyro and accelerometer data
+ * @param callback A CallbackStatus containing gyro and accelerometer data
*/
void SetMotion(Common::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
+ * @param callback A CallbackStatus containing the touch position
+ * @param index Finger ID to be updated
*/
void SetTouch(Common::Input::CallbackStatus callback, std::size_t index);
/**
* Triggers a callback that something has changed on the console status
- * @param Input type of the event to trigger
+ * @param type Input type of the event to trigger
*/
void TriggerOnChange(ConsoleTriggerType type);
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index 2c5d51bc8..5887e3e38 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -132,8 +132,8 @@ struct ControllerUpdateCallback {
class EmulatedController {
public:
/**
- * Contains all input data related to this controller. Like buttons, joysticks, motion.
- * @param Npad id type for this specific controller
+ * Contains all input data (buttons, joysticks, vibration, and motion) within this controller.
+ * @param npad_id_type npad id type for this specific controller
*/
explicit EmulatedController(NpadIdType npad_id_type_);
~EmulatedController();
@@ -155,7 +155,7 @@ public:
/**
* Gets the NpadStyleIndex for this controller
- * @param If true tmp_npad_type will be returned
+ * @param get_temporary_value If true tmp_npad_type will be returned
* @return NpadStyleIndex set on the controller
*/
NpadStyleIndex GetNpadStyleIndex(bool get_temporary_value = false) const;
@@ -168,7 +168,7 @@ public:
/**
* Is the emulated connected
- * @param If true tmp_is_connected will be returned
+ * @param get_temporary_value If true tmp_is_connected will be returned
* @return true if the controller has the connected status
*/
bool IsConnected(bool get_temporary_value = false) const;
@@ -179,14 +179,16 @@ public:
/// Removes all callbacks created from input devices
void UnloadInput();
- /// Sets the emulated console into configuring mode. Locking all HID service events from being
- /// moddified
+ /**
+ * Sets the emulated controller into configuring mode
+ * This prevents the modification of the HID state of the emulated controller by input commands
+ */
void EnableConfiguration();
- /// Returns the emulated console to the normal behaivour
+ /// Returns the emulated controller into normal mode, allowing the modification of the HID state
void DisableConfiguration();
- /// Returns true if the emulated device is on configuring mode
+ /// Returns true if the emulated controller is in configuring mode
bool IsConfiguring() const;
/// Reload all input devices
@@ -215,19 +217,19 @@ public:
/**
* Updates the current mapped button device
- * @param ParamPackage with controller data to be mapped
+ * @param 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
+ * @param 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
+ * @param param ParamPackage with controller data to be mapped
*/
void SetMotionParam(std::size_t index, Common::ParamPackage param);
@@ -270,13 +272,13 @@ public:
/// 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
*/
@@ -290,14 +292,14 @@ public:
/**
* Adds a callback to the list of events
- * @param ConsoleUpdateCallback that will be triggered
+ * @param update_callback A 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
+ * @param key Key corresponding to the callback index in the list
*/
void DeleteCallback(int key);
@@ -310,43 +312,43 @@ private:
/**
* Updates the button status of the controller
- * @param callback: A CallbackStatus containing the button status
- * @param index: Button ID of the to be updated
+ * @param callback A CallbackStatus containing the button status
+ * @param index Button ID of the to be updated
*/
void SetButton(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
/**
* 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
+ * @param callback A CallbackStatus containing the analog stick status
+ * @param index stick ID of the to be updated
*/
void SetStick(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
/**
* Updates the trigger status of the controller
- * @param callback: A CallbackStatus containing the trigger status
- * @param index: trigger ID of the to be updated
+ * @param callback A CallbackStatus containing the trigger status
+ * @param index trigger ID of the to be updated
*/
void SetTrigger(Common::Input::CallbackStatus callback, std::size_t index, Common::UUID uuid);
/**
* 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
+ * @param callback A CallbackStatus containing gyro and accelerometer data
+ * @param index motion ID of the to be updated
*/
void SetMotion(Common::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
+ * @param callback A CallbackStatus containing the battery status
+ * @param index Button ID of the to be updated
*/
void SetBattery(Common::Input::CallbackStatus callback, std::size_t index);
/**
* Triggers a callback that something has changed on the controller status
- * @param type: Input type of the event to trigger
- * @param is_service_update: indicates if this event should be sended to only services
+ * @param type Input type of the event to trigger
+ * @param is_service_update indicates if this event should only be sent to HID services
*/
void TriggerOnChange(ControllerTriggerType type, bool is_service_update);
@@ -357,7 +359,7 @@ private:
f32 motion_sensitivity{0.01f};
bool force_update_motion{false};
- // Temporary values to avoid doing changes while the controller is on configuration mode
+ // Temporary values to avoid doing changes while the controller is in configuring mode
NpadStyleIndex tmp_npad_type{NpadStyleIndex::None};
bool tmp_is_connected{false};
diff --git a/src/core/hid/emulated_devices.h b/src/core/hid/emulated_devices.h
index 05a945d08..c72327681 100644
--- a/src/core/hid/emulated_devices.h
+++ b/src/core/hid/emulated_devices.h
@@ -75,9 +75,9 @@ class EmulatedDevices {
public:
/**
* Contains all input data related to external devices that aren't necesarily a controller
- * like keyboard and mouse
+ * This includes devices such as the keyboard or mouse
*/
- EmulatedDevices();
+ explicit EmulatedDevices();
~EmulatedDevices();
YUZU_NON_COPYABLE(EmulatedDevices);
@@ -86,14 +86,16 @@ public:
/// Removes all callbacks created from input devices
void UnloadInput();
- /// Sets the emulated console into configuring mode. Locking all HID service events from being
- /// moddified
+ /**
+ * Sets the emulated devices into configuring mode
+ * This prevents the modification of the HID state of the emulated devices by input commands
+ */
void EnableConfiguration();
- /// Returns the emulated console to the normal behaivour
+ /// Returns the emulated devices into normal mode, allowing the modification of the HID state
void DisableConfiguration();
- /// Returns true if the emulated device is on configuring mode
+ /// Returns true if the emulated device is in configuring mode
bool IsConfiguring() const;
/// Reload all input devices
@@ -134,14 +136,14 @@ public:
/**
* Adds a callback to the list of events
- * @param InterfaceUpdateCallback that will be triggered
+ * @param update_callback InterfaceUpdateCallback that will be triggered
* @return an unique key corresponding to the callback index in the list
*/
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
+ * @param key Key corresponding to the callback index in the list
*/
void DeleteCallback(int key);
@@ -151,42 +153,42 @@ private:
/**
* Updates the touch status of the keyboard device
- * @param callback: A CallbackStatus containing the key status
- * @param index: key ID to be updated
+ * @param callback A CallbackStatus containing the key status
+ * @param index key ID to be updated
*/
void SetKeyboardButton(Common::Input::CallbackStatus callback, std::size_t index);
/**
* Updates the keyboard status of the keyboard device
- * @param callback: A CallbackStatus containing the modifier key status
- * @param index: modifier key ID to be updated
+ * @param callback A CallbackStatus containing the modifier key status
+ * @param index modifier key ID to be updated
*/
void SetKeyboardModifier(Common::Input::CallbackStatus callback, std::size_t index);
/**
* Updates the mouse button status of the mouse device
- * @param callback: A CallbackStatus containing the button status
- * @param index: Button ID to be updated
+ * @param callback A CallbackStatus containing the button status
+ * @param index Button ID to be updated
*/
void SetMouseButton(Common::Input::CallbackStatus callback, std::size_t index);
/**
* Updates the mouse wheel status of the mouse device
- * @param callback: A CallbackStatus containing the wheel status
- * @param index: wheel ID to be updated
+ * @param callback A CallbackStatus containing the wheel status
+ * @param index wheel ID to be updated
*/
void SetMouseAnalog(Common::Input::CallbackStatus callback, std::size_t index);
/**
* Updates the mouse position status of the mouse device
- * @param callback: A CallbackStatus containing the position status
- * @param index: stick ID to be updated
+ * @param callback A CallbackStatus containing the position status
+ * @param index stick ID to be updated
*/
void SetMouseStick(Common::Input::CallbackStatus callback);
/**
* Triggers a callback that something has changed on the device status
- * @param Input type of the event to trigger
+ * @param type Input type of the event to trigger
*/
void TriggerOnChange(DeviceTriggerType type);
diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp
index 741a69c3c..946adde00 100644
--- a/src/core/hid/hid_core.cpp
+++ b/src/core/hid/hid_core.cpp
@@ -135,6 +135,32 @@ NpadIdType HIDCore::GetFirstNpadId() const {
return NpadIdType::Player1;
}
+void HIDCore::EnableAllControllerConfiguration() {
+ player_1->EnableConfiguration();
+ player_2->EnableConfiguration();
+ player_3->EnableConfiguration();
+ player_4->EnableConfiguration();
+ player_5->EnableConfiguration();
+ player_6->EnableConfiguration();
+ player_7->EnableConfiguration();
+ player_8->EnableConfiguration();
+ other->EnableConfiguration();
+ handheld->EnableConfiguration();
+}
+
+void HIDCore::DisableAllControllerConfiguration() {
+ player_1->DisableConfiguration();
+ player_2->DisableConfiguration();
+ player_3->DisableConfiguration();
+ player_4->DisableConfiguration();
+ player_5->DisableConfiguration();
+ player_6->DisableConfiguration();
+ player_7->DisableConfiguration();
+ player_8->DisableConfiguration();
+ other->DisableConfiguration();
+ handheld->DisableConfiguration();
+}
+
void HIDCore::ReloadInputDevices() {
player_1->ReloadFromSettings();
player_2->ReloadFromSettings();
diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h
index 609f40f3b..140a0e962 100644
--- a/src/core/hid/hid_core.h
+++ b/src/core/hid/hid_core.h
@@ -45,6 +45,12 @@ public:
/// Returns the first connected npad id
NpadIdType GetFirstNpadId() const;
+ /// Sets all emulated controllers into configuring mode.
+ void EnableAllControllerConfiguration();
+
+ /// Sets all emulated controllers into normal mode.
+ void DisableAllControllerConfiguration();
+
/// Reloads all input devices from settings
void ReloadInputDevices();
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h
index acf54e233..780659b86 100644
--- a/src/core/hid/hid_types.h
+++ b/src/core/hid/hid_types.h
@@ -63,6 +63,8 @@ enum class NpadButton : u64 {
LagonCUp = 1ULL << 32,
LagonCRight = 1ULL << 33,
LagonCDown = 1ULL << 34,
+
+ All = 0xFFFFFFFFFFFFFFFFULL,
};
DECLARE_ENUM_FLAG_OPERATORS(NpadButton);
diff --git a/src/core/hid/input_converter.h b/src/core/hid/input_converter.h
index 1492489d7..d24582226 100644
--- a/src/core/hid/input_converter.h
+++ b/src/core/hid/input_converter.h
@@ -21,7 +21,7 @@ namespace Core::HID {
/**
* Converts raw input data into a valid battery status.
*
- * @param Supported callbacks: Analog, Battery, Trigger.
+ * @param callback Supported callbacks: Analog, Battery, Trigger.
* @return A valid BatteryStatus object.
*/
Common::Input::BatteryStatus TransformToBattery(const Common::Input::CallbackStatus& callback);
@@ -29,7 +29,7 @@ Common::Input::BatteryStatus TransformToBattery(const Common::Input::CallbackSta
/**
* Converts raw input data into a valid button status. Applies invert properties to the output.
*
- * @param Supported callbacks: Analog, Button, Trigger.
+ * @param callback Supported callbacks: Analog, Button, Trigger.
* @return A valid TouchStatus object.
*/
Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatus& callback);
@@ -37,7 +37,7 @@ Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatu
/**
* Converts raw input data into a valid motion status.
*
- * @param Supported callbacks: Motion.
+ * @param callback Supported callbacks: Motion.
* @return A valid TouchStatus object.
*/
Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatus& callback);
@@ -46,7 +46,7 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
* Converts raw input data into a valid stick status. Applies offset, deadzone, range and invert
* properties to the output.
*
- * @param Supported callbacks: Stick.
+ * @param callback Supported callbacks: Stick.
* @return A valid StickStatus object.
*/
Common::Input::StickStatus TransformToStick(const Common::Input::CallbackStatus& callback);
@@ -54,7 +54,7 @@ Common::Input::StickStatus TransformToStick(const Common::Input::CallbackStatus&
/**
* Converts raw input data into a valid touch status.
*
- * @param Supported callbacks: Touch.
+ * @param callback Supported callbacks: Touch.
* @return A valid TouchStatus object.
*/
Common::Input::TouchStatus TransformToTouch(const Common::Input::CallbackStatus& callback);
@@ -63,7 +63,7 @@ Common::Input::TouchStatus TransformToTouch(const Common::Input::CallbackStatus&
* Converts raw input data into a valid trigger status. Applies offset, deadzone, range and
* invert properties to the output. Button status uses the threshold property if necessary.
*
- * @param Supported callbacks: Analog, Button, Trigger.
+ * @param callback Supported callbacks: Analog, Button, Trigger.
* @return A valid TriggerStatus object.
*/
Common::Input::TriggerStatus TransformToTrigger(const Common::Input::CallbackStatus& callback);
@@ -72,22 +72,23 @@ Common::Input::TriggerStatus TransformToTrigger(const Common::Input::CallbackSta
* Converts raw input data into a valid analog status. Applies offset, deadzone, range and
* invert properties to the output.
*
- * @param Supported callbacks: Analog.
+ * @param callback Supported callbacks: Analog.
* @return A valid AnalogStatus object.
*/
Common::Input::AnalogStatus TransformToAnalog(const Common::Input::CallbackStatus& callback);
/**
* Converts raw analog data into a valid analog value
- * @param An analog object containing raw data and properties, bool that determines if the value
- * needs to be clamped between -1.0f and 1.0f.
+ * @param analog An analog object containing raw data and properties
+ * @param clamp_value determines if the value needs to be clamped between -1.0f and 1.0f.
*/
void SanitizeAnalog(Common::Input::AnalogStatus& analog, bool clamp_value);
/**
* Converts raw stick data into a valid stick value
- * @param Two analog objects containing raw data and properties, bool that determines if the value
- * needs to be clamped into the unit circle.
+ * @param analog_x raw analog data and properties for the x-axis
+ * @param analog_y raw analog data and properties for the y-axis
+ * @param clamp_value bool that determines if the value needs to be clamped into the unit circle.
*/
void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogStatus& analog_y,
bool clamp_value);
diff --git a/src/core/hid/input_interpreter.cpp b/src/core/hid/input_interpreter.cpp
index 870422d82..2dbda8814 100644
--- a/src/core/hid/input_interpreter.cpp
+++ b/src/core/hid/input_interpreter.cpp
@@ -20,7 +20,7 @@ InputInterpreter::InputInterpreter(Core::System& system)
InputInterpreter::~InputInterpreter() = default;
void InputInterpreter::PollInput() {
- const u64 button_state = npad.GetAndResetPressState();
+ const auto button_state = npad.GetAndResetPressState();
previous_index = current_index;
current_index = (current_index + 1) % button_states.size();
@@ -32,30 +32,30 @@ void InputInterpreter::ResetButtonStates() {
previous_index = 0;
current_index = 0;
- button_states[0] = 0xFFFFFFFFFFFFFFFF;
+ button_states[0] = Core::HID::NpadButton::All;
for (std::size_t i = 1; i < button_states.size(); ++i) {
- button_states[i] = 0;
+ button_states[i] = Core::HID::NpadButton::None;
}
}
bool InputInterpreter::IsButtonPressed(Core::HID::NpadButton button) const {
- return (button_states[current_index] & static_cast<u64>(button)) != 0;
+ return True(button_states[current_index] & button);
}
bool InputInterpreter::IsButtonPressedOnce(Core::HID::NpadButton button) const {
- const bool current_press = (button_states[current_index] & static_cast<u64>(button)) != 0;
- const bool previous_press = (button_states[previous_index] & static_cast<u64>(button)) != 0;
+ const bool current_press = True(button_states[current_index] & button);
+ const bool previous_press = True(button_states[previous_index] & button);
return current_press && !previous_press;
}
bool InputInterpreter::IsButtonHeld(Core::HID::NpadButton button) const {
- u64 held_buttons{button_states[0]};
+ Core::HID::NpadButton held_buttons{button_states[0]};
for (std::size_t i = 1; i < button_states.size(); ++i) {
held_buttons &= button_states[i];
}
- return (held_buttons & static_cast<u64>(button)) != 0;
+ return True(held_buttons & button);
}
diff --git a/src/core/hid/input_interpreter.h b/src/core/hid/input_interpreter.h
index 1c2e02142..70c34d474 100644
--- a/src/core/hid/input_interpreter.h
+++ b/src/core/hid/input_interpreter.h
@@ -105,7 +105,7 @@ private:
Service::HID::Controller_NPad& npad;
/// Stores 9 consecutive button states polled from HID.
- std::array<u64, 9> button_states{};
+ std::array<Core::HID::NpadButton, 9> button_states{};
std::size_t previous_index{};
std::size_t current_index{};