summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/joycon.cpp
diff options
context:
space:
mode:
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 {
16 16
17Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) { 17Joycons::Joycons(const std::string& input_engine_) : InputEngine(input_engine_) {
18 // Avoid conflicting with SDL driver 18 // Avoid conflicting with SDL driver
19 if (!Settings::values.enable_joycon_driver) { 19 if (!Settings::values.enable_joycon_driver && !Settings::values.enable_procon_driver) {
20 return; 20 return;
21 } 21 }
22 LOG_INFO(Input, "Joycon driver Initialization started"); 22 LOG_INFO(Input, "Joycon driver Initialization started");
@@ -46,6 +46,12 @@ void Joycons::Reset() {
46 } 46 }
47 device->Stop(); 47 device->Stop();
48 } 48 }
49 for (const auto& device : pro_controller) {
50 if (!device) {
51 continue;
52 }
53 device->Stop();
54 }
49 SDL_hid_exit(); 55 SDL_hid_exit();
50} 56}
51 57
@@ -61,6 +67,11 @@ void Joycons::Setup() {
61 PreSetController(GetIdentifier(port, Joycon::ControllerType::Right)); 67 PreSetController(GetIdentifier(port, Joycon::ControllerType::Right));
62 device = std::make_shared<Joycon::JoyconDriver>(port++); 68 device = std::make_shared<Joycon::JoyconDriver>(port++);
63 } 69 }
70 port = 0;
71 for (auto& device : pro_controller) {
72 PreSetController(GetIdentifier(port, Joycon::ControllerType::Pro));
73 device = std::make_shared<Joycon::JoyconDriver>(port++);
74 }
64 75
65 scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); }); 76 scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); });
66} 77}
@@ -116,6 +127,9 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
116 // Check if device already exist 127 // Check if device already exist
117 switch (type) { 128 switch (type) {
118 case Joycon::ControllerType::Left: 129 case Joycon::ControllerType::Left:
130 if (!Settings::values.enable_joycon_driver) {
131 return false;
132 }
119 for (const auto& device : left_joycons) { 133 for (const auto& device : left_joycons) {
120 if (is_handle_identical(device)) { 134 if (is_handle_identical(device)) {
121 return false; 135 return false;
@@ -123,12 +137,25 @@ bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
123 } 137 }
124 break; 138 break;
125 case Joycon::ControllerType::Right: 139 case Joycon::ControllerType::Right:
140 if (!Settings::values.enable_joycon_driver) {
141 return false;
142 }
126 for (const auto& device : right_joycons) { 143 for (const auto& device : right_joycons) {
127 if (is_handle_identical(device)) { 144 if (is_handle_identical(device)) {
128 return false; 145 return false;
129 } 146 }
130 } 147 }
131 break; 148 break;
149 case Joycon::ControllerType::Pro:
150 if (!Settings::values.enable_procon_driver) {
151 return false;
152 }
153 for (const auto& device : pro_controller) {
154 if (is_handle_identical(device)) {
155 return false;
156 }
157 }
158 break;
132 default: 159 default:
133 return false; 160 return false;
134 } 161 }
@@ -199,6 +226,14 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetNextFreeHandle(
199 return *unconnected_device; 226 return *unconnected_device;
200 } 227 }
201 } 228 }
229 if (type == Joycon::ControllerType::Pro) {
230 const auto unconnected_device = std::ranges::find_if(
231 pro_controller, [](auto& device) { return !device->IsConnected(); });
232
233 if (unconnected_device != pro_controller.end()) {
234 return *unconnected_device;
235 }
236 }
202 return nullptr; 237 return nullptr;
203} 238}
204 239
@@ -409,6 +444,15 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
409 } 444 }
410 } 445 }
411 446
447 if (type == Joycon::ControllerType::Pro) {
448 const auto matching_device = std::ranges::find_if(
449 pro_controller, [is_handle_active](auto& device) { return is_handle_active(device); });
450
451 if (matching_device != pro_controller.end()) {
452 return *matching_device;
453 }
454 }
455
412 return nullptr; 456 return nullptr;
413} 457}
414 458
@@ -455,6 +499,9 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
455 for (const auto& controller : right_joycons) { 499 for (const auto& controller : right_joycons) {
456 add_entry(controller); 500 add_entry(controller);
457 } 501 }
502 for (const auto& controller : pro_controller) {
503 add_entry(controller);
504 }
458 505
459 // List dual joycon pairs 506 // List dual joycon pairs
460 for (std::size_t i = 0; i < MaxSupportedControllers; i++) { 507 for (std::size_t i = 0; i < MaxSupportedControllers; i++) {