summaryrefslogtreecommitdiff
path: root/src/input_common/helpers/joycon_driver.cpp
diff options
context:
space:
mode:
authorGravatar Narr the Reg2022-12-20 19:10:42 -0600
committerGravatar Narr the Reg2023-01-19 18:05:21 -0600
commit751d36e7392b0b1637f17988cfc1ef0d7cd95753 (patch)
tree8ba772846be04719e41f82ef059ee81491a7c0e9 /src/input_common/helpers/joycon_driver.cpp
parentinput_common: Add support for joycon input reports (diff)
downloadyuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.gz
yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.tar.xz
yuzu-751d36e7392b0b1637f17988cfc1ef0d7cd95753.zip
input_common: Add support for joycon ring controller
Diffstat (limited to 'src/input_common/helpers/joycon_driver.cpp')
-rw-r--r--src/input_common/helpers/joycon_driver.cpp43
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() {
52 error_counter = 0; 52 error_counter = 0;
53 hidapi_handle->packet_counter = 0; 53 hidapi_handle->packet_counter = 0;
54 54
55 // Reset external device status
56 starlink_connected = false;
57 ring_connected = false;
58 amiibo_detected = false;
59
55 // Set HW default configuration 60 // Set HW default configuration
56 vibration_enabled = true; 61 vibration_enabled = true;
57 motion_enabled = true; 62 motion_enabled = true;
58 hidbus_enabled = false; 63 hidbus_enabled = false;
59 nfc_enabled = false; 64 nfc_enabled = false;
60 passive_enabled = false; 65 passive_enabled = false;
66 irs_enabled = false;
61 gyro_sensitivity = Joycon::GyroSensitivity::DPS2000; 67 gyro_sensitivity = Joycon::GyroSensitivity::DPS2000;
62 gyro_performance = Joycon::GyroPerformance::HZ833; 68 gyro_performance = Joycon::GyroPerformance::HZ833;
63 accelerometer_sensitivity = Joycon::AccelerometerSensitivity::G8; 69 accelerometer_sensitivity = Joycon::AccelerometerSensitivity::G8;
@@ -66,6 +72,7 @@ DriverResult JoyconDriver::InitializeDevice() {
66 // Initialize HW Protocols 72 // Initialize HW Protocols
67 calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); 73 calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle);
68 generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); 74 generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle);
75 ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle);
69 rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); 76 rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle);
70 77
71 // Get fixed joycon info 78 // Get fixed joycon info
@@ -172,9 +179,23 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) {
172 .accelerometer_sensitivity = accelerometer_sensitivity, 179 .accelerometer_sensitivity = accelerometer_sensitivity,
173 }; 180 };
174 181
182 // TODO: Remove this when calibration is properly loaded and not calculated
183 if (ring_connected && report_mode == InputReport::STANDARD_FULL_60HZ) {
184 InputReportActive data{};
185 memcpy(&data, buffer.data(), sizeof(InputReportActive));
186 calibration_protocol->GetRingCalibration(ring_calibration, data.ring_input);
187 }
188
189 const RingStatus ring_status{
190 .is_enabled = ring_connected,
191 .default_value = ring_calibration.default_value,
192 .max_value = ring_calibration.max_value,
193 .min_value = ring_calibration.min_value,
194 };
195
175 switch (report_mode) { 196 switch (report_mode) {
176 case InputReport::STANDARD_FULL_60HZ: 197 case InputReport::STANDARD_FULL_60HZ:
177 joycon_poller->ReadActiveMode(buffer, motion_status); 198 joycon_poller->ReadActiveMode(buffer, motion_status, ring_status);
178 break; 199 break;
179 case InputReport::NFC_IR_MODE_60HZ: 200 case InputReport::NFC_IR_MODE_60HZ:
180 joycon_poller->ReadNfcIRMode(buffer, motion_status); 201 joycon_poller->ReadNfcIRMode(buffer, motion_status);
@@ -204,6 +225,26 @@ void JoyconDriver::SetPollingMode() {
204 generic_protocol->EnableImu(false); 225 generic_protocol->EnableImu(false);
205 } 226 }
206 227
228 if (ring_protocol->IsEnabled()) {
229 ring_connected = false;
230 ring_protocol->DisableRingCon();
231 }
232
233 if (hidbus_enabled && supported_features.hidbus) {
234 auto result = ring_protocol->EnableRingCon();
235 if (result == DriverResult::Success) {
236 result = ring_protocol->StartRingconPolling();
237 }
238 if (result == DriverResult::Success) {
239 ring_connected = true;
240 disable_input_thread = false;
241 return;
242 }
243 ring_connected = false;
244 ring_protocol->DisableRingCon();
245 LOG_ERROR(Input, "Error enabling Ringcon");
246 }
247
207 if (passive_enabled && supported_features.passive) { 248 if (passive_enabled && supported_features.passive) {
208 const auto result = generic_protocol->EnablePassiveMode(); 249 const auto result = generic_protocol->EnablePassiveMode();
209 if (result == DriverResult::Success) { 250 if (result == DriverResult::Success) {