summaryrefslogtreecommitdiff
path: root/src/input_common/helpers/joycon_driver.cpp
diff options
context:
space:
mode:
authorGravatar german772022-12-26 12:49:49 -0600
committerGravatar Narr the Reg2023-01-19 18:05:22 -0600
commit5cb437703fa441a08db295f8a916caedc3a581f2 (patch)
tree148c35e47d18462f0b8f8e116e2247b4cbfdbde2 /src/input_common/helpers/joycon_driver.cpp
parentinput_common: Use DriverResult on all engines (diff)
downloadyuzu-5cb437703fa441a08db295f8a916caedc3a581f2.tar.gz
yuzu-5cb437703fa441a08db295f8a916caedc3a581f2.tar.xz
yuzu-5cb437703fa441a08db295f8a916caedc3a581f2.zip
yuzu: Add ring controller test button
Diffstat (limited to 'src/input_common/helpers/joycon_driver.cpp')
-rw-r--r--src/input_common/helpers/joycon_driver.cpp38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp
index b00b6110b..8217ba7f6 100644
--- a/src/input_common/helpers/joycon_driver.cpp
+++ b/src/input_common/helpers/joycon_driver.cpp
@@ -238,7 +238,7 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) {
238 } 238 }
239} 239}
240 240
241void JoyconDriver::SetPollingMode() { 241DriverResult JoyconDriver::SetPollingMode() {
242 disable_input_thread = true; 242 disable_input_thread = true;
243 243
244 rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration); 244 rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration);
@@ -263,7 +263,7 @@ void JoyconDriver::SetPollingMode() {
263 } 263 }
264 if (result == DriverResult::Success) { 264 if (result == DriverResult::Success) {
265 disable_input_thread = false; 265 disable_input_thread = false;
266 return; 266 return result;
267 } 267 }
268 nfc_protocol->DisableNfc(); 268 nfc_protocol->DisableNfc();
269 LOG_ERROR(Input, "Error enabling NFC"); 269 LOG_ERROR(Input, "Error enabling NFC");
@@ -282,7 +282,7 @@ void JoyconDriver::SetPollingMode() {
282 if (result == DriverResult::Success) { 282 if (result == DriverResult::Success) {
283 ring_connected = true; 283 ring_connected = true;
284 disable_input_thread = false; 284 disable_input_thread = false;
285 return; 285 return result;
286 } 286 }
287 ring_connected = false; 287 ring_connected = false;
288 ring_protocol->DisableRingCon(); 288 ring_protocol->DisableRingCon();
@@ -293,7 +293,7 @@ void JoyconDriver::SetPollingMode() {
293 const auto result = generic_protocol->EnablePassiveMode(); 293 const auto result = generic_protocol->EnablePassiveMode();
294 if (result == DriverResult::Success) { 294 if (result == DriverResult::Success) {
295 disable_input_thread = false; 295 disable_input_thread = false;
296 return; 296 return result;
297 } 297 }
298 LOG_ERROR(Input, "Error enabling passive mode"); 298 LOG_ERROR(Input, "Error enabling passive mode");
299 } 299 }
@@ -305,6 +305,7 @@ void JoyconDriver::SetPollingMode() {
305 } 305 }
306 306
307 disable_input_thread = false; 307 disable_input_thread = false;
308 return result;
308} 309}
309 310
310JoyconDriver::SupportedFeatures JoyconDriver::GetSupportedFeatures() { 311JoyconDriver::SupportedFeatures JoyconDriver::GetSupportedFeatures() {
@@ -380,8 +381,7 @@ DriverResult JoyconDriver::SetPasiveMode() {
380 hidbus_enabled = false; 381 hidbus_enabled = false;
381 nfc_enabled = false; 382 nfc_enabled = false;
382 passive_enabled = true; 383 passive_enabled = true;
383 SetPollingMode(); 384 return SetPollingMode();
384 return DriverResult::Success;
385} 385}
386 386
387DriverResult JoyconDriver::SetActiveMode() { 387DriverResult JoyconDriver::SetActiveMode() {
@@ -390,28 +390,42 @@ DriverResult JoyconDriver::SetActiveMode() {
390 hidbus_enabled = false; 390 hidbus_enabled = false;
391 nfc_enabled = false; 391 nfc_enabled = false;
392 passive_enabled = false; 392 passive_enabled = false;
393 SetPollingMode(); 393 return SetPollingMode();
394 return DriverResult::Success;
395} 394}
396 395
397DriverResult JoyconDriver::SetNfcMode() { 396DriverResult JoyconDriver::SetNfcMode() {
398 std::scoped_lock lock{mutex}; 397 std::scoped_lock lock{mutex};
398
399 if (!supported_features.nfc) {
400 return DriverResult::NotSupported;
401 }
402
399 motion_enabled = true; 403 motion_enabled = true;
400 hidbus_enabled = false; 404 hidbus_enabled = false;
401 nfc_enabled = true; 405 nfc_enabled = true;
402 passive_enabled = false; 406 passive_enabled = false;
403 SetPollingMode(); 407 return SetPollingMode();
404 return DriverResult::Success;
405} 408}
406 409
407DriverResult JoyconDriver::SetRingConMode() { 410DriverResult JoyconDriver::SetRingConMode() {
408 std::scoped_lock lock{mutex}; 411 std::scoped_lock lock{mutex};
412
413 if (!supported_features.hidbus) {
414 return DriverResult::NotSupported;
415 }
416
409 motion_enabled = true; 417 motion_enabled = true;
410 hidbus_enabled = true; 418 hidbus_enabled = true;
411 nfc_enabled = false; 419 nfc_enabled = false;
412 passive_enabled = false; 420 passive_enabled = false;
413 SetPollingMode(); 421
414 return DriverResult::Success; 422 const auto result = SetPollingMode();
423
424 if (!ring_connected) {
425 return DriverResult::NoDeviceDetected;
426 }
427
428 return result;
415} 429}
416 430
417bool JoyconDriver::IsConnected() const { 431bool JoyconDriver::IsConnected() const {