diff options
| author | 2022-12-20 14:30:03 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:21 -0600 | |
| 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.gz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.tar.xz yuzu-594b2ade6d8d829c65166aebe12f5eb3463a6fe9.zip | |
input_common: Add support for joycon generic functions
Diffstat (limited to 'src/input_common/helpers/joycon_driver.cpp')
| -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() { | |||
| 64 | accelerometer_performance = Joycon::AccelerometerPerformance::HZ100; | 64 | accelerometer_performance = Joycon::AccelerometerPerformance::HZ100; |
| 65 | 65 | ||
| 66 | // Initialize HW Protocols | 66 | // Initialize HW Protocols |
| 67 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); | ||
| 67 | 68 | ||
| 68 | // Get fixed joycon info | 69 | // Get fixed joycon info |
| 70 | generic_protocol->GetVersionNumber(version); | ||
| 71 | generic_protocol->GetColor(color); | ||
| 72 | if (handle_device_type == ControllerType::Pro) { | ||
| 73 | // Some 3rd party controllers aren't pro controllers | ||
| 74 | generic_protocol->GetControllerType(device_type); | ||
| 75 | } else { | ||
| 76 | device_type = handle_device_type; | ||
| 77 | } | ||
| 78 | generic_protocol->GetSerialNumber(serial_number); | ||
| 69 | supported_features = GetSupportedFeatures(); | 79 | supported_features = GetSupportedFeatures(); |
| 70 | 80 | ||
| 71 | // Get Calibration data | 81 | // Get Calibration data |
| 72 | 82 | ||
| 73 | // Set led status | 83 | // Set led status |
| 84 | generic_protocol->SetLedBlinkPattern(static_cast<u8>(1 + port)); | ||
| 74 | 85 | ||
| 75 | // Apply HW configuration | 86 | // Apply HW configuration |
| 76 | SetPollingMode(); | 87 | SetPollingMode(); |
| @@ -137,6 +148,9 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 137 | case InputReport::SIMPLE_HID_MODE: | 148 | case InputReport::SIMPLE_HID_MODE: |
| 138 | ReadPassiveMode(buffer); | 149 | ReadPassiveMode(buffer); |
| 139 | break; | 150 | break; |
| 151 | case InputReport::SUBCMD_REPLY: | ||
| 152 | LOG_DEBUG(Input, "Unhandled command reply"); | ||
| 153 | break; | ||
| 140 | default: | 154 | default: |
| 141 | LOG_ERROR(Input, "Report mode not Implemented {}", report_mode); | 155 | LOG_ERROR(Input, "Report mode not Implemented {}", report_mode); |
| 142 | break; | 156 | break; |
| @@ -145,6 +159,30 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 145 | 159 | ||
| 146 | void JoyconDriver::SetPollingMode() { | 160 | void JoyconDriver::SetPollingMode() { |
| 147 | disable_input_thread = true; | 161 | disable_input_thread = true; |
| 162 | |||
| 163 | if (motion_enabled && supported_features.motion) { | ||
| 164 | generic_protocol->EnableImu(true); | ||
| 165 | generic_protocol->SetImuConfig(gyro_sensitivity, gyro_performance, | ||
| 166 | accelerometer_sensitivity, accelerometer_performance); | ||
| 167 | } else { | ||
| 168 | generic_protocol->EnableImu(false); | ||
| 169 | } | ||
| 170 | |||
| 171 | if (passive_enabled && supported_features.passive) { | ||
| 172 | const auto result = generic_protocol->EnablePassiveMode(); | ||
| 173 | if (result == DriverResult::Success) { | ||
| 174 | disable_input_thread = false; | ||
| 175 | return; | ||
| 176 | } | ||
| 177 | LOG_ERROR(Input, "Error enabling passive mode"); | ||
| 178 | } | ||
| 179 | |||
| 180 | // Default Mode | ||
| 181 | const auto result = generic_protocol->EnableActiveMode(); | ||
| 182 | if (result != DriverResult::Success) { | ||
| 183 | LOG_ERROR(Input, "Error enabling active mode"); | ||
| 184 | } | ||
| 185 | |||
| 148 | disable_input_thread = false; | 186 | disable_input_thread = false; |
| 149 | } | 187 | } |
| 150 | 188 | ||
| @@ -257,15 +295,22 @@ bool JoyconDriver::IsPayloadCorrect(int status, std::span<const u8> buffer) { | |||
| 257 | 295 | ||
| 258 | DriverResult JoyconDriver::SetVibration(const VibrationValue& vibration) { | 296 | DriverResult JoyconDriver::SetVibration(const VibrationValue& vibration) { |
| 259 | std::scoped_lock lock{mutex}; | 297 | std::scoped_lock lock{mutex}; |
| 298 | if (disable_input_thread) { | ||
| 299 | return DriverResult::HandleInUse; | ||
| 300 | } | ||
| 260 | return DriverResult::NotSupported; | 301 | return DriverResult::NotSupported; |
| 261 | } | 302 | } |
| 262 | 303 | ||
| 263 | DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { | 304 | DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { |
| 264 | std::scoped_lock lock{mutex}; | 305 | std::scoped_lock lock{mutex}; |
| 265 | return DriverResult::NotSupported; | 306 | if (disable_input_thread) { |
| 307 | return DriverResult::HandleInUse; | ||
| 308 | } | ||
| 309 | return generic_protocol->SetLedPattern(led_pattern); | ||
| 266 | } | 310 | } |
| 267 | 311 | ||
| 268 | DriverResult JoyconDriver::SetPasiveMode() { | 312 | DriverResult JoyconDriver::SetPasiveMode() { |
| 313 | std::scoped_lock lock{mutex}; | ||
| 269 | motion_enabled = false; | 314 | motion_enabled = false; |
| 270 | hidbus_enabled = false; | 315 | hidbus_enabled = false; |
| 271 | nfc_enabled = false; | 316 | nfc_enabled = false; |
| @@ -275,7 +320,8 @@ DriverResult JoyconDriver::SetPasiveMode() { | |||
| 275 | } | 320 | } |
| 276 | 321 | ||
| 277 | DriverResult JoyconDriver::SetActiveMode() { | 322 | DriverResult JoyconDriver::SetActiveMode() { |
| 278 | motion_enabled = false; | 323 | std::scoped_lock lock{mutex}; |
| 324 | motion_enabled = true; | ||
| 279 | hidbus_enabled = false; | 325 | hidbus_enabled = false; |
| 280 | nfc_enabled = false; | 326 | nfc_enabled = false; |
| 281 | passive_enabled = false; | 327 | passive_enabled = false; |
| @@ -284,6 +330,7 @@ DriverResult JoyconDriver::SetActiveMode() { | |||
| 284 | } | 330 | } |
| 285 | 331 | ||
| 286 | DriverResult JoyconDriver::SetNfcMode() { | 332 | DriverResult JoyconDriver::SetNfcMode() { |
| 333 | std::scoped_lock lock{mutex}; | ||
| 287 | motion_enabled = false; | 334 | motion_enabled = false; |
| 288 | hidbus_enabled = false; | 335 | hidbus_enabled = false; |
| 289 | nfc_enabled = true; | 336 | nfc_enabled = true; |
| @@ -293,6 +340,7 @@ DriverResult JoyconDriver::SetNfcMode() { | |||
| 293 | } | 340 | } |
| 294 | 341 | ||
| 295 | DriverResult JoyconDriver::SetRingConMode() { | 342 | DriverResult JoyconDriver::SetRingConMode() { |
| 343 | std::scoped_lock lock{mutex}; | ||
| 296 | motion_enabled = true; | 344 | motion_enabled = true; |
| 297 | hidbus_enabled = true; | 345 | hidbus_enabled = true; |
| 298 | nfc_enabled = false; | 346 | nfc_enabled = false; |
| @@ -328,7 +376,7 @@ std::size_t JoyconDriver::GetDevicePort() const { | |||
| 328 | 376 | ||
| 329 | ControllerType JoyconDriver::GetDeviceType() const { | 377 | ControllerType JoyconDriver::GetDeviceType() const { |
| 330 | std::scoped_lock lock{mutex}; | 378 | std::scoped_lock lock{mutex}; |
| 331 | return handle_device_type; | 379 | return device_type; |
| 332 | } | 380 | } |
| 333 | 381 | ||
| 334 | ControllerType JoyconDriver::GetHandleDeviceType() const { | 382 | ControllerType JoyconDriver::GetHandleDeviceType() const { |