summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar german772023-07-02 19:21:16 -0600
committerGravatar german772023-07-02 19:21:16 -0600
commit9cd698e8ad584a199048f072ed65986ee10ba31a (patch)
tree2959ccd4fd535565d4b7aa28d289ca3ecce461fa /src
parentMerge pull request #10998 from Morph1984/qt-stop-messing-with-me (diff)
downloadyuzu-9cd698e8ad584a199048f072ed65986ee10ba31a.tar.gz
yuzu-9cd698e8ad584a199048f072ed65986ee10ba31a.tar.xz
yuzu-9cd698e8ad584a199048f072ed65986ee10ba31a.zip
service: nfc: Ensure controller is in the correct mode
Diffstat (limited to 'src')
-rw-r--r--src/core/hid/emulated_controller.cpp12
-rw-r--r--src/core/hid/emulated_controller.h8
-rw-r--r--src/core/hle/service/nfc/common/device.cpp32
3 files changed, 41 insertions, 11 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 1ebc32c1e..94bd656fe 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -1243,10 +1243,12 @@ Common::Input::DriverResult EmulatedController::SetPollingMode(
1243 auto& nfc_output_device = output_devices[3]; 1243 auto& nfc_output_device = output_devices[3];
1244 1244
1245 if (device_index == EmulatedDeviceIndex::LeftIndex) { 1245 if (device_index == EmulatedDeviceIndex::LeftIndex) {
1246 controller.left_polling_mode = polling_mode;
1246 return left_output_device->SetPollingMode(polling_mode); 1247 return left_output_device->SetPollingMode(polling_mode);
1247 } 1248 }
1248 1249
1249 if (device_index == EmulatedDeviceIndex::RightIndex) { 1250 if (device_index == EmulatedDeviceIndex::RightIndex) {
1251 controller.right_polling_mode = polling_mode;
1250 const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode); 1252 const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode);
1251 const auto mapped_nfc_result = right_output_device->SetPollingMode(polling_mode); 1253 const auto mapped_nfc_result = right_output_device->SetPollingMode(polling_mode);
1252 1254
@@ -1261,12 +1263,22 @@ Common::Input::DriverResult EmulatedController::SetPollingMode(
1261 return mapped_nfc_result; 1263 return mapped_nfc_result;
1262 } 1264 }
1263 1265
1266 controller.left_polling_mode = polling_mode;
1267 controller.right_polling_mode = polling_mode;
1264 left_output_device->SetPollingMode(polling_mode); 1268 left_output_device->SetPollingMode(polling_mode);
1265 right_output_device->SetPollingMode(polling_mode); 1269 right_output_device->SetPollingMode(polling_mode);
1266 nfc_output_device->SetPollingMode(polling_mode); 1270 nfc_output_device->SetPollingMode(polling_mode);
1267 return Common::Input::DriverResult::Success; 1271 return Common::Input::DriverResult::Success;
1268} 1272}
1269 1273
1274Common::Input::PollingMode EmulatedController::GetPollingMode(
1275 EmulatedDeviceIndex device_index) const {
1276 if (device_index == EmulatedDeviceIndex::LeftIndex) {
1277 return controller.left_polling_mode;
1278 }
1279 return controller.right_polling_mode;
1280}
1281
1270bool EmulatedController::SetCameraFormat( 1282bool EmulatedController::SetCameraFormat(
1271 Core::IrSensor::ImageTransferProcessorFormat camera_format) { 1283 Core::IrSensor::ImageTransferProcessorFormat camera_format) {
1272 LOG_INFO(Service_HID, "Set camera format {}", camera_format); 1284 LOG_INFO(Service_HID, "Set camera format {}", camera_format);
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index d511e5fac..88d77db8d 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -143,6 +143,8 @@ struct ControllerStatus {
143 CameraState camera_state{}; 143 CameraState camera_state{};
144 RingSensorForce ring_analog_state{}; 144 RingSensorForce ring_analog_state{};
145 NfcState nfc_state{}; 145 NfcState nfc_state{};
146 Common::Input::PollingMode left_polling_mode{};
147 Common::Input::PollingMode right_polling_mode{};
146}; 148};
147 149
148enum class ControllerTriggerType { 150enum class ControllerTriggerType {
@@ -370,6 +372,12 @@ public:
370 */ 372 */
371 Common::Input::DriverResult SetPollingMode(EmulatedDeviceIndex device_index, 373 Common::Input::DriverResult SetPollingMode(EmulatedDeviceIndex device_index,
372 Common::Input::PollingMode polling_mode); 374 Common::Input::PollingMode polling_mode);
375 /**
376 * Get the current polling mode from a controller
377 * @param device_index index of the controller to set the polling mode
378 * @return current polling mode
379 */
380 Common::Input::PollingMode GetPollingMode(EmulatedDeviceIndex device_index) const;
373 381
374 /** 382 /**
375 * Sets the desired camera format to be polled from a controller 383 * Sets the desired camera format to be polled from a controller
diff --git a/src/core/hle/service/nfc/common/device.cpp b/src/core/hle/service/nfc/common/device.cpp
index 5bf289818..2d633b03f 100644
--- a/src/core/hle/service/nfc/common/device.cpp
+++ b/src/core/hle/service/nfc/common/device.cpp
@@ -66,10 +66,6 @@ NfcDevice::~NfcDevice() {
66}; 66};
67 67
68void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) { 68void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
69 if (!is_initalized) {
70 return;
71 }
72
73 if (type == Core::HID::ControllerTriggerType::Connected) { 69 if (type == Core::HID::ControllerTriggerType::Connected) {
74 Initialize(); 70 Initialize();
75 availability_change_event->Signal(); 71 availability_change_event->Signal();
@@ -77,12 +73,12 @@ void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
77 } 73 }
78 74
79 if (type == Core::HID::ControllerTriggerType::Disconnected) { 75 if (type == Core::HID::ControllerTriggerType::Disconnected) {
80 device_state = DeviceState::Unavailable; 76 Finalize();
81 availability_change_event->Signal(); 77 availability_change_event->Signal();
82 return; 78 return;
83 } 79 }
84 80
85 if (type != Core::HID::ControllerTriggerType::Nfc) { 81 if (!is_initalized) {
86 return; 82 return;
87 } 83 }
88 84
@@ -90,6 +86,17 @@ void NfcDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
90 return; 86 return;
91 } 87 }
92 88
89 // Ensure nfc mode is always active
90 if (npad_device->GetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex) ==
91 Common::Input::PollingMode::Active) {
92 npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
93 Common::Input::PollingMode::NFC);
94 }
95
96 if (type != Core::HID::ControllerTriggerType::Nfc) {
97 return;
98 }
99
93 const auto nfc_status = npad_device->GetNfc(); 100 const auto nfc_status = npad_device->GetNfc();
94 switch (nfc_status.state) { 101 switch (nfc_status.state) {
95 case Common::Input::NfcState::NewAmiibo: 102 case Common::Input::NfcState::NewAmiibo:
@@ -207,11 +214,14 @@ void NfcDevice::Initialize() {
207} 214}
208 215
209void NfcDevice::Finalize() { 216void NfcDevice::Finalize() {
210 if (device_state == DeviceState::TagMounted) { 217 if (npad_device->IsConnected()) {
211 Unmount(); 218 if (device_state == DeviceState::TagMounted) {
212 } 219 Unmount();
213 if (device_state == DeviceState::SearchingForTag || device_state == DeviceState::TagRemoved) { 220 }
214 StopDetection(); 221 if (device_state == DeviceState::SearchingForTag ||
222 device_state == DeviceState::TagRemoved) {
223 StopDetection();
224 }
215 } 225 }
216 226
217 if (device_state != DeviceState::Unavailable) { 227 if (device_state != DeviceState::Unavailable) {