diff options
Diffstat (limited to 'src/input_common/helpers/joycon_driver.cpp')
| -rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index 8217ba7f6..040832a4b 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include "input_common/helpers/joycon_driver.h" | 7 | #include "input_common/helpers/joycon_driver.h" |
| 8 | #include "input_common/helpers/joycon_protocol/calibration.h" | 8 | #include "input_common/helpers/joycon_protocol/calibration.h" |
| 9 | #include "input_common/helpers/joycon_protocol/generic_functions.h" | 9 | #include "input_common/helpers/joycon_protocol/generic_functions.h" |
| 10 | #include "input_common/helpers/joycon_protocol/irs.h" | ||
| 10 | #include "input_common/helpers/joycon_protocol/nfc.h" | 11 | #include "input_common/helpers/joycon_protocol/nfc.h" |
| 11 | #include "input_common/helpers/joycon_protocol/poller.h" | 12 | #include "input_common/helpers/joycon_protocol/poller.h" |
| 12 | #include "input_common/helpers/joycon_protocol/ringcon.h" | 13 | #include "input_common/helpers/joycon_protocol/ringcon.h" |
| @@ -78,6 +79,7 @@ DriverResult JoyconDriver::InitializeDevice() { | |||
| 78 | // Initialize HW Protocols | 79 | // Initialize HW Protocols |
| 79 | calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); | 80 | calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); |
| 80 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); | 81 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); |
| 82 | irs_protocol = std::make_unique<IrsProtocol>(hidapi_handle); | ||
| 81 | nfc_protocol = std::make_unique<NfcProtocol>(hidapi_handle); | 83 | nfc_protocol = std::make_unique<NfcProtocol>(hidapi_handle); |
| 82 | ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle); | 84 | ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle); |
| 83 | rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); | 85 | rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); |
| @@ -200,10 +202,15 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 200 | .min_value = ring_calibration.min_value, | 202 | .min_value = ring_calibration.min_value, |
| 201 | }; | 203 | }; |
| 202 | 204 | ||
| 205 | if (irs_protocol->IsEnabled()) { | ||
| 206 | irs_protocol->RequestImage(buffer); | ||
| 207 | joycon_poller->UpdateCamera(irs_protocol->GetImage(), irs_protocol->GetIrsFormat()); | ||
| 208 | } | ||
| 209 | |||
| 203 | if (nfc_protocol->IsEnabled()) { | 210 | if (nfc_protocol->IsEnabled()) { |
| 204 | if (amiibo_detected) { | 211 | if (amiibo_detected) { |
| 205 | if (!nfc_protocol->HasAmiibo()) { | 212 | if (!nfc_protocol->HasAmiibo()) { |
| 206 | joycon_poller->updateAmiibo({}); | 213 | joycon_poller->UpdateAmiibo({}); |
| 207 | amiibo_detected = false; | 214 | amiibo_detected = false; |
| 208 | return; | 215 | return; |
| 209 | } | 216 | } |
| @@ -213,7 +220,7 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 213 | std::vector<u8> data(0x21C); | 220 | std::vector<u8> data(0x21C); |
| 214 | const auto result = nfc_protocol->ScanAmiibo(data); | 221 | const auto result = nfc_protocol->ScanAmiibo(data); |
| 215 | if (result == DriverResult::Success) { | 222 | if (result == DriverResult::Success) { |
| 216 | joycon_poller->updateAmiibo(data); | 223 | joycon_poller->UpdateAmiibo(data); |
| 217 | amiibo_detected = true; | 224 | amiibo_detected = true; |
| 218 | } | 225 | } |
| 219 | } | 226 | } |
| @@ -251,6 +258,20 @@ DriverResult JoyconDriver::SetPollingMode() { | |||
| 251 | generic_protocol->EnableImu(false); | 258 | generic_protocol->EnableImu(false); |
| 252 | } | 259 | } |
| 253 | 260 | ||
| 261 | if (irs_protocol->IsEnabled()) { | ||
| 262 | irs_protocol->DisableIrs(); | ||
| 263 | } | ||
| 264 | |||
| 265 | if (irs_enabled && supported_features.irs) { | ||
| 266 | auto result = irs_protocol->EnableIrs(); | ||
| 267 | if (result == DriverResult::Success) { | ||
| 268 | disable_input_thread = false; | ||
| 269 | return result; | ||
| 270 | } | ||
| 271 | irs_protocol->DisableIrs(); | ||
| 272 | LOG_ERROR(Input, "Error enabling IRS"); | ||
| 273 | } | ||
| 274 | |||
| 254 | if (nfc_protocol->IsEnabled()) { | 275 | if (nfc_protocol->IsEnabled()) { |
| 255 | amiibo_detected = false; | 276 | amiibo_detected = false; |
| 256 | nfc_protocol->DisableNfc(); | 277 | nfc_protocol->DisableNfc(); |
| @@ -375,12 +396,24 @@ DriverResult JoyconDriver::SetLedConfig(u8 led_pattern) { | |||
| 375 | return generic_protocol->SetLedPattern(led_pattern); | 396 | return generic_protocol->SetLedPattern(led_pattern); |
| 376 | } | 397 | } |
| 377 | 398 | ||
| 399 | DriverResult JoyconDriver::SetIrsConfig(IrsMode mode_, IrsResolution format_) { | ||
| 400 | std::scoped_lock lock{mutex}; | ||
| 401 | if (disable_input_thread) { | ||
| 402 | return DriverResult::HandleInUse; | ||
| 403 | } | ||
| 404 | disable_input_thread = true; | ||
| 405 | const auto result = irs_protocol->SetIrsConfig(mode_, format_); | ||
| 406 | disable_input_thread = false; | ||
| 407 | return result; | ||
| 408 | } | ||
| 409 | |||
| 378 | DriverResult JoyconDriver::SetPasiveMode() { | 410 | DriverResult JoyconDriver::SetPasiveMode() { |
| 379 | std::scoped_lock lock{mutex}; | 411 | std::scoped_lock lock{mutex}; |
| 380 | motion_enabled = false; | 412 | motion_enabled = false; |
| 381 | hidbus_enabled = false; | 413 | hidbus_enabled = false; |
| 382 | nfc_enabled = false; | 414 | nfc_enabled = false; |
| 383 | passive_enabled = true; | 415 | passive_enabled = true; |
| 416 | irs_enabled = false; | ||
| 384 | return SetPollingMode(); | 417 | return SetPollingMode(); |
| 385 | } | 418 | } |
| 386 | 419 | ||
| @@ -390,6 +423,22 @@ DriverResult JoyconDriver::SetActiveMode() { | |||
| 390 | hidbus_enabled = false; | 423 | hidbus_enabled = false; |
| 391 | nfc_enabled = false; | 424 | nfc_enabled = false; |
| 392 | passive_enabled = false; | 425 | passive_enabled = false; |
| 426 | irs_enabled = false; | ||
| 427 | return SetPollingMode(); | ||
| 428 | } | ||
| 429 | |||
| 430 | DriverResult JoyconDriver::SetIrMode() { | ||
| 431 | std::scoped_lock lock{mutex}; | ||
| 432 | |||
| 433 | if (!supported_features.irs) { | ||
| 434 | return DriverResult::NotSupported; | ||
| 435 | } | ||
| 436 | |||
| 437 | motion_enabled = false; | ||
| 438 | hidbus_enabled = false; | ||
| 439 | nfc_enabled = false; | ||
| 440 | passive_enabled = false; | ||
| 441 | irs_enabled = true; | ||
| 393 | return SetPollingMode(); | 442 | return SetPollingMode(); |
| 394 | } | 443 | } |
| 395 | 444 | ||
| @@ -404,6 +453,7 @@ DriverResult JoyconDriver::SetNfcMode() { | |||
| 404 | hidbus_enabled = false; | 453 | hidbus_enabled = false; |
| 405 | nfc_enabled = true; | 454 | nfc_enabled = true; |
| 406 | passive_enabled = false; | 455 | passive_enabled = false; |
| 456 | irs_enabled = false; | ||
| 407 | return SetPollingMode(); | 457 | return SetPollingMode(); |
| 408 | } | 458 | } |
| 409 | 459 | ||
| @@ -418,6 +468,7 @@ DriverResult JoyconDriver::SetRingConMode() { | |||
| 418 | hidbus_enabled = true; | 468 | hidbus_enabled = true; |
| 419 | nfc_enabled = false; | 469 | nfc_enabled = false; |
| 420 | passive_enabled = false; | 470 | passive_enabled = false; |
| 471 | irs_enabled = false; | ||
| 421 | 472 | ||
| 422 | const auto result = SetPollingMode(); | 473 | const auto result = SetPollingMode(); |
| 423 | 474 | ||