From 5cb437703fa441a08db295f8a916caedc3a581f2 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 26 Dec 2022 12:49:49 -0600 Subject: yuzu: Add ring controller test button --- src/input_common/helpers/joycon_driver.cpp | 38 ++++++++++++++++++++---------- src/input_common/helpers/joycon_driver.h | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src/input_common/helpers') 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 buffer) { } } -void JoyconDriver::SetPollingMode() { +DriverResult JoyconDriver::SetPollingMode() { disable_input_thread = true; rumble_protocol->EnableRumble(vibration_enabled && supported_features.vibration); @@ -263,7 +263,7 @@ void JoyconDriver::SetPollingMode() { } if (result == DriverResult::Success) { disable_input_thread = false; - return; + return result; } nfc_protocol->DisableNfc(); LOG_ERROR(Input, "Error enabling NFC"); @@ -282,7 +282,7 @@ void JoyconDriver::SetPollingMode() { if (result == DriverResult::Success) { ring_connected = true; disable_input_thread = false; - return; + return result; } ring_connected = false; ring_protocol->DisableRingCon(); @@ -293,7 +293,7 @@ void JoyconDriver::SetPollingMode() { const auto result = generic_protocol->EnablePassiveMode(); if (result == DriverResult::Success) { disable_input_thread = false; - return; + return result; } LOG_ERROR(Input, "Error enabling passive mode"); } @@ -305,6 +305,7 @@ void JoyconDriver::SetPollingMode() { } disable_input_thread = false; + return result; } JoyconDriver::SupportedFeatures JoyconDriver::GetSupportedFeatures() { @@ -380,8 +381,7 @@ DriverResult JoyconDriver::SetPasiveMode() { hidbus_enabled = false; nfc_enabled = false; passive_enabled = true; - SetPollingMode(); - return DriverResult::Success; + return SetPollingMode(); } DriverResult JoyconDriver::SetActiveMode() { @@ -390,28 +390,42 @@ DriverResult JoyconDriver::SetActiveMode() { hidbus_enabled = false; nfc_enabled = false; passive_enabled = false; - SetPollingMode(); - return DriverResult::Success; + return SetPollingMode(); } DriverResult JoyconDriver::SetNfcMode() { std::scoped_lock lock{mutex}; + + if (!supported_features.nfc) { + return DriverResult::NotSupported; + } + motion_enabled = true; hidbus_enabled = false; nfc_enabled = true; passive_enabled = false; - SetPollingMode(); - return DriverResult::Success; + return SetPollingMode(); } DriverResult JoyconDriver::SetRingConMode() { std::scoped_lock lock{mutex}; + + if (!supported_features.hidbus) { + return DriverResult::NotSupported; + } + motion_enabled = true; hidbus_enabled = true; nfc_enabled = false; passive_enabled = false; - SetPollingMode(); - return DriverResult::Success; + + const auto result = SetPollingMode(); + + if (!ring_connected) { + return DriverResult::NoDeviceDetected; + } + + return result; } bool JoyconDriver::IsConnected() const { diff --git a/src/input_common/helpers/joycon_driver.h b/src/input_common/helpers/joycon_driver.h index bf38a3009..5ff15c784 100644 --- a/src/input_common/helpers/joycon_driver.h +++ b/src/input_common/helpers/joycon_driver.h @@ -73,7 +73,7 @@ private: void OnNewData(std::span buffer); /// Updates device configuration to enable or disable features - void SetPollingMode(); + DriverResult SetPollingMode(); /// Returns true if input thread is valid and doesn't need to be stopped bool IsInputThreadValid() const; -- cgit v1.2.3