summaryrefslogtreecommitdiffstats
path: root/src/core/hid
diff options
context:
space:
mode:
authorNarr the Reg <juangerman-13@hotmail.com>2022-12-20 20:09:10 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2023-01-20 01:05:20 +0100
commita4074001fe2e8ed72c87093f57ec972815661b81 (patch)
tree145ff4c2896098d069cb2b08d175ed8e4c906e83 /src/core/hid
parentyuzu: Update controller colors and button names (diff)
downloadyuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar
yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.gz
yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.bz2
yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.lz
yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.xz
yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.tar.zst
yuzu-a4074001fe2e8ed72c87093f57ec972815661b81.zip
Diffstat (limited to 'src/core/hid')
-rw-r--r--src/core/hid/emulated_controller.cpp46
-rw-r--r--src/core/hid/emulated_controller.h35
-rw-r--r--src/core/hid/emulated_devices.cpp46
-rw-r--r--src/core/hid/emulated_devices.h18
4 files changed, 80 insertions, 65 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 7a01f3f4c..128101e8c 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -139,6 +139,7 @@ void EmulatedController::LoadDevices() {
camera_params = Common::ParamPackage{"engine:camera,camera:1"};
nfc_params = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"};
+ ring_params = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"};
output_params[LeftIndex] = left_joycon;
output_params[RightIndex] = right_joycon;
@@ -160,6 +161,7 @@ void EmulatedController::LoadDevices() {
std::ranges::transform(battery_params, battery_devices.begin(),
Common::Input::CreateInputDevice);
camera_devices = Common::Input::CreateInputDevice(camera_params);
+ ring_analog_device = Common::Input::CreateInputDevice(ring_params);
nfc_devices = Common::Input::CreateInputDevice(nfc_params);
std::ranges::transform(output_params, output_devices.begin(),
Common::Input::CreateOutputDevice);
@@ -343,6 +345,13 @@ void EmulatedController::ReloadInput() {
camera_devices->ForceUpdate();
}
+ if (ring_analog_device) {
+ ring_analog_device->SetCallback({
+ .on_change =
+ [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); },
+ });
+ }
+
if (nfc_devices) {
if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) {
nfc_devices->SetCallback({
@@ -436,6 +445,7 @@ void EmulatedController::UnloadInput() {
stick.reset();
}
camera_devices.reset();
+ ring_analog_device.reset();
nfc_devices.reset();
}
@@ -501,6 +511,7 @@ void EmulatedController::SaveCurrentConfig() {
for (std::size_t index = 0; index < player.motions.size(); ++index) {
player.motions[index] = motion_params[index].Serialize();
}
+ Settings::values.ringcon_analogs = ring_params.Serialize();
}
void EmulatedController::RestoreConfig() {
@@ -1005,6 +1016,24 @@ void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback
TriggerOnChange(ControllerTriggerType::IrSensor, true);
}
+void EmulatedController::SetRingAnalog(const Common::Input::CallbackStatus& callback) {
+ std::unique_lock lock{mutex};
+ const auto force_value = TransformToStick(callback);
+
+ controller.ring_analog_value = force_value.x;
+
+ if (is_configuring) {
+ lock.unlock();
+ TriggerOnChange(ControllerTriggerType::RingController, false);
+ return;
+ }
+
+ controller.ring_analog_state.force = force_value.x.value;
+
+ lock.unlock();
+ TriggerOnChange(ControllerTriggerType::RingController, true);
+}
+
void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) {
std::unique_lock lock{mutex};
controller.nfc_values = TransformToNfc(callback);
@@ -1104,6 +1133,15 @@ bool EmulatedController::SetCameraFormat(
camera_format)) == Common::Input::CameraError::None;
}
+Common::ParamPackage EmulatedController::GetRingParam() const {
+ return ring_params;
+}
+
+void EmulatedController::SetRingParam(Common::ParamPackage param) {
+ ring_params = std::move(param);
+ ReloadInput();
+}
+
bool EmulatedController::HasNfc() const {
const auto& nfc_output_device = output_devices[3];
@@ -1395,6 +1433,10 @@ CameraValues EmulatedController::GetCameraValues() const {
return controller.camera_values;
}
+RingAnalogValue EmulatedController::GetRingSensorValues() const {
+ return controller.ring_analog_value;
+}
+
HomeButtonState EmulatedController::GetHomeButtons() const {
std::scoped_lock lock{mutex};
if (is_configuring) {
@@ -1478,6 +1520,10 @@ const CameraState& EmulatedController::GetCamera() const {
return controller.camera_state;
}
+RingSensorForce EmulatedController::GetRingSensorForce() const {
+ return controller.ring_analog_state;
+}
+
const NfcState& EmulatedController::GetNfc() const {
std::scoped_lock lock{mutex};
return controller.nfc_state;
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index a398543a6..aed331a1a 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -38,6 +38,7 @@ using TriggerDevices =
using BatteryDevices =
std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>;
using CameraDevices = std::unique_ptr<Common::Input::InputDevice>;
+using RingAnalogDevice = std::unique_ptr<Common::Input::InputDevice>;
using NfcDevices = std::unique_ptr<Common::Input::InputDevice>;
using OutputDevices = std::array<std::unique_ptr<Common::Input::OutputDevice>, output_devices_size>;
@@ -47,6 +48,7 @@ using ControllerMotionParams = std::array<Common::ParamPackage, Settings::Native
using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>;
using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>;
using CameraParams = Common::ParamPackage;
+using RingAnalogParams = Common::ParamPackage;
using NfcParams = Common::ParamPackage;
using OutputParams = std::array<Common::ParamPackage, output_devices_size>;
@@ -58,6 +60,7 @@ using ControllerMotionValues = std::array<ControllerMotionInfo, Settings::Native
using ColorValues = std::array<Common::Input::BodyColorStatus, max_emulated_controllers>;
using BatteryValues = std::array<Common::Input::BatteryStatus, max_emulated_controllers>;
using CameraValues = Common::Input::CameraStatus;
+using RingAnalogValue = Common::Input::AnalogStatus;
using NfcValues = Common::Input::NfcStatus;
using VibrationValues = std::array<Common::Input::VibrationStatus, max_emulated_controllers>;
@@ -84,6 +87,10 @@ struct CameraState {
std::size_t sample{};
};
+struct RingSensorForce {
+ f32 force;
+};
+
struct NfcState {
Common::Input::NfcState state{};
std::vector<u8> data{};
@@ -116,6 +123,7 @@ struct ControllerStatus {
BatteryValues battery_values{};
VibrationValues vibration_values{};
CameraValues camera_values{};
+ RingAnalogValue ring_analog_value{};
NfcValues nfc_values{};
// Data for HID serices
@@ -129,6 +137,7 @@ struct ControllerStatus {
ControllerColors colors_state{};
BatteryLevelState battery_state{};
CameraState camera_state{};
+ RingSensorForce ring_analog_state{};
NfcState nfc_state{};
};
@@ -141,6 +150,7 @@ enum class ControllerTriggerType {
Battery,
Vibration,
IrSensor,
+ RingController,
Nfc,
Connected,
Disconnected,
@@ -294,6 +304,9 @@ public:
/// Returns the latest camera status from the controller with parameters
CameraValues GetCameraValues() const;
+ /// Returns the latest status of analog input from the ring sensor with parameters
+ RingAnalogValue GetRingSensorValues() const;
+
/// Returns the latest status of button input for the hid::HomeButton service
HomeButtonState GetHomeButtons() const;
@@ -324,6 +337,9 @@ public:
/// Returns the latest camera status from the controller
const CameraState& GetCamera() const;
+ /// Returns the latest ringcon force sensor value
+ RingSensorForce GetRingSensorForce() const;
+
/// Returns the latest ntag status from the controller
const NfcState& GetNfc() const;
@@ -353,6 +369,15 @@ public:
*/
bool SetCameraFormat(Core::IrSensor::ImageTransferProcessorFormat camera_format);
+ // Returns the current mapped ring device
+ Common::ParamPackage GetRingParam() const;
+
+ /**
+ * Updates the current mapped ring device
+ * @param param ParamPackage with ring sensor data to be mapped
+ */
+ void SetRingParam(Common::ParamPackage param);
+
/// Returns true if the device has nfc support
bool HasNfc() const;
@@ -435,7 +460,7 @@ private:
/**
* 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 index battery ID of the to be updated
*/
void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index);
@@ -446,6 +471,12 @@ private:
void SetCamera(const Common::Input::CallbackStatus& callback);
/**
+ * Updates the ring analog sensor status of the ring controller
+ * @param callback A CallbackStatus containing the force status
+ */
+ void SetRingAnalog(const Common::Input::CallbackStatus& callback);
+
+ /**
* Updates the nfc status of the controller
* @param callback A CallbackStatus containing the nfc status
*/
@@ -485,6 +516,7 @@ private:
TriggerParams trigger_params;
BatteryParams battery_params;
CameraParams camera_params;
+ RingAnalogParams ring_params;
NfcParams nfc_params;
OutputParams output_params;
@@ -494,6 +526,7 @@ private:
TriggerDevices trigger_devices;
BatteryDevices battery_devices;
CameraDevices camera_devices;
+ RingAnalogDevice ring_analog_device;
NfcDevices nfc_devices;
OutputDevices output_devices;
diff --git a/src/core/hid/emulated_devices.cpp b/src/core/hid/emulated_devices.cpp
index e421828d2..836f32c0f 100644
--- a/src/core/hid/emulated_devices.cpp
+++ b/src/core/hid/emulated_devices.cpp
@@ -14,7 +14,6 @@ EmulatedDevices::EmulatedDevices() = default;
EmulatedDevices::~EmulatedDevices() = default;
void EmulatedDevices::ReloadFromSettings() {
- ring_params = Common::ParamPackage(Settings::values.ringcon_analogs);
ReloadInput();
}
@@ -66,8 +65,6 @@ void EmulatedDevices::ReloadInput() {
key_index++;
}
- ring_analog_device = Common::Input::CreateInputDevice(ring_params);
-
for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) {
if (!mouse_button_devices[index]) {
continue;
@@ -122,13 +119,6 @@ void EmulatedDevices::ReloadInput() {
},
});
}
-
- if (ring_analog_device) {
- ring_analog_device->SetCallback({
- .on_change =
- [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); },
- });
- }
}
void EmulatedDevices::UnloadInput() {
@@ -145,7 +135,6 @@ void EmulatedDevices::UnloadInput() {
for (auto& button : keyboard_modifier_devices) {
button.reset();
}
- ring_analog_device.reset();
}
void EmulatedDevices::EnableConfiguration() {
@@ -165,7 +154,6 @@ void EmulatedDevices::SaveCurrentConfig() {
if (!is_configuring) {
return;
}
- Settings::values.ringcon_analogs = ring_params.Serialize();
}
void EmulatedDevices::RestoreConfig() {
@@ -175,15 +163,6 @@ void EmulatedDevices::RestoreConfig() {
ReloadFromSettings();
}
-Common::ParamPackage EmulatedDevices::GetRingParam() const {
- return ring_params;
-}
-
-void EmulatedDevices::SetRingParam(Common::ParamPackage param) {
- ring_params = std::move(param);
- ReloadInput();
-}
-
void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback,
std::size_t index) {
if (index >= device_status.keyboard_values.size()) {
@@ -430,23 +409,6 @@ void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callbac
TriggerOnChange(DeviceTriggerType::Mouse);
}
-void EmulatedDevices::SetRingAnalog(const Common::Input::CallbackStatus& callback) {
- std::lock_guard lock{mutex};
- const auto force_value = TransformToStick(callback);
-
- device_status.ring_analog_value = force_value.x;
-
- if (is_configuring) {
- device_status.ring_analog_value = {};
- TriggerOnChange(DeviceTriggerType::RingController);
- return;
- }
-
- device_status.ring_analog_state.force = force_value.x.value;
-
- TriggerOnChange(DeviceTriggerType::RingController);
-}
-
KeyboardValues EmulatedDevices::GetKeyboardValues() const {
std::scoped_lock lock{mutex};
return device_status.keyboard_values;
@@ -462,10 +424,6 @@ MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const {
return device_status.mouse_button_values;
}
-RingAnalogValue EmulatedDevices::GetRingSensorValues() const {
- return device_status.ring_analog_value;
-}
-
KeyboardKey EmulatedDevices::GetKeyboard() const {
std::scoped_lock lock{mutex};
return device_status.keyboard_state;
@@ -491,10 +449,6 @@ AnalogStickState EmulatedDevices::GetMouseWheel() const {
return device_status.mouse_wheel_state;
}
-RingSensorForce EmulatedDevices::GetRingSensorForce() const {
- return device_status.ring_analog_state;
-}
-
void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) {
std::scoped_lock lock{callback_mutex};
for (const auto& poller_pair : callback_list) {
diff --git a/src/core/hid/emulated_devices.h b/src/core/hid/emulated_devices.h
index 4cdbf9dc6..76f9150df 100644
--- a/src/core/hid/emulated_devices.h
+++ b/src/core/hid/emulated_devices.h
@@ -26,11 +26,9 @@ using MouseButtonDevices = std::array<std::unique_ptr<Common::Input::InputDevice
using MouseAnalogDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
Settings::NativeMouseWheel::NumMouseWheels>;
using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>;
-using RingAnalogDevice = std::unique_ptr<Common::Input::InputDevice>;
using MouseButtonParams =
std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>;
-using RingAnalogParams = Common::ParamPackage;
using KeyboardValues =
std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>;
@@ -41,17 +39,12 @@ using MouseButtonValues =
using MouseAnalogValues =
std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>;
using MouseStickValue = Common::Input::TouchStatus;
-using RingAnalogValue = Common::Input::AnalogStatus;
struct MousePosition {
f32 x;
f32 y;
};
-struct RingSensorForce {
- f32 force;
-};
-
struct DeviceStatus {
// Data from input_common
KeyboardValues keyboard_values{};
@@ -59,7 +52,6 @@ struct DeviceStatus {
MouseButtonValues mouse_button_values{};
MouseAnalogValues mouse_analog_values{};
MouseStickValue mouse_stick_value{};
- RingAnalogValue ring_analog_value{};
// Data for HID serices
KeyboardKey keyboard_state{};
@@ -67,7 +59,6 @@ struct DeviceStatus {
MouseButton mouse_button_state{};
MousePosition mouse_position_state{};
AnalogStickState mouse_wheel_state{};
- RingSensorForce ring_analog_state{};
};
enum class DeviceTriggerType {
@@ -138,9 +129,6 @@ public:
/// Returns the latest status of button input from the mouse with parameters
MouseButtonValues GetMouseButtonsValues() const;
- /// Returns the latest status of analog input from the ring sensor with parameters
- RingAnalogValue GetRingSensorValues() const;
-
/// Returns the latest status of button input from the keyboard
KeyboardKey GetKeyboard() const;
@@ -156,9 +144,6 @@ public:
/// Returns the latest mouse wheel change
AnalogStickState GetMouseWheel() const;
- /// Returns the latest ringcon force sensor value
- RingSensorForce GetRingSensorForce() const;
-
/**
* Adds a callback to the list of events
* @param update_callback InterfaceUpdateCallback that will be triggered
@@ -224,14 +209,11 @@ private:
bool is_configuring{false};
- RingAnalogParams ring_params;
-
KeyboardDevices keyboard_devices;
KeyboardModifierDevices keyboard_modifier_devices;
MouseButtonDevices mouse_button_devices;
MouseAnalogDevices mouse_analog_devices;
MouseStickDevice mouse_stick_device;
- RingAnalogDevice ring_analog_device;
mutable std::mutex mutex;
mutable std::mutex callback_mutex;