diff options
| author | 2022-12-22 01:07:46 -0600 | |
|---|---|---|
| committer | 2023-01-19 18:05:21 -0600 | |
| commit | 6d6b7bdbc327528d155f0422ef096846559844c0 (patch) | |
| tree | 6954aaa23abe6d725f8452afb1fd19a59e962800 /src/input_common/helpers/joycon_driver.cpp | |
| parent | input_common: Add dual joycon support (diff) | |
| download | yuzu-6d6b7bdbc327528d155f0422ef096846559844c0.tar.gz yuzu-6d6b7bdbc327528d155f0422ef096846559844c0.tar.xz yuzu-6d6b7bdbc327528d155f0422ef096846559844c0.zip | |
input_common: Implement joycon nfc
Diffstat (limited to 'src/input_common/helpers/joycon_driver.cpp')
| -rw-r--r-- | src/input_common/helpers/joycon_driver.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index c0a03fe2e..c3debffd1 100644 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp | |||
| @@ -5,6 +5,12 @@ | |||
| 5 | #include "common/swap.h" | 5 | #include "common/swap.h" |
| 6 | #include "common/thread.h" | 6 | #include "common/thread.h" |
| 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" | ||
| 9 | #include "input_common/helpers/joycon_protocol/generic_functions.h" | ||
| 10 | #include "input_common/helpers/joycon_protocol/nfc.h" | ||
| 11 | #include "input_common/helpers/joycon_protocol/poller.h" | ||
| 12 | #include "input_common/helpers/joycon_protocol/ringcon.h" | ||
| 13 | #include "input_common/helpers/joycon_protocol/rumble.h" | ||
| 8 | 14 | ||
| 9 | namespace InputCommon::Joycon { | 15 | namespace InputCommon::Joycon { |
| 10 | JoyconDriver::JoyconDriver(std::size_t port_) : port{port_} { | 16 | JoyconDriver::JoyconDriver(std::size_t port_) : port{port_} { |
| @@ -72,6 +78,7 @@ DriverResult JoyconDriver::InitializeDevice() { | |||
| 72 | // Initialize HW Protocols | 78 | // Initialize HW Protocols |
| 73 | calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); | 79 | calibration_protocol = std::make_unique<CalibrationProtocol>(hidapi_handle); |
| 74 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); | 80 | generic_protocol = std::make_unique<GenericProtocol>(hidapi_handle); |
| 81 | nfc_protocol = std::make_unique<NfcProtocol>(hidapi_handle); | ||
| 75 | ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle); | 82 | ring_protocol = std::make_unique<RingConProtocol>(hidapi_handle); |
| 76 | rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); | 83 | rumble_protocol = std::make_unique<RumbleProtocol>(hidapi_handle); |
| 77 | 84 | ||
| @@ -193,6 +200,25 @@ void JoyconDriver::OnNewData(std::span<u8> buffer) { | |||
| 193 | .min_value = ring_calibration.min_value, | 200 | .min_value = ring_calibration.min_value, |
| 194 | }; | 201 | }; |
| 195 | 202 | ||
| 203 | if (nfc_protocol->IsEnabled()) { | ||
| 204 | if (amiibo_detected) { | ||
| 205 | if (!nfc_protocol->HasAmiibo()) { | ||
| 206 | joycon_poller->updateAmiibo({}); | ||
| 207 | amiibo_detected = false; | ||
| 208 | return; | ||
| 209 | } | ||
| 210 | } | ||
| 211 | |||
| 212 | if (!amiibo_detected) { | ||
| 213 | std::vector<u8> data(0x21C); | ||
| 214 | const auto result = nfc_protocol->ScanAmiibo(data); | ||
| 215 | if (result == DriverResult::Success) { | ||
| 216 | joycon_poller->updateAmiibo(data); | ||
| 217 | amiibo_detected = true; | ||
| 218 | } | ||
| 219 | } | ||
| 220 | } | ||
| 221 | |||
| 196 | switch (report_mode) { | 222 | switch (report_mode) { |
| 197 | case InputReport::STANDARD_FULL_60HZ: | 223 | case InputReport::STANDARD_FULL_60HZ: |
| 198 | joycon_poller->ReadActiveMode(buffer, motion_status, ring_status); | 224 | joycon_poller->ReadActiveMode(buffer, motion_status, ring_status); |
| @@ -225,6 +251,24 @@ void JoyconDriver::SetPollingMode() { | |||
| 225 | generic_protocol->EnableImu(false); | 251 | generic_protocol->EnableImu(false); |
| 226 | } | 252 | } |
| 227 | 253 | ||
| 254 | if (nfc_protocol->IsEnabled()) { | ||
| 255 | amiibo_detected = false; | ||
| 256 | nfc_protocol->DisableNfc(); | ||
| 257 | } | ||
| 258 | |||
| 259 | if (nfc_enabled && supported_features.nfc) { | ||
| 260 | auto result = nfc_protocol->EnableNfc(); | ||
| 261 | if (result == DriverResult::Success) { | ||
| 262 | result = nfc_protocol->StartNFCPollingMode(); | ||
| 263 | } | ||
| 264 | if (result == DriverResult::Success) { | ||
| 265 | disable_input_thread = false; | ||
| 266 | return; | ||
| 267 | } | ||
| 268 | nfc_protocol->DisableNfc(); | ||
| 269 | LOG_ERROR(Input, "Error enabling NFC"); | ||
| 270 | } | ||
| 271 | |||
| 228 | if (ring_protocol->IsEnabled()) { | 272 | if (ring_protocol->IsEnabled()) { |
| 229 | ring_connected = false; | 273 | ring_connected = false; |
| 230 | ring_protocol->DisableRingCon(); | 274 | ring_protocol->DisableRingCon(); |