diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2022-12-21 02:10:42 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-01-20 01:05:21 +0100 |
commit | 751d36e7392b0b1637f17988cfc1ef0d7cd95753 (patch) | |
tree | 8ba772846be04719e41f82ef059ee81491a7c0e9 /src/input_common/helpers/joycon_driver.cpp | |
parent | input_common: Add support for joycon input reports (diff) | |
download | yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.gz yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.bz2 yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.lz yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.xz yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.zst yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.zip |
Diffstat (limited to 'src/input_common/helpers/joycon_driver.cpp')
-rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index 5d0aeabf5..c0a03fe2e 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp @@ -52,12 +52,18 @@ DriverResult JoyconDriver::InitializeDevice() { error_counter = 0; hidapi_handle->packet_counter = 0; + // Reset external device status + starlink_connected = false; + ring_connected = false; + amiibo_detected = false; + // Set HW default configuration vibration_enabled = true; motion_enabled = true; hidbus_enabled = false; nfc_enabled = false; passive_enabled = false; + irs_enabled = false; gyro_sensitivity = Joycon::GyroSensitivity::DPS2000; gyro_performance = Joycon::GyroPerformance::HZ833; accelerometer_sensitivity = Joycon::AccelerometerSensitivity::G8; @@ -66,6 +72,7 @@ DriverResult JoyconDriver::InitializeDevice() { // Initialize HW Protocols calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); + ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle); rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); // Get fixed joycon info @@ -172,9 +179,23 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { .accelerometer_sensitivity = accelerometer_sensitivity, }; + // TODO: Remove this when calibration is properly loaded and not calculated + if (ring_connected && report_mode == InputReport::STANDARD_FULL_60HZ) { + InputReportActive data{}; + memcpy(&data, buffer.data(), sizeof(InputReportActive)); + calibration_protocol->GetRingCalibration(ring_calibration, data.ring_input); + } + + const RingStatus ring_status{ + .is_enabled = ring_connected, + .default_value = ring_calibration.default_value, + .max_value = ring_calibration.max_value, + .min_value = ring_calibration.min_value, + }; + switch (report_mode) { case InputReport::STANDARD_FULL_60HZ: - joycon_poller->ReadActiveMode(buffer, motion_status); + joycon_poller->ReadActiveMode(buffer, motion_status, ring_status); break; case InputReport::NFC_IR_MODE_60HZ: joycon_poller->ReadNfcIRMode(buffer, motion_status); @@ -204,6 +225,26 @@ void JoyconDriver::SetPollingMode() { generic_protocol->EnableImu(false); } + if (ring_protocol->IsEnabled()) { + ring_connected = false; + ring_protocol->DisableRingCon(); + } + + if (hidbus_enabled && supported_features.hidbus) { + auto result = ring_protocol->EnableRingCon(); + if (result == DriverResult::Success) { + result = ring_protocol->StartRingconPolling(); + } + if (result == DriverResult::Success) { + ring_connected = true; + disable_input_thread = false; + return; + } + ring_connected = false; + ring_protocol->DisableRingCon(); + LOG_ERROR(Input, "Error enabling Ringcon"); + } + if (passive_enabled && supported_features.passive) { const auto result = generic_protocol->EnablePassiveMode(); if (result == DriverResult::Success) { |