forked from ShuriZma/suyu
1
0
Fork 0

core: hid: Migrate ring from emulated devices to emulated controller

This commit is contained in:
Narr the Reg 2022-12-20 13:09:10 -06:00
parent 18c9f8eeed
commit a4074001fe
8 changed files with 105 additions and 88 deletions

View File

@ -139,6 +139,7 @@ void EmulatedController::LoadDevices() {
camera_params = Common::ParamPackage{"engine:camera,camera:1"}; camera_params = Common::ParamPackage{"engine:camera,camera:1"};
nfc_params = Common::ParamPackage{"engine:virtual_amiibo,nfc: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[LeftIndex] = left_joycon;
output_params[RightIndex] = right_joycon; output_params[RightIndex] = right_joycon;
@ -160,6 +161,7 @@ void EmulatedController::LoadDevices() {
std::ranges::transform(battery_params, battery_devices.begin(), std::ranges::transform(battery_params, battery_devices.begin(),
Common::Input::CreateInputDevice); Common::Input::CreateInputDevice);
camera_devices = Common::Input::CreateInputDevice(camera_params); camera_devices = Common::Input::CreateInputDevice(camera_params);
ring_analog_device = Common::Input::CreateInputDevice(ring_params);
nfc_devices = Common::Input::CreateInputDevice(nfc_params); nfc_devices = Common::Input::CreateInputDevice(nfc_params);
std::ranges::transform(output_params, output_devices.begin(), std::ranges::transform(output_params, output_devices.begin(),
Common::Input::CreateOutputDevice); Common::Input::CreateOutputDevice);
@ -343,6 +345,13 @@ void EmulatedController::ReloadInput() {
camera_devices->ForceUpdate(); 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 (nfc_devices) {
if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) { if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) {
nfc_devices->SetCallback({ nfc_devices->SetCallback({
@ -436,6 +445,7 @@ void EmulatedController::UnloadInput() {
stick.reset(); stick.reset();
} }
camera_devices.reset(); camera_devices.reset();
ring_analog_device.reset();
nfc_devices.reset(); nfc_devices.reset();
} }
@ -501,6 +511,7 @@ void EmulatedController::SaveCurrentConfig() {
for (std::size_t index = 0; index < player.motions.size(); ++index) { for (std::size_t index = 0; index < player.motions.size(); ++index) {
player.motions[index] = motion_params[index].Serialize(); player.motions[index] = motion_params[index].Serialize();
} }
Settings::values.ringcon_analogs = ring_params.Serialize();
} }
void EmulatedController::RestoreConfig() { void EmulatedController::RestoreConfig() {
@ -1005,6 +1016,24 @@ void EmulatedController::SetCamera(const Common::Input::CallbackStatus& callback
TriggerOnChange(ControllerTriggerType::IrSensor, true); 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) { void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) {
std::unique_lock lock{mutex}; std::unique_lock lock{mutex};
controller.nfc_values = TransformToNfc(callback); controller.nfc_values = TransformToNfc(callback);
@ -1104,6 +1133,15 @@ bool EmulatedController::SetCameraFormat(
camera_format)) == Common::Input::CameraError::None; 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 { bool EmulatedController::HasNfc() const {
const auto& nfc_output_device = output_devices[3]; const auto& nfc_output_device = output_devices[3];
@ -1395,6 +1433,10 @@ CameraValues EmulatedController::GetCameraValues() const {
return controller.camera_values; return controller.camera_values;
} }
RingAnalogValue EmulatedController::GetRingSensorValues() const {
return controller.ring_analog_value;
}
HomeButtonState EmulatedController::GetHomeButtons() const { HomeButtonState EmulatedController::GetHomeButtons() const {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
if (is_configuring) { if (is_configuring) {
@ -1478,6 +1520,10 @@ const CameraState& EmulatedController::GetCamera() const {
return controller.camera_state; return controller.camera_state;
} }
RingSensorForce EmulatedController::GetRingSensorForce() const {
return controller.ring_analog_state;
}
const NfcState& EmulatedController::GetNfc() const { const NfcState& EmulatedController::GetNfc() const {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
return controller.nfc_state; return controller.nfc_state;

View File

@ -38,6 +38,7 @@ using TriggerDevices =
using BatteryDevices = using BatteryDevices =
std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>;
using CameraDevices = std::unique_ptr<Common::Input::InputDevice>; 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 NfcDevices = std::unique_ptr<Common::Input::InputDevice>;
using OutputDevices = std::array<std::unique_ptr<Common::Input::OutputDevice>, output_devices_size>; 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 TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::NumTriggers>;
using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>;
using CameraParams = Common::ParamPackage; using CameraParams = Common::ParamPackage;
using RingAnalogParams = Common::ParamPackage;
using NfcParams = Common::ParamPackage; using NfcParams = Common::ParamPackage;
using OutputParams = std::array<Common::ParamPackage, output_devices_size>; 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 ColorValues = std::array<Common::Input::BodyColorStatus, max_emulated_controllers>;
using BatteryValues = std::array<Common::Input::BatteryStatus, max_emulated_controllers>; using BatteryValues = std::array<Common::Input::BatteryStatus, max_emulated_controllers>;
using CameraValues = Common::Input::CameraStatus; using CameraValues = Common::Input::CameraStatus;
using RingAnalogValue = Common::Input::AnalogStatus;
using NfcValues = Common::Input::NfcStatus; using NfcValues = Common::Input::NfcStatus;
using VibrationValues = std::array<Common::Input::VibrationStatus, max_emulated_controllers>; using VibrationValues = std::array<Common::Input::VibrationStatus, max_emulated_controllers>;
@ -84,6 +87,10 @@ struct CameraState {
std::size_t sample{}; std::size_t sample{};
}; };
struct RingSensorForce {
f32 force;
};
struct NfcState { struct NfcState {
Common::Input::NfcState state{}; Common::Input::NfcState state{};
std::vector<u8> data{}; std::vector<u8> data{};
@ -116,6 +123,7 @@ struct ControllerStatus {
BatteryValues battery_values{}; BatteryValues battery_values{};
VibrationValues vibration_values{}; VibrationValues vibration_values{};
CameraValues camera_values{}; CameraValues camera_values{};
RingAnalogValue ring_analog_value{};
NfcValues nfc_values{}; NfcValues nfc_values{};
// Data for HID serices // Data for HID serices
@ -129,6 +137,7 @@ struct ControllerStatus {
ControllerColors colors_state{}; ControllerColors colors_state{};
BatteryLevelState battery_state{}; BatteryLevelState battery_state{};
CameraState camera_state{}; CameraState camera_state{};
RingSensorForce ring_analog_state{};
NfcState nfc_state{}; NfcState nfc_state{};
}; };
@ -141,6 +150,7 @@ enum class ControllerTriggerType {
Battery, Battery,
Vibration, Vibration,
IrSensor, IrSensor,
RingController,
Nfc, Nfc,
Connected, Connected,
Disconnected, Disconnected,
@ -294,6 +304,9 @@ public:
/// Returns the latest camera status from the controller with parameters /// Returns the latest camera status from the controller with parameters
CameraValues GetCameraValues() const; 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 /// Returns the latest status of button input for the hid::HomeButton service
HomeButtonState GetHomeButtons() const; HomeButtonState GetHomeButtons() const;
@ -324,6 +337,9 @@ public:
/// Returns the latest camera status from the controller /// Returns the latest camera status from the controller
const CameraState& GetCamera() const; const CameraState& GetCamera() const;
/// Returns the latest ringcon force sensor value
RingSensorForce GetRingSensorForce() const;
/// Returns the latest ntag status from the controller /// Returns the latest ntag status from the controller
const NfcState& GetNfc() const; const NfcState& GetNfc() const;
@ -353,6 +369,15 @@ public:
*/ */
bool SetCameraFormat(Core::IrSensor::ImageTransferProcessorFormat camera_format); 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 /// Returns true if the device has nfc support
bool HasNfc() const; bool HasNfc() const;
@ -435,7 +460,7 @@ private:
/** /**
* Updates the battery status of the controller * Updates the battery status of the controller
* @param callback A CallbackStatus containing the battery status * @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); void SetBattery(const Common::Input::CallbackStatus& callback, std::size_t index);
@ -445,6 +470,12 @@ private:
*/ */
void SetCamera(const Common::Input::CallbackStatus& callback); 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 * Updates the nfc status of the controller
* @param callback A CallbackStatus containing the nfc status * @param callback A CallbackStatus containing the nfc status
@ -485,6 +516,7 @@ private:
TriggerParams trigger_params; TriggerParams trigger_params;
BatteryParams battery_params; BatteryParams battery_params;
CameraParams camera_params; CameraParams camera_params;
RingAnalogParams ring_params;
NfcParams nfc_params; NfcParams nfc_params;
OutputParams output_params; OutputParams output_params;
@ -494,6 +526,7 @@ private:
TriggerDevices trigger_devices; TriggerDevices trigger_devices;
BatteryDevices battery_devices; BatteryDevices battery_devices;
CameraDevices camera_devices; CameraDevices camera_devices;
RingAnalogDevice ring_analog_device;
NfcDevices nfc_devices; NfcDevices nfc_devices;
OutputDevices output_devices; OutputDevices output_devices;

View File

@ -14,7 +14,6 @@ EmulatedDevices::EmulatedDevices() = default;
EmulatedDevices::~EmulatedDevices() = default; EmulatedDevices::~EmulatedDevices() = default;
void EmulatedDevices::ReloadFromSettings() { void EmulatedDevices::ReloadFromSettings() {
ring_params = Common::ParamPackage(Settings::values.ringcon_analogs);
ReloadInput(); ReloadInput();
} }
@ -66,8 +65,6 @@ void EmulatedDevices::ReloadInput() {
key_index++; key_index++;
} }
ring_analog_device = Common::Input::CreateInputDevice(ring_params);
for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) { for (std::size_t index = 0; index < mouse_button_devices.size(); ++index) {
if (!mouse_button_devices[index]) { if (!mouse_button_devices[index]) {
continue; 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() { void EmulatedDevices::UnloadInput() {
@ -145,7 +135,6 @@ void EmulatedDevices::UnloadInput() {
for (auto& button : keyboard_modifier_devices) { for (auto& button : keyboard_modifier_devices) {
button.reset(); button.reset();
} }
ring_analog_device.reset();
} }
void EmulatedDevices::EnableConfiguration() { void EmulatedDevices::EnableConfiguration() {
@ -165,7 +154,6 @@ void EmulatedDevices::SaveCurrentConfig() {
if (!is_configuring) { if (!is_configuring) {
return; return;
} }
Settings::values.ringcon_analogs = ring_params.Serialize();
} }
void EmulatedDevices::RestoreConfig() { void EmulatedDevices::RestoreConfig() {
@ -175,15 +163,6 @@ void EmulatedDevices::RestoreConfig() {
ReloadFromSettings(); 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, void EmulatedDevices::SetKeyboardButton(const Common::Input::CallbackStatus& callback,
std::size_t index) { std::size_t index) {
if (index >= device_status.keyboard_values.size()) { if (index >= device_status.keyboard_values.size()) {
@ -430,23 +409,6 @@ void EmulatedDevices::SetMouseStick(const Common::Input::CallbackStatus& callbac
TriggerOnChange(DeviceTriggerType::Mouse); 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 { KeyboardValues EmulatedDevices::GetKeyboardValues() const {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
return device_status.keyboard_values; return device_status.keyboard_values;
@ -462,10 +424,6 @@ MouseButtonValues EmulatedDevices::GetMouseButtonsValues() const {
return device_status.mouse_button_values; return device_status.mouse_button_values;
} }
RingAnalogValue EmulatedDevices::GetRingSensorValues() const {
return device_status.ring_analog_value;
}
KeyboardKey EmulatedDevices::GetKeyboard() const { KeyboardKey EmulatedDevices::GetKeyboard() const {
std::scoped_lock lock{mutex}; std::scoped_lock lock{mutex};
return device_status.keyboard_state; return device_status.keyboard_state;
@ -491,10 +449,6 @@ AnalogStickState EmulatedDevices::GetMouseWheel() const {
return device_status.mouse_wheel_state; return device_status.mouse_wheel_state;
} }
RingSensorForce EmulatedDevices::GetRingSensorForce() const {
return device_status.ring_analog_state;
}
void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) { void EmulatedDevices::TriggerOnChange(DeviceTriggerType type) {
std::scoped_lock lock{callback_mutex}; std::scoped_lock lock{callback_mutex};
for (const auto& poller_pair : callback_list) { for (const auto& poller_pair : callback_list) {

View File

@ -26,11 +26,9 @@ using MouseButtonDevices = std::array<std::unique_ptr<Common::Input::InputDevice
using MouseAnalogDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, using MouseAnalogDevices = std::array<std::unique_ptr<Common::Input::InputDevice>,
Settings::NativeMouseWheel::NumMouseWheels>; Settings::NativeMouseWheel::NumMouseWheels>;
using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>; using MouseStickDevice = std::unique_ptr<Common::Input::InputDevice>;
using RingAnalogDevice = std::unique_ptr<Common::Input::InputDevice>;
using MouseButtonParams = using MouseButtonParams =
std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>; std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons>;
using RingAnalogParams = Common::ParamPackage;
using KeyboardValues = using KeyboardValues =
std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>; std::array<Common::Input::ButtonStatus, Settings::NativeKeyboard::NumKeyboardKeys>;
@ -41,17 +39,12 @@ using MouseButtonValues =
using MouseAnalogValues = using MouseAnalogValues =
std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>; std::array<Common::Input::AnalogStatus, Settings::NativeMouseWheel::NumMouseWheels>;
using MouseStickValue = Common::Input::TouchStatus; using MouseStickValue = Common::Input::TouchStatus;
using RingAnalogValue = Common::Input::AnalogStatus;
struct MousePosition { struct MousePosition {
f32 x; f32 x;
f32 y; f32 y;
}; };
struct RingSensorForce {
f32 force;
};
struct DeviceStatus { struct DeviceStatus {
// Data from input_common // Data from input_common
KeyboardValues keyboard_values{}; KeyboardValues keyboard_values{};
@ -59,7 +52,6 @@ struct DeviceStatus {
MouseButtonValues mouse_button_values{}; MouseButtonValues mouse_button_values{};
MouseAnalogValues mouse_analog_values{}; MouseAnalogValues mouse_analog_values{};
MouseStickValue mouse_stick_value{}; MouseStickValue mouse_stick_value{};
RingAnalogValue ring_analog_value{};
// Data for HID serices // Data for HID serices
KeyboardKey keyboard_state{}; KeyboardKey keyboard_state{};
@ -67,7 +59,6 @@ struct DeviceStatus {
MouseButton mouse_button_state{}; MouseButton mouse_button_state{};
MousePosition mouse_position_state{}; MousePosition mouse_position_state{};
AnalogStickState mouse_wheel_state{}; AnalogStickState mouse_wheel_state{};
RingSensorForce ring_analog_state{};
}; };
enum class DeviceTriggerType { enum class DeviceTriggerType {
@ -138,9 +129,6 @@ public:
/// Returns the latest status of button input from the mouse with parameters /// Returns the latest status of button input from the mouse with parameters
MouseButtonValues GetMouseButtonsValues() const; 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 /// Returns the latest status of button input from the keyboard
KeyboardKey GetKeyboard() const; KeyboardKey GetKeyboard() const;
@ -156,9 +144,6 @@ public:
/// Returns the latest mouse wheel change /// Returns the latest mouse wheel change
AnalogStickState GetMouseWheel() const; AnalogStickState GetMouseWheel() const;
/// Returns the latest ringcon force sensor value
RingSensorForce GetRingSensorForce() const;
/** /**
* Adds a callback to the list of events * Adds a callback to the list of events
* @param update_callback InterfaceUpdateCallback that will be triggered * @param update_callback InterfaceUpdateCallback that will be triggered
@ -224,14 +209,11 @@ private:
bool is_configuring{false}; bool is_configuring{false};
RingAnalogParams ring_params;
KeyboardDevices keyboard_devices; KeyboardDevices keyboard_devices;
KeyboardModifierDevices keyboard_modifier_devices; KeyboardModifierDevices keyboard_modifier_devices;
MouseButtonDevices mouse_button_devices; MouseButtonDevices mouse_button_devices;
MouseAnalogDevices mouse_analog_devices; MouseAnalogDevices mouse_analog_devices;
MouseStickDevice mouse_stick_device; MouseStickDevice mouse_stick_device;
RingAnalogDevice ring_analog_device;
mutable std::mutex mutex; mutable std::mutex mutex;
mutable std::mutex callback_mutex; mutable std::mutex callback_mutex;

View File

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_controller.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_event.h"
#include "core/hle/kernel/k_readable_event.h" #include "core/hle/kernel/k_readable_event.h"
@ -12,16 +12,18 @@ namespace Service::HID {
RingController::RingController(Core::HID::HIDCore& hid_core_, RingController::RingController(Core::HID::HIDCore& hid_core_,
KernelHelpers::ServiceContext& service_context_) KernelHelpers::ServiceContext& service_context_)
: HidbusBase(service_context_) { : HidbusBase(service_context_) {
input = hid_core_.GetEmulatedDevices(); input = hid_core_.GetEmulatedController(Core::HID::NpadIdType::Player1);
} }
RingController::~RingController() = default; RingController::~RingController() = default;
void RingController::OnInit() { void RingController::OnInit() {
input->SetPollingMode(Common::Input::PollingMode::Ring);
return; return;
} }
void RingController::OnRelease() { void RingController::OnRelease() {
input->SetPollingMode(Common::Input::PollingMode::Active);
return; return;
}; };

View File

@ -9,7 +9,7 @@
#include "core/hle/service/hid/hidbus/hidbus_base.h" #include "core/hle/service/hid/hidbus/hidbus_base.h"
namespace Core::HID { namespace Core::HID {
class EmulatedDevices; class EmulatedController;
} // namespace Core::HID } // namespace Core::HID
namespace Service::HID { namespace Service::HID {
@ -248,6 +248,6 @@ private:
.zero = {.value = idle_value, .crc = 225}, .zero = {.value = idle_value, .crc = 225},
}; };
Core::HID::EmulatedDevices* input; Core::HID::EmulatedController* input;
}; };
} // namespace Service::HID } // namespace Service::HID

View File

@ -6,7 +6,7 @@
#include <QMenu> #include <QMenu>
#include <QTimer> #include <QTimer>
#include "core/hid/emulated_devices.h" #include "core/hid/emulated_controller.h"
#include "core/hid/hid_core.h" #include "core/hid/hid_core.h"
#include "input_common/drivers/keyboard.h" #include "input_common/drivers/keyboard.h"
#include "input_common/drivers/mouse.h" #include "input_common/drivers/mouse.h"
@ -126,9 +126,9 @@ ConfigureRingController::ConfigureRingController(QWidget* parent,
ui->buttonRingAnalogPush, ui->buttonRingAnalogPush,
}; };
emulated_device = hid_core_.GetEmulatedDevices(); emulated_controller = hid_core_.GetEmulatedController(Core::HID::NpadIdType::Player1);
emulated_device->SaveCurrentConfig(); emulated_controller->SaveCurrentConfig();
emulated_device->EnableConfiguration(); emulated_controller->EnableConfiguration();
LoadConfiguration(); LoadConfiguration();
@ -143,9 +143,9 @@ ConfigureRingController::ConfigureRingController(QWidget* parent,
HandleClick( HandleClick(
analog_map_buttons[sub_button_id], analog_map_buttons[sub_button_id],
[=, this](const Common::ParamPackage& params) { [=, this](const Common::ParamPackage& params) {
Common::ParamPackage param = emulated_device->GetRingParam(); Common::ParamPackage param = emulated_controller->GetRingParam();
SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]); SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]);
emulated_device->SetRingParam(param); emulated_controller->SetRingParam(param);
}, },
InputCommon::Polling::InputType::Stick); InputCommon::Polling::InputType::Stick);
}); });
@ -155,16 +155,16 @@ ConfigureRingController::ConfigureRingController(QWidget* parent,
connect(analog_button, &QPushButton::customContextMenuRequested, connect(analog_button, &QPushButton::customContextMenuRequested,
[=, this](const QPoint& menu_location) { [=, this](const QPoint& menu_location) {
QMenu context_menu; QMenu context_menu;
Common::ParamPackage param = emulated_device->GetRingParam(); Common::ParamPackage param = emulated_controller->GetRingParam();
context_menu.addAction(tr("Clear"), [&] { context_menu.addAction(tr("Clear"), [&] {
emulated_device->SetRingParam({}); emulated_controller->SetRingParam(param);
analog_map_buttons[sub_button_id]->setText(tr("[not set]")); analog_map_buttons[sub_button_id]->setText(tr("[not set]"));
}); });
context_menu.addAction(tr("Invert axis"), [&] { context_menu.addAction(tr("Invert axis"), [&] {
const bool invert_value = param.Get("invert_x", "+") == "-"; const bool invert_value = param.Get("invert_x", "+") == "-";
const std::string invert_str = invert_value ? "+" : "-"; const std::string invert_str = invert_value ? "+" : "-";
param.Set("invert_x", invert_str); param.Set("invert_x", invert_str);
emulated_device->SetRingParam(param); emulated_controller->SetRingParam(param);
for (int sub_button_id2 = 0; sub_button_id2 < ANALOG_SUB_BUTTONS_NUM; for (int sub_button_id2 = 0; sub_button_id2 < ANALOG_SUB_BUTTONS_NUM;
++sub_button_id2) { ++sub_button_id2) {
analog_map_buttons[sub_button_id2]->setText( analog_map_buttons[sub_button_id2]->setText(
@ -177,11 +177,11 @@ ConfigureRingController::ConfigureRingController(QWidget* parent,
} }
connect(ui->sliderRingAnalogDeadzone, &QSlider::valueChanged, [=, this] { connect(ui->sliderRingAnalogDeadzone, &QSlider::valueChanged, [=, this] {
Common::ParamPackage param = emulated_device->GetRingParam(); Common::ParamPackage param = emulated_controller->GetRingParam();
const auto slider_value = ui->sliderRingAnalogDeadzone->value(); const auto slider_value = ui->sliderRingAnalogDeadzone->value();
ui->labelRingAnalogDeadzone->setText(tr("Deadzone: %1%").arg(slider_value)); ui->labelRingAnalogDeadzone->setText(tr("Deadzone: %1%").arg(slider_value));
param.Set("deadzone", slider_value / 100.0f); param.Set("deadzone", slider_value / 100.0f);
emulated_device->SetRingParam(param); emulated_controller->SetRingParam(param);
}); });
connect(ui->restore_defaults_button, &QPushButton::clicked, this, connect(ui->restore_defaults_button, &QPushButton::clicked, this,
@ -202,7 +202,7 @@ ConfigureRingController::ConfigureRingController(QWidget* parent,
} }
ConfigureRingController::~ConfigureRingController() { ConfigureRingController::~ConfigureRingController() {
emulated_device->DisableConfiguration(); emulated_controller->DisableConfiguration();
}; };
void ConfigureRingController::changeEvent(QEvent* event) { void ConfigureRingController::changeEvent(QEvent* event) {
@ -219,7 +219,7 @@ void ConfigureRingController::RetranslateUI() {
void ConfigureRingController::UpdateUI() { void ConfigureRingController::UpdateUI() {
RetranslateUI(); RetranslateUI();
const Common::ParamPackage param = emulated_device->GetRingParam(); const Common::ParamPackage param = emulated_controller->GetRingParam();
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[sub_button_id]; auto* const analog_button = analog_map_buttons[sub_button_id];
@ -240,9 +240,9 @@ void ConfigureRingController::UpdateUI() {
} }
void ConfigureRingController::ApplyConfiguration() { void ConfigureRingController::ApplyConfiguration() {
emulated_device->DisableConfiguration(); emulated_controller->DisableConfiguration();
emulated_device->SaveCurrentConfig(); emulated_controller->SaveCurrentConfig();
emulated_device->EnableConfiguration(); emulated_controller->EnableConfiguration();
} }
void ConfigureRingController::LoadConfiguration() { void ConfigureRingController::LoadConfiguration() {
@ -252,7 +252,7 @@ void ConfigureRingController::LoadConfiguration() {
void ConfigureRingController::RestoreDefaults() { void ConfigureRingController::RestoreDefaults() {
const std::string default_ring_string = InputCommon::GenerateAnalogParamFromKeys( const std::string default_ring_string = InputCommon::GenerateAnalogParamFromKeys(
0, 0, Config::default_ringcon_analogs[0], Config::default_ringcon_analogs[1], 0, 0.05f); 0, 0, Config::default_ringcon_analogs[0], Config::default_ringcon_analogs[1], 0, 0.05f);
emulated_device->SetRingParam(Common::ParamPackage(default_ring_string)); emulated_controller->SetRingParam(Common::ParamPackage(default_ring_string));
UpdateUI(); UpdateUI();
} }

View File

@ -13,7 +13,7 @@ class InputSubsystem;
namespace Core::HID { namespace Core::HID {
class HIDCore; class HIDCore;
class EmulatedDevices; class EmulatedController;
} // namespace Core::HID } // namespace Core::HID
namespace Ui { namespace Ui {
@ -78,7 +78,7 @@ private:
std::optional<std::function<void(const Common::ParamPackage&)>> input_setter; std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
InputCommon::InputSubsystem* input_subsystem; InputCommon::InputSubsystem* input_subsystem;
Core::HID::EmulatedDevices* emulated_device; Core::HID::EmulatedController* emulated_controller;
std::unique_ptr<Ui::ConfigureRingController> ui; std::unique_ptr<Ui::ConfigureRingController> ui;
}; };