diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2022-12-23 03:47:51 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2023-01-20 01:05:22 +0100 |
commit | 1c08d532e059fab603facb43f758f37fe148c1fc (patch) | |
tree | 7451b6e38166cb3c422b22678ae0b989cd447de3 /src/core/hid | |
parent | input_common: Implement joycon nfc (diff) | |
download | yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.gz yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.bz2 yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.lz yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.xz yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.tar.zst yuzu-1c08d532e059fab603facb43f758f37fe148c1fc.zip |
Diffstat (limited to 'src/core/hid')
-rw-r--r-- | src/core/hid/emulated_controller.cpp | 55 | ||||
-rw-r--r-- | src/core/hid/emulated_controller.h | 12 |
2 files changed, 42 insertions, 25 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() { .button = GetNpadColor(player.button_color_right), }; + ring_params[0] = Common::ParamPackage(Settings::values.ringcon_analogs); + // Other or debug controller should always be a pro controller if (npad_id_type != NpadIdType::Other) { SetNpadStyleIndex(MapSettingsTypeToNPad(player.controller_type)); @@ -144,14 +146,15 @@ void EmulatedController::LoadDevices() { battery_params[RightIndex].Set("battery", true); camera_params = Common::ParamPackage{"engine:camera,camera:1"}; - nfc_params = right_joycon; - nfc_params.Set("nfc", true); - ring_params = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"}; + ring_params[1] = Common::ParamPackage{"engine:joycon,axis_x:100,axis_y:101"}; + nfc_params[0] = Common::ParamPackage{"engine:virtual_amiibo,nfc:1"}; + nfc_params[1] = right_joycon; + nfc_params[1].Set("nfc", true); output_params[LeftIndex] = left_joycon; output_params[RightIndex] = right_joycon; output_params[2] = camera_params; - output_params[3] = nfc_params; + output_params[3] = nfc_params[0]; output_params[LeftIndex].Set("output", true); output_params[RightIndex].Set("output", true); output_params[2].Set("output", true); @@ -169,8 +172,9 @@ void EmulatedController::LoadDevices() { Common::Input::CreateInputDevice); std::ranges::transform(color_params, color_devices.begin(), Common::Input::CreateInputDevice); camera_devices = Common::Input::CreateInputDevice(camera_params); - ring_analog_device = Common::Input::CreateInputDevice(ring_params); - nfc_devices = Common::Input::CreateInputDevice(nfc_params); + std::ranges::transform(ring_params, ring_analog_devices.begin(), + Common::Input::CreateInputDevice); + std::ranges::transform(nfc_params, nfc_devices.begin(), Common::Input::CreateInputDevice); std::ranges::transform(output_params, output_devices.begin(), Common::Input::CreateOutputDevice); @@ -366,21 +370,26 @@ void EmulatedController::ReloadInput() { camera_devices->ForceUpdate(); } - if (ring_analog_device) { - ring_analog_device->SetCallback({ + for (std::size_t index = 0; index < ring_analog_devices.size(); ++index) { + if (!ring_analog_devices[index]) { + continue; + } + ring_analog_devices[index]->SetCallback({ .on_change = [this](const Common::Input::CallbackStatus& callback) { SetRingAnalog(callback); }, }); + ring_analog_devices[index]->ForceUpdate(); } - if (nfc_devices) { - if (npad_id_type == NpadIdType::Handheld || npad_id_type == NpadIdType::Player1) { - nfc_devices->SetCallback({ - .on_change = - [this](const Common::Input::CallbackStatus& callback) { SetNfc(callback); }, - }); - nfc_devices->ForceUpdate(); + for (std::size_t index = 0; index < nfc_devices.size(); ++index) { + if (!nfc_devices[index]) { + continue; } + nfc_devices[index]->SetCallback({ + .on_change = + [this](const Common::Input::CallbackStatus& callback) { SetNfc(callback); }, + }); + nfc_devices[index]->ForceUpdate(); } // Register TAS devices. No need to force update @@ -469,8 +478,12 @@ void EmulatedController::UnloadInput() { stick.reset(); } camera_devices.reset(); - ring_analog_device.reset(); - nfc_devices.reset(); + for (auto& ring : ring_analog_devices) { + ring.reset(); + } + for (auto& nfc : nfc_devices) { + nfc.reset(); + } } void EmulatedController::EnableConfiguration() { @@ -540,7 +553,9 @@ void EmulatedController::SaveCurrentConfig() { for (std::size_t index = 0; index < player.motions.size(); ++index) { player.motions[index] = motion_params[index].Serialize(); } - Settings::values.ringcon_analogs = ring_params.Serialize(); + if (npad_id_type == NpadIdType::Player1) { + Settings::values.ringcon_analogs = ring_params[0].Serialize(); + } } void EmulatedController::RestoreConfig() { @@ -1215,11 +1230,11 @@ bool EmulatedController::SetCameraFormat( } Common::ParamPackage EmulatedController::GetRingParam() const { - return ring_params; + return ring_params[0]; } void EmulatedController::SetRingParam(Common::ParamPackage param) { - ring_params = std::move(param); + ring_params[0] = std::move(param); ReloadInput(); } 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 = using BatteryDevices = std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; using CameraDevices = std::unique_ptr<Common::Input::InputDevice>; -using RingAnalogDevice = std::unique_ptr<Common::Input::InputDevice>; -using NfcDevices = std::unique_ptr<Common::Input::InputDevice>; +using RingAnalogDevices = + std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; +using NfcDevices = + std::array<std::unique_ptr<Common::Input::InputDevice>, max_emulated_controllers>; using OutputDevices = std::array<std::unique_ptr<Common::Input::OutputDevice>, output_devices_size>; using ButtonParams = std::array<Common::ParamPackage, Settings::NativeButton::NumButtons>; @@ -51,8 +53,8 @@ using TriggerParams = std::array<Common::ParamPackage, Settings::NativeTrigger:: using ColorParams = std::array<Common::ParamPackage, max_emulated_controllers>; using BatteryParams = std::array<Common::ParamPackage, max_emulated_controllers>; using CameraParams = Common::ParamPackage; -using RingAnalogParams = Common::ParamPackage; -using NfcParams = Common::ParamPackage; +using RingAnalogParams = std::array<Common::ParamPackage, max_emulated_controllers>; +using NfcParams = std::array<Common::ParamPackage, max_emulated_controllers>; using OutputParams = std::array<Common::ParamPackage, output_devices_size>; using ButtonValues = std::array<Common::Input::ButtonStatus, Settings::NativeButton::NumButtons>; @@ -538,7 +540,7 @@ private: BatteryDevices battery_devices; ColorDevices color_devices; CameraDevices camera_devices; - RingAnalogDevice ring_analog_device; + RingAnalogDevices ring_analog_devices; NfcDevices nfc_devices; OutputDevices output_devices; |