summaryrefslogtreecommitdiffstats
path: root/src/input_common/drivers/joycon.cpp
diff options
context:
space:
mode:
authorNarr the Reg <juangerman-13@hotmail.com>2023-02-10 02:59:12 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2023-02-10 03:08:54 +0100
commitacba9a6b769f96a35e02669d87ce7b19fc47b025 (patch)
tree7ebd5f331962f67ad037b086c5550c69c6dcaf64 /src/input_common/drivers/joycon.cpp
parentMerge pull request #9749 from ameerj/pr9559-partial-revert (diff)
downloadyuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.tar
yuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.tar.gz
yuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.tar.bz2
yuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.tar.lz
yuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.tar.xz
yuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.tar.zst
yuzu-acba9a6b769f96a35e02669d87ce7b19fc47b025.zip
Diffstat (limited to 'src/input_common/drivers/joycon.cpp')
-rw-r--r--src/input_common/drivers/joycon.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp
index 4fcfb4510..afc33db57 100644
--- a/src/input_common/drivers/joycon.cpp
+++ b/src/input_common/drivers/joycon.cpp
@@ -16,7 +16,7 @@ namespace InputCommon {
Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) {
// Avoid conflicting with SDL driver
- if (!Settings::values.enable_joycon_driver) {
+ if (!Settings::values.enable_joycon_driver && !Settings::values.enable_procon_driver) {
return;
}
LOG_INFO(Input, "Joycon driver Initialization started");
@@ -46,6 +46,12 @@ void Joycons::Reset() {
}
device->Stop();
}
+ for (const auto& device : pro_controller) {
+ if (!device) {
+ continue;
+ }
+ device->Stop();
+ }
SDL_hid_exit();
}
@@ -61,6 +67,11 @@ void Joycons::Setup() {
PreSetController(GetIdentifier(port, Joycon::ControllerType::Right));
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); });
}
@@ -116,6 +127,9 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
// Check if device already exist
switch (type) {
case Joycon::ControllerType::Left:
+ if (!Settings::values.enable_joycon_driver) {
+ return false;
+ }
for (const auto& device : left_joycons) {
if (is_handle_identical(device)) {
return false;
@@ -123,12 +137,25 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
}
break;
case Joycon::ControllerType::Right:
+ if (!Settings::values.enable_joycon_driver) {
+ return false;
+ }
for (const auto& device : right_joycons) {
if (is_handle_identical(device)) {
return false;
}
}
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:
return false;
}
@@ -199,6 +226,14 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetNextFreeHandle(
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;
}
@@ -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;
}
@@ -455,6 +499,9 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
for (const auto& controller : right_joycons) {
add_entry(controller);
}
+ for (const auto& controller : pro_controller) {
+ add_entry(controller);
+ }
// List dual joycon pairs
for (std::size_t i = 0; i < MaxSupportedControllers; i++) {