diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2022-12-20 21:30:03 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-01-20 01:05:21 +0100 |
commit | 594b2ade6d8d829c65166aebe12f5eb3463a6fe9 (patch) | |
tree | d6d8013f6252cc9051429f39da255fe6937c8346 /src/input_common/helpers/joycon_driver.cpp | |
parent | input_common: Add joycon low level functions (diff) | |
download | yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.gz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.bz2 yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.lz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.xz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.zst yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.zip |
Diffstat (limited to '')
-rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index a0a2a180b..0de55578b 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp @@ -64,13 +64,24 @@ DriverResult JoyconDriver::InitializeDevice() { accelerometer_performance = Joycon::AccelerometerPerformance::HZ100; // Initialize HW Protocols + generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); // Get fixed joycon info + generic_protocol->GetVersionNumber(version); + generic_protocol->GetColor(color); + if (handle_device_type == ControllerType::Pro) { + // Some 3rd party controllers aren't pro controllers + generic_protocol->GetControllerType(device_type); + } else { + device_type = handle_device_type; + } + generic_protocol->GetSerialNumber(serial_number); supported_features = GetSupportedFeatures(); // Get Calibration data // Set led status + generic_protocol->SetLedBlinkPattern(static_cast<u8>(1 + port)); // Apply HW configuration SetPollingMode(); @@ -137,6 +148,9 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { case InputReport::SIMPLE_HID_MODE: ReadPassiveMode(buffer); break; + case InputReport::SUBCMD_REPLY: + LOG_DEBUG(Input, "Unhandled command reply"); + break; default: LOG_ERROR(Input, "Report mode not Implemented {}", report_mode); break; @@ -145,6 +159,30 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { void JoyconDriver::SetPollingMode() { disable_input_thread = true; + + if (motion_enabled && supported_features.motion) { + generic_protocol->EnableImu(true); + generic_protocol->SetImuConfig(gyro_sensitivity, gyro_performance, + accelerometer_sensitivity, accelerometer_performance); + } else { + generic_protocol->EnableImu(false); + } + + if (passive_enabled && supported_features.passive) { + const auto result = generic_protocol->EnablePassiveMode(); + if (result == DriverResult::Success) { + disable_input_thread = false; + return; + } + LOG_ERROR(Input, "Error enabling passive mode"); + } + + // Default Mode + const auto result = generic_protocol->EnableActiveMode(); + if (result != DriverResult::Success) { + LOG_ERROR(Input, "Error enabling active mode"); + } + disable_input_thread = false; } @@ -257,15 +295,22 @@ bool JoyconDriver::IsPayloadCorrect(int status, std::span<const u8> buffer) { DriverResult JoyconDriver::SetVibration(const VibrationValue& vibration) { std::scoped_lock lock{mutex}; + if (disable_input_thread) { + return DriverResult::HandleInUse; + } return DriverResult::NotSupported; } DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { std::scoped_lock lock{mutex}; - return DriverResult::NotSupported; + if (disable_input_thread) { + return DriverResult::HandleInUse; + } + return generic_protocol->SetLedPattern(led_pattern); } DriverResult JoyconDriver::SetPasiveMode() { + std::scoped_lock lock{mutex}; motion_enabled = false; hidbus_enabled = false; nfc_enabled = false; @@ -275,7 +320,8 @@ DriverResult JoyconDriver::SetPasiveMode() { } DriverResult JoyconDriver::SetActiveMode() { - motion_enabled = false; + std::scoped_lock lock{mutex}; + motion_enabled = true; hidbus_enabled = false; nfc_enabled = false; passive_enabled = false; @@ -284,6 +330,7 @@ DriverResult JoyconDriver::SetActiveMode() { } DriverResult JoyconDriver::SetNfcMode() { + std::scoped_lock lock{mutex}; motion_enabled = false; hidbus_enabled = false; nfc_enabled = true; @@ -293,6 +340,7 @@ DriverResult JoyconDriver::SetNfcMode() { } DriverResult JoyconDriver::SetRingConMode() { + std::scoped_lock lock{mutex}; motion_enabled = true; hidbus_enabled = true; nfc_enabled = false; @@ -328,7 +376,7 @@ std::size_t JoyconDriver::GetDevicePort() const { ControllerType JoyconDriver::GetDeviceType() const { std::scoped_lock lock{mutex}; - return handle_device_type; + return device_type; } ControllerType JoyconDriver::GetHandleDeviceType() const { |