mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-25 19:00:05 +00:00
input_common: Reintroduce custom pro controller support
This commit is contained in:
parent
7bad3a7e5e
commit
acba9a6b76
@ -488,6 +488,7 @@ struct Values {
|
|||||||
Setting<bool> enable_raw_input{false, "enable_raw_input"};
|
Setting<bool> enable_raw_input{false, "enable_raw_input"};
|
||||||
Setting<bool> controller_navigation{true, "controller_navigation"};
|
Setting<bool> controller_navigation{true, "controller_navigation"};
|
||||||
Setting<bool> enable_joycon_driver{true, "enable_joycon_driver"};
|
Setting<bool> enable_joycon_driver{true, "enable_joycon_driver"};
|
||||||
|
Setting<bool> enable_procon_driver{false, "enable_procon_driver"};
|
||||||
|
|
||||||
SwitchableSetting<bool> vibration_enabled{true, "vibration_enabled"};
|
SwitchableSetting<bool> vibration_enabled{true, "vibration_enabled"};
|
||||||
SwitchableSetting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"};
|
SwitchableSetting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"};
|
||||||
|
@ -16,7 +16,7 @@ namespace InputCommon {
|
|||||||
|
|
||||||
Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) {
|
Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) {
|
||||||
// Avoid conflicting with SDL driver
|
// Avoid conflicting with SDL driver
|
||||||
if (!Settings::values.enable_joycon_driver) {
|
if (!Settings::values.enable_joycon_driver && !Settings::values.enable_procon_driver) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG_INFO(Input, "Joycon driver Initialization started");
|
LOG_INFO(Input, "Joycon driver Initialization started");
|
||||||
@ -46,6 +46,12 @@ void Joycons::Reset() {
|
|||||||
}
|
}
|
||||||
device->Stop();
|
device->Stop();
|
||||||
}
|
}
|
||||||
|
for (const auto& device : pro_controller) {
|
||||||
|
if (!device) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
device->Stop();
|
||||||
|
}
|
||||||
SDL_hid_exit();
|
SDL_hid_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +67,11 @@ void Joycons::Setup() {
|
|||||||
PreSetController(GetIdentifier(port, Joycon::ControllerType::Right));
|
PreSetController(GetIdentifier(port, Joycon::ControllerType::Right));
|
||||||
device = std::make_shared<Joycon::JoyconDriver>(port++);
|
device = std::make_shared<Joycon::JoyconDriver>(port++);
|
||||||
}
|
}
|
||||||
|
port = 0;
|
||||||
|
for (auto& device : pro_controller) {
|
||||||
|
PreSetController(GetIdentifier(port, Joycon::ControllerType::Pro));
|
||||||
|
device = std::make_shared<Joycon::JoyconDriver>(port++);
|
||||||
|
}
|
||||||
|
|
||||||
scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
|
scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
|
||||||
}
|
}
|
||||||
@ -116,6 +127,9 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
|
|||||||
// Check if device already exist
|
// Check if device already exist
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Joycon::ControllerType::Left:
|
case Joycon::ControllerType::Left:
|
||||||
|
if (!Settings::values.enable_joycon_driver) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (const auto& device : left_joycons) {
|
for (const auto& device : left_joycons) {
|
||||||
if (is_handle_identical(device)) {
|
if (is_handle_identical(device)) {
|
||||||
return false;
|
return false;
|
||||||
@ -123,12 +137,25 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Joycon::ControllerType::Right:
|
case Joycon::ControllerType::Right:
|
||||||
|
if (!Settings::values.enable_joycon_driver) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (const auto& device : right_joycons) {
|
for (const auto& device : right_joycons) {
|
||||||
if (is_handle_identical(device)) {
|
if (is_handle_identical(device)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Joycon::ControllerType::Pro:
|
||||||
|
if (!Settings::values.enable_procon_driver) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const auto& device : pro_controller) {
|
||||||
|
if (is_handle_identical(device)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -199,6 +226,14 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetNextFreeHandle(
|
|||||||
return *unconnected_device;
|
return *unconnected_device;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (type == Joycon::ControllerType::Pro) {
|
||||||
|
const auto unconnected_device = std::ranges::find_if(
|
||||||
|
pro_controller, [](auto& device) { return !device->IsConnected(); });
|
||||||
|
|
||||||
|
if (unconnected_device != pro_controller.end()) {
|
||||||
|
return *unconnected_device;
|
||||||
|
}
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,6 +444,15 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == Joycon::ControllerType::Pro) {
|
||||||
|
const auto matching_device = std::ranges::find_if(
|
||||||
|
pro_controller, [is_handle_active](auto& device) { return is_handle_active(device); });
|
||||||
|
|
||||||
|
if (matching_device != pro_controller.end()) {
|
||||||
|
return *matching_device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -455,6 +499,9 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
|
|||||||
for (const auto& controller : right_joycons) {
|
for (const auto& controller : right_joycons) {
|
||||||
add_entry(controller);
|
add_entry(controller);
|
||||||
}
|
}
|
||||||
|
for (const auto& controller : pro_controller) {
|
||||||
|
add_entry(controller);
|
||||||
|
}
|
||||||
|
|
||||||
// List dual joycon pairs
|
// List dual joycon pairs
|
||||||
for (std::size_t i = 0; i < MaxSupportedControllers; i++) {
|
for (std::size_t i = 0; i < MaxSupportedControllers; i++) {
|
||||||
|
@ -106,6 +106,7 @@ private:
|
|||||||
// Joycon types are split by type to ease supporting dualjoycon configurations
|
// Joycon types are split by type to ease supporting dualjoycon configurations
|
||||||
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};
|
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};
|
||||||
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> right_joycons{};
|
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> right_joycons{};
|
||||||
|
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> pro_controller{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace InputCommon
|
} // namespace InputCommon
|
||||||
|
@ -343,6 +343,14 @@ void SDLDriver::InitJoystick(int joystick_index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Settings::values.enable_procon_driver) {
|
||||||
|
if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e && guid.uuid[8] == 0x09) {
|
||||||
|
LOG_WARNING(Input, "Preferring joycon driver for device index {}", joystick_index);
|
||||||
|
SDL_JoystickClose(sdl_joystick);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::scoped_lock lock{joystick_map_mutex};
|
std::scoped_lock lock{joystick_map_mutex};
|
||||||
if (joystick_map.find(guid) == joystick_map.end()) {
|
if (joystick_map.find(guid) == joystick_map.end()) {
|
||||||
auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller);
|
auto joystick = std::make_shared<SDLJoystick>(guid, 0, sdl_joystick, sdl_gamecontroller);
|
||||||
@ -465,13 +473,19 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en
|
|||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||||
|
|
||||||
// Disable hidapi drivers for switch controllers when the custom joycon driver is enabled
|
// Disable hidapi drivers for joycon controllers when the custom joycon driver is enabled
|
||||||
if (Settings::values.enable_joycon_driver) {
|
if (Settings::values.enable_joycon_driver) {
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "0");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "0");
|
||||||
} else {
|
} else {
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
|
||||||
}
|
}
|
||||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "1");
|
|
||||||
|
// Disable hidapi drivers for pro controllers when the custom joycon driver is enabled
|
||||||
|
if (Settings::values.enable_procon_driver) {
|
||||||
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "0");
|
||||||
|
} else {
|
||||||
|
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH, "1");
|
||||||
|
}
|
||||||
|
|
||||||
// Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native
|
// Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native
|
||||||
// driver on Linux.
|
// driver on Linux.
|
||||||
|
@ -543,9 +543,10 @@ void JoyconDriver::SetCallbacks(const JoyconCallbacks& callbacks) {
|
|||||||
|
|
||||||
DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* device_info,
|
DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* device_info,
|
||||||
ControllerType& controller_type) {
|
ControllerType& controller_type) {
|
||||||
static constexpr std::array<std::pair<u32, ControllerType>, 2> supported_devices{
|
static constexpr std::array<std::pair<u32, ControllerType>, 6> supported_devices{
|
||||||
std::pair<u32, ControllerType>{0x2006, ControllerType::Left},
|
std::pair<u32, ControllerType>{0x2006, ControllerType::Left},
|
||||||
{0x2007, ControllerType::Right},
|
{0x2007, ControllerType::Right},
|
||||||
|
{0x2009, ControllerType::Pro},
|
||||||
};
|
};
|
||||||
constexpr u16 nintendo_vendor_id = 0x057e;
|
constexpr u16 nintendo_vendor_id = 0x057e;
|
||||||
|
|
||||||
|
@ -441,6 +441,7 @@ void Config::ReadControlValues() {
|
|||||||
Settings::values.mouse_panning = false;
|
Settings::values.mouse_panning = false;
|
||||||
ReadBasicSetting(Settings::values.mouse_panning_sensitivity);
|
ReadBasicSetting(Settings::values.mouse_panning_sensitivity);
|
||||||
ReadBasicSetting(Settings::values.enable_joycon_driver);
|
ReadBasicSetting(Settings::values.enable_joycon_driver);
|
||||||
|
ReadBasicSetting(Settings::values.enable_procon_driver);
|
||||||
|
|
||||||
ReadBasicSetting(Settings::values.tas_enable);
|
ReadBasicSetting(Settings::values.tas_enable);
|
||||||
ReadBasicSetting(Settings::values.tas_loop);
|
ReadBasicSetting(Settings::values.tas_loop);
|
||||||
@ -1141,6 +1142,7 @@ void Config::SaveControlValues() {
|
|||||||
WriteGlobalSetting(Settings::values.motion_enabled);
|
WriteGlobalSetting(Settings::values.motion_enabled);
|
||||||
WriteBasicSetting(Settings::values.enable_raw_input);
|
WriteBasicSetting(Settings::values.enable_raw_input);
|
||||||
WriteBasicSetting(Settings::values.enable_joycon_driver);
|
WriteBasicSetting(Settings::values.enable_joycon_driver);
|
||||||
|
WriteBasicSetting(Settings::values.enable_procon_driver);
|
||||||
WriteBasicSetting(Settings::values.keyboard_enabled);
|
WriteBasicSetting(Settings::values.keyboard_enabled);
|
||||||
WriteBasicSetting(Settings::values.emulate_analog_keyboard);
|
WriteBasicSetting(Settings::values.emulate_analog_keyboard);
|
||||||
WriteBasicSetting(Settings::values.mouse_panning_sensitivity);
|
WriteBasicSetting(Settings::values.mouse_panning_sensitivity);
|
||||||
|
@ -139,6 +139,7 @@ void ConfigureInputAdvanced::ApplyConfiguration() {
|
|||||||
Settings::values.enable_ring_controller = ui->enable_ring_controller->isChecked();
|
Settings::values.enable_ring_controller = ui->enable_ring_controller->isChecked();
|
||||||
Settings::values.enable_ir_sensor = ui->enable_ir_sensor->isChecked();
|
Settings::values.enable_ir_sensor = ui->enable_ir_sensor->isChecked();
|
||||||
Settings::values.enable_joycon_driver = ui->enable_joycon_driver->isChecked();
|
Settings::values.enable_joycon_driver = ui->enable_joycon_driver->isChecked();
|
||||||
|
Settings::values.enable_procon_driver = ui->enable_procon_driver->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureInputAdvanced::LoadConfiguration() {
|
void ConfigureInputAdvanced::LoadConfiguration() {
|
||||||
@ -174,6 +175,7 @@ void ConfigureInputAdvanced::LoadConfiguration() {
|
|||||||
ui->enable_ring_controller->setChecked(Settings::values.enable_ring_controller.GetValue());
|
ui->enable_ring_controller->setChecked(Settings::values.enable_ring_controller.GetValue());
|
||||||
ui->enable_ir_sensor->setChecked(Settings::values.enable_ir_sensor.GetValue());
|
ui->enable_ir_sensor->setChecked(Settings::values.enable_ir_sensor.GetValue());
|
||||||
ui->enable_joycon_driver->setChecked(Settings::values.enable_joycon_driver.GetValue());
|
ui->enable_joycon_driver->setChecked(Settings::values.enable_joycon_driver.GetValue());
|
||||||
|
ui->enable_procon_driver->setChecked(Settings::values.enable_procon_driver.GetValue());
|
||||||
|
|
||||||
UpdateUIEnabled();
|
UpdateUIEnabled();
|
||||||
}
|
}
|
||||||
|
@ -2712,6 +2712,22 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="6" column="0">
|
||||||
|
<widget class="QCheckBox" name="enable_procon_driver">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Requires restarting yuzu</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>23</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable direct Pro Controller driver [EXPERIMENTAL]</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="7" column="0">
|
||||||
<widget class="QCheckBox" name="mouse_panning">
|
<widget class="QCheckBox" name="mouse_panning">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
@ -2724,7 +2740,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="2">
|
<item row="7" column="2">
|
||||||
<widget class="QSpinBox" name="mouse_panning_sensitivity">
|
<widget class="QSpinBox" name="mouse_panning_sensitivity">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Mouse sensitivity</string>
|
<string>Mouse sensitivity</string>
|
||||||
@ -2746,14 +2762,14 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="0">
|
<item row="8" column="0">
|
||||||
<widget class="QLabel" name="motion_touch">
|
<widget class="QLabel" name="motion_touch">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Motion / Touch</string>
|
<string>Motion / Touch</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="2">
|
<item row="8" column="2">
|
||||||
<widget class="QPushButton" name="buttonMotionTouch">
|
<widget class="QPushButton" name="buttonMotionTouch">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Configure</string>
|
<string>Configure</string>
|
||||||
|
@ -178,6 +178,7 @@ void Config::ReadValues() {
|
|||||||
|
|
||||||
ReadSetting("ControlsGeneral", Settings::values.enable_raw_input);
|
ReadSetting("ControlsGeneral", Settings::values.enable_raw_input);
|
||||||
ReadSetting("ControlsGeneral", Settings::values.enable_joycon_driver);
|
ReadSetting("ControlsGeneral", Settings::values.enable_joycon_driver);
|
||||||
|
ReadSetting("ControlsGeneral", Settings::values.enable_procon_driver);
|
||||||
ReadSetting("ControlsGeneral", Settings::values.emulate_analog_keyboard);
|
ReadSetting("ControlsGeneral", Settings::values.emulate_analog_keyboard);
|
||||||
ReadSetting("ControlsGeneral", Settings::values.vibration_enabled);
|
ReadSetting("ControlsGeneral", Settings::values.vibration_enabled);
|
||||||
ReadSetting("ControlsGeneral", Settings::values.enable_accurate_vibrations);
|
ReadSetting("ControlsGeneral", Settings::values.enable_accurate_vibrations);
|
||||||
|
Loading…
Reference in New Issue
Block a user