summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Narr the Reg2022-12-22 20:47:51 -0600
committerGravatar Narr the Reg2023-01-19 18:05:22 -0600
commit1c08d532e059fab603facb43f758f37fe148c1fc (patch)
tree7451b6e38166cb3c422b22678ae0b989cd447de3
parentinput_common: Implement joycon nfc (diff)
downloadyuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.gz
yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.xz
yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.zip
core: hid: Fix input regressions
-rw-r--r--src/core/hid/emulated_controller.cpp55
-rw-r--r--src/core/hid/emulated_controller.h12
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp1
-rw-r--r--src/core/hle/service/hid/hidbus.cpp24
-rw-r--r--src/input_common/helpers/joycon_driver.cpp2
-rw-r--r--src/input_common/helpers/joycon_protocol/ringcon.cpp3
6 files changed, 56 insertions, 41 deletions
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp
index 1e4ec4add..1ed57f949 100644
--- a/src/core/hid/emulated_controller.cpp
+++ b/src/core/hid/emulated_controller.cpp
@@ -107,6 +107,8 @@ void EmulatedController::ReloadFromSettings() {
107 .button = GetNpadColor(player.button_color_right), 107 .button = GetNpadColor(player.button_color_right),
108 }; 108 };
109 109
110 ring_params[0] = Common::ParamPackage(Settings::values.ringcon_analogs);
111
110 // Other or debug controller should always be a pro controller 112 // Other or debug controller should always be a pro controller
111 if (npad_id_type != NpadIdType::Other) { 113 if (npad_id_type != NpadIdType::Other) {
112 SetNpadStyleIndex(MapSettingsTypeToNPad(player.controller_type)); 114 SetNpadStyleIndex(MapSettingsTypeToNPad(player.controller_type));
@@ -144,14 +146,15 @@ void EmulatedController::LoadDevices() {
144 battery_params[RightIndex].Set("battery", true); 146 battery_params[RightIndex].Set("battery", true);
145 147
146 camera_params = Common::ParamPackage{"engine:camera,camera:1"}; 148 camera_params = Common::ParamPackage{"engine:camera,camera:1"};
147 nfc_params = right_joycon; 149 ring_params[1] = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"};
148 nfc_params.Set("nfc", true); 150 nfc_params[0] = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"};
149 ring_params = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"}; 151 nfc_params[1] = right_joycon;
152 nfc_params[1].Set("nfc", true);
150 153
151 output_params[LeftIndex] = left_joycon; 154 output_params[LeftIndex] = left_joycon;
152 output_params[RightIndex] = right_joycon; 155 output_params[RightIndex] = right_joycon;
153 output_params[2] = camera_params; 156 output_params[2] = camera_params;
154 output_params[3] = nfc_params; 157 output_params[3] = nfc_params[0];
155 output_params[LeftIndex].Set("output", true); 158 output_params[LeftIndex].Set("output", true);
156 output_params[RightIndex].Set("output", true); 159 output_params[RightIndex].Set("output", true);
157 output_params[2].Set("output", true); 160 output_params[2].Set("output", true);
@@ -169,8 +172,9 @@ void EmulatedController::LoadDevices() {
169 Common::Input::CreateInputDevice); 172 Common::Input::CreateInputDevice);
170 std::ranges::transform(color_params, color_devices.begin(), Common::Input::CreateInputDevice); 173 std::ranges::transform(color_params, color_devices.begin(), Common::Input::CreateInputDevice);
171 camera_devices = Common::Input::CreateInputDevice(camera_params); 174 camera_devices = Common::Input::CreateInputDevice(camera_params);
172 ring_analog_device = Common::Input::CreateInputDevice(ring_params); 175 std::ranges::transform(ring_params, ring_analog_devices.begin(),
173 nfc_devices = Common::Input::CreateInputDevice(nfc_params); 176 Common::Input::CreateInputDevice);
177 std::ranges::transform(nfc_params, nfc_devices.begin(), Common::Input::CreateInputDevice);
174 std::ranges::transform(output_params, output_devices.begin(), 178 std::ranges::transform(output_params, output_devices.begin(),
175 Common::Input::CreateOutputDevice); 179 Common::Input::CreateOutputDevice);
176 180
@@ -366,21 +370,26 @@ void EmulatedController::ReloadInput() {
366 camera_devices->ForceUpdate(); 370 camera_devices->ForceUpdate();
367 } 371 }
368 372
369 if (ring_analog_device) { 373 for (std::size_t index = 0; index < ring_analog_devices.size(); ++index) {
370 ring_analog_device->SetCallback({ 374 if (!ring_analog_devices[index]) {
375 continue;
376 }
377 ring_analog_devices[index]->SetCallback({
371 .on_change = 378 .on_change =
372 [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); }, 379 [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); },
373 }); 380 });
381 ring_analog_devices[index]->ForceUpdate();
374 } 382 }
375 383
376 if (nfc_devices) { 384 for (std::size_t index = 0; index < nfc_devices.size(); ++index) {
377 if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) { 385 if (!nfc_devices[index]) {
378 nfc_devices->SetCallback({ 386 continue;
379 .on_change =
380 [this](const Common::Input::CallbackStatus& callback) { SetNfc(callback); },
381 });
382 nfc_devices->ForceUpdate();
383 } 387 }
388 nfc_devices[index]->SetCallback({
389 .on_change =
390 [this](const Common::Input::CallbackStatus& callback) { SetNfc(callback); },
391 });
392 nfc_devices[index]->ForceUpdate();
384 } 393 }
385 394
386 // Register TAS devices. No need to force update 395 // Register TAS devices. No need to force update
@@ -469,8 +478,12 @@ void EmulatedController::UnloadInput() {
469 stick.reset(); 478 stick.reset();
470 } 479 }
471 camera_devices.reset(); 480 camera_devices.reset();
472 ring_analog_device.reset(); 481 for (auto& ring : ring_analog_devices) {
473 nfc_devices.reset(); 482 ring.reset();
483 }
484 for (auto& nfc : nfc_devices) {
485 nfc.reset();
486 }
474} 487}
475 488
476void EmulatedController::EnableConfiguration() { 489void EmulatedController::EnableConfiguration() {
@@ -540,7 +553,9 @@ void EmulatedController::SaveCurrentConfig() {
540 for (std::size_t index = 0; index < player.motions.size(); ++index) { 553 for (std::size_t index = 0; index < player.motions.size(); ++index) {
541 player.motions[index] = motion_params[index].Serialize(); 554 player.motions[index] = motion_params[index].Serialize();
542 } 555 }
543 Settings::values.ringcon_analogs = ring_params.Serialize(); 556 if (npad_id_type == NpadIdType::Player1) {
557 Settings::values.ringcon_analogs = ring_params[0].Serialize();
558 }
544} 559}
545 560
546void EmulatedController::RestoreConfig() { 561void EmulatedController::RestoreConfig() {
@@ -1215,11 +1230,11 @@ bool EmulatedController::SetCameraFormat(
1215} 1230}
1216 1231
1217Common::ParamPackage EmulatedController::GetRingParam() const { 1232Common::ParamPackage EmulatedController::GetRingParam() const {
1218 return ring_params; 1233 return ring_params[0];
1219} 1234}
1220 1235
1221void EmulatedController::SetRingParam(Common::ParamPackage param) { 1236void EmulatedController::SetRingParam(Common::ParamPackage param) {
1222 ring_params = std::move(param); 1237 ring_params[0] = std::move(param);
1223 ReloadInput(); 1238 ReloadInput();
1224} 1239}
1225 1240
diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h
index d044cc36b..c517aa5d7 100644
--- a/src/core/hid/emulated_controller.h
+++ b/src/core/hid/emulated_controller.h
@@ -40,8 +40,10 @@ using ColorDevices =
40using BatteryDevices = 40using BatteryDevices =
41 std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; 41 std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>;
42using CameraDevices = std::unique_ptr<Common::Input::InputDevice>; 42using CameraDevices = std::unique_ptr<Common::Input::InputDevice>;
43using RingAnalogDevice = std::unique_ptr<Common::Input::InputDevice>; 43using RingAnalogDevices =
44using NfcDevices = std::unique_ptr<Common::Input::InputDevice>; 44 std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>;
45using NfcDevices =
46 std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>;
45using OutputDevices = std::array<std::unique_ptr<Common::Input::OutputDevice>, output_devices_size>; 47using OutputDevices = std::array<std::unique_ptr<Common::Input::OutputDevice>, output_devices_size>;
46 48
47using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; 49using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>;
@@ -51,8 +53,8 @@ using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger::
51using ColorParams = std::array<Common::ParamPackage, max_emulated_controllers>; 53using ColorParams = std::array<Common::ParamPackage, max_emulated_controllers>;
52using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; 54using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>;
53using CameraParams = Common::ParamPackage; 55using CameraParams = Common::ParamPackage;
54using RingAnalogParams = Common::ParamPackage; 56using RingAnalogParams = std::array<Common::ParamPackage, max_emulated_controllers>;
55using NfcParams = Common::ParamPackage; 57using NfcParams = std::array<Common::ParamPackage, max_emulated_controllers>;
56using OutputParams = std::array<Common::ParamPackage, output_devices_size>; 58using OutputParams = std::array<Common::ParamPackage, output_devices_size>;
57 59
58using ButtonValues = std::array<Common::Input::ButtonStatus, Settings::NativeButton::NumButtons>; 60using ButtonValues = std::array<Common::Input::ButtonStatus, Settings::NativeButton::NumButtons>;
@@ -538,7 +540,7 @@ private:
538 BatteryDevices battery_devices; 540 BatteryDevices battery_devices;
539 ColorDevices color_devices; 541 ColorDevices color_devices;
540 CameraDevices camera_devices; 542 CameraDevices camera_devices;
541 RingAnalogDevice ring_analog_device; 543 RingAnalogDevices ring_analog_devices;
542 NfcDevices nfc_devices; 544 NfcDevices nfc_devices;
543 OutputDevices output_devices; 545 OutputDevices output_devices;
544 546
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index 83b368091..fe5bf94d2 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -337,6 +337,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
337 controller.is_connected = true; 337 controller.is_connected = true;
338 controller.device->Connect(); 338 controller.device->Connect();
339 controller.device->SetLedPattern(); 339 controller.device->SetLedPattern();
340 controller.device->SetPollingMode(Common::Input::PollingMode::Active);
340 SignalStyleSetChangedEvent(npad_id); 341 SignalStyleSetChangedEvent(npad_id);
341 WriteEmptyEntry(controller.shared_memory); 342 WriteEmptyEntry(controller.shared_memory);
342} 343}
diff --git a/src/core/hle/service/hid/hidbus.cpp b/src/core/hle/service/hid/hidbus.cpp
index e5e50845f..17252a84a 100644
--- a/src/core/hle/service/hid/hidbus.cpp
+++ b/src/core/hle/service/hid/hidbus.cpp
@@ -297,13 +297,13 @@ void HidBus::EnableExternalDevice(Kernel::HLERequestContext& ctx) {
297 297
298 const auto parameters{rp.PopRaw<Parameters>()}; 298 const auto parameters{rp.PopRaw<Parameters>()};
299 299
300 LOG_INFO(Service_HID, 300 LOG_DEBUG(Service_HID,
301 "called, enable={}, abstracted_pad_id={}, bus_type={}, internal_index={}, " 301 "called, enable={}, abstracted_pad_id={}, bus_type={}, internal_index={}, "
302 "player_number={}, is_valid={}, inval={}, applet_resource_user_id{}", 302 "player_number={}, is_valid={}, inval={}, applet_resource_user_id{}",
303 parameters.enable, parameters.bus_handle.abstracted_pad_id, 303 parameters.enable, parameters.bus_handle.abstracted_pad_id,
304 parameters.bus_handle.bus_type, parameters.bus_handle.internal_index, 304 parameters.bus_handle.bus_type, parameters.bus_handle.internal_index,
305 parameters.bus_handle.player_number, parameters.bus_handle.is_valid, parameters.inval, 305 parameters.bus_handle.player_number, parameters.bus_handle.is_valid, parameters.inval,
306 parameters.applet_resource_user_id); 306 parameters.applet_resource_user_id);
307 307
308 const auto device_index = GetDeviceIndexFromHandle(parameters.bus_handle); 308 const auto device_index = GetDeviceIndexFromHandle(parameters.bus_handle);
309 309
@@ -326,11 +326,11 @@ void HidBus::GetExternalDeviceId(Kernel::HLERequestContext& ctx) {
326 IPC::RequestParser rp{ctx}; 326 IPC::RequestParser rp{ctx};
327 const auto bus_handle_{rp.PopRaw<BusHandle>()}; 327 const auto bus_handle_{rp.PopRaw<BusHandle>()};
328 328
329 LOG_INFO(Service_HID, 329 LOG_DEBUG(Service_HID,
330 "called, abstracted_pad_id={}, bus_type={}, internal_index={}, player_number={}, " 330 "called, abstracted_pad_id={}, bus_type={}, internal_index={}, player_number={}, "
331 "is_valid={}", 331 "is_valid={}",
332 bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index, 332 bus_handle_.abstracted_pad_id, bus_handle_.bus_type, bus_handle_.internal_index,
333 bus_handle_.player_number, bus_handle_.is_valid); 333 bus_handle_.player_number, bus_handle_.is_valid);
334 334
335 const auto device_index = GetDeviceIndexFromHandle(bus_handle_); 335 const auto device_index = GetDeviceIndexFromHandle(bus_handle_);
336 336
diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp
index c3debffd1..db9ff4875 100644
--- a/src/input_common/helpers/joycon_driver.cpp
+++ b/src/input_common/helpers/joycon_driver.cpp
@@ -396,7 +396,7 @@ DriverResult JoyconDriver::SetActiveMode() {
396 396
397DriverResult JoyconDriver::SetNfcMode() { 397DriverResult JoyconDriver::SetNfcMode() {
398 std::scoped_lock lock{mutex}; 398 std::scoped_lock lock{mutex};
399 motion_enabled = false; 399 motion_enabled = true;
400 hidbus_enabled = false; 400 hidbus_enabled = false;
401 nfc_enabled = true; 401 nfc_enabled = true;
402 passive_enabled = false; 402 passive_enabled = false;
diff --git a/src/input_common/helpers/joycon_protocol/ringcon.cpp b/src/input_common/helpers/joycon_protocol/ringcon.cpp
index 2d137b85d..47769f344 100644
--- a/src/input_common/helpers/joycon_protocol/ringcon.cpp
+++ b/src/input_common/helpers/joycon_protocol/ringcon.cpp
@@ -56,9 +56,6 @@ DriverResult RingConProtocol::StartRingconPolling() {
56 SetBlocking(); 56 SetBlocking();
57 57
58 if (result == DriverResult::Success) { 58 if (result == DriverResult::Success) {
59 result = WaitSetMCUMode(ReportMode::STANDARD_FULL_60HZ, MCUMode::Standby);
60 }
61 if (result == DriverResult::Success) {
62 result = IsRingConnected(is_connected); 59 result = IsRingConnected(is_connected);
63 } 60 }
64 if (result == DriverResult::Success && is_connected) { 61 if (result == DriverResult::Success && is_connected) {