From 3aab9514447ee9470527fcf2b6c430eb93d3f5fa Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sun, 15 Jan 2023 21:36:14 +0100 Subject: [PATCH] early-access version 3309 --- README.md | 2 +- src/core/hid/emulated_controller.cpp | 30 +++-- src/core/hid/emulated_controller.h | 4 +- src/core/hle/service/hid/controllers/npad.cpp | 14 ++- src/core/hle/service/hid/hidbus/ringcon.cpp | 6 +- src/core/hle/service/hid/irs.cpp | 27 ++-- src/core/hle/service/nfc/nfc_device.cpp | 6 +- src/core/hle/service/nfp/nfp_device.cpp | 6 +- src/input_common/drivers/joycon.cpp | 116 ++++++++---------- src/input_common/drivers/joycon.h | 6 +- src/input_common/drivers/sdl_driver.cpp | 2 +- src/input_common/helpers/joycon_driver.cpp | 4 +- .../joycon_protocol/common_protocol.cpp | 2 +- .../helpers/joycon_protocol/common_protocol.h | 15 ++- .../helpers/joycon_protocol/irs.cpp | 6 +- .../helpers/joycon_protocol/nfc.cpp | 65 +++++----- .../helpers/joycon_protocol/poller.cpp | 18 +-- .../helpers/joycon_protocol/rumble.cpp | 12 +- .../configuration/configure_input_advanced.ui | 2 +- src/yuzu/configuration/configure_ringcon.cpp | 6 +- 20 files changed, 201 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index 34e740fc0..abe4d0a56 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3308. +This is the source code for early-access 3309. ## Legal Notice diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index cb5390e35..0122a815c 100755 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -1208,19 +1208,31 @@ bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { } Common::Input::DriverResult EmulatedController::SetPollingMode( - Common::Input::PollingMode polling_mode) { - LOG_INFO(Service_HID, "Set polling mode {}", polling_mode); - auto& output_device = output_devices[static_cast(DeviceIndex::Right)]; + EmulatedDeviceIndex device_index, Common::Input::PollingMode polling_mode) { + LOG_INFO(Service_HID, "Set polling mode {}, device_index={}", polling_mode, device_index); + + auto& left_output_device = output_devices[static_cast(DeviceIndex::Left)]; + auto& right_output_device = output_devices[static_cast(DeviceIndex::Right)]; auto& nfc_output_device = output_devices[3]; - const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode); - const auto mapped_nfc_result = output_device->SetPollingMode(polling_mode); - - if (virtual_nfc_result == Common::Input::DriverResult::Success) { - return virtual_nfc_result; + if (device_index == EmulatedDeviceIndex::LeftIndex) { + return left_output_device->SetPollingMode(polling_mode); } - return mapped_nfc_result; + if (device_index == EmulatedDeviceIndex::RightIndex) { + const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode); + const auto mapped_nfc_result = right_output_device->SetPollingMode(polling_mode); + + if (virtual_nfc_result == Common::Input::DriverResult::Success) { + return virtual_nfc_result; + } + return mapped_nfc_result; + } + + left_output_device->SetPollingMode(polling_mode); + right_output_device->SetPollingMode(polling_mode); + nfc_output_device->SetPollingMode(polling_mode); + return Common::Input::DriverResult::Success; } bool EmulatedController::SetCameraFormat( diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index 65f2d40a8..dd97bb817 100755 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -363,10 +363,12 @@ public: /** * Sets the desired data to be polled from a controller + * @param device_index index of the controller to set the polling mode * @param polling_mode type of input desired buttons, gyro, nfc, ir, etc. * @return driver result from this command */ - Common::Input::DriverResult SetPollingMode(Common::Input::PollingMode polling_mode); + Common::Input::DriverResult SetPollingMode(EmulatedDeviceIndex device_index, + Common::Input::PollingMode polling_mode); /** * Sets the desired camera format to be polled from a controller diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 1ef3d757a..986370455 100755 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -337,7 +337,19 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { controller.is_connected = true; controller.device->Connect(); controller.device->SetLedPattern(); - controller.device->SetPollingMode(Common::Input::PollingMode::Active); + if (controller_type == Core::HID::NpadStyleIndex::JoyconDual) { + if (controller.is_dual_left_connected) { + controller.device->SetPollingMode(Core::HID::EmulatedDeviceIndex::LeftIndex, + Common::Input::PollingMode::Active); + } + if (controller.is_dual_right_connected) { + controller.device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); + } + } else { + controller.device->SetPollingMode(Core::HID::EmulatedDeviceIndex::AllDevices, + Common::Input::PollingMode::Active); + } SignalStyleSetChangedEvent(npad_id); WriteEmptyEntry(controller.shared_memory); } diff --git a/src/core/hle/service/hid/hidbus/ringcon.cpp b/src/core/hle/service/hid/hidbus/ringcon.cpp index 7422fb40c..8181531d7 100755 --- a/src/core/hle/service/hid/hidbus/ringcon.cpp +++ b/src/core/hle/service/hid/hidbus/ringcon.cpp @@ -18,12 +18,14 @@ RingController::RingController(Core::HID::HIDCore& hid_core_, RingController::~RingController() = default; void RingController::OnInit() { - input->SetPollingMode(Common::Input::PollingMode::Ring); + input->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Ring); return; } void RingController::OnRelease() { - input->SetPollingMode(Common::Input::PollingMode::Active); + input->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); return; }; diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp index 01e3f63fc..04021d5c3 100755 --- a/src/core/hle/service/hid/irs.cpp +++ b/src/core/hle/service/hid/irs.cpp @@ -108,7 +108,8 @@ void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) { auto result = IsIrCameraHandleValid(parameters.camera_handle); if (result.IsSuccess()) { // TODO: Stop Image processor - npad_device->SetPollingMode(Common::Input::PollingMode::Active); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); result = ResultSuccess; } @@ -140,7 +141,8 @@ void IRS::RunMomentProcessor(Kernel::HLERequestContext& ctx) { MakeProcessor(parameters.camera_handle, device); auto& image_transfer_processor = GetProcessor(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -172,7 +174,8 @@ void IRS::RunClusteringProcessor(Kernel::HLERequestContext& ctx) { auto& image_transfer_processor = GetProcessor(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -222,7 +225,8 @@ void IRS::RunImageTransferProcessor(Kernel::HLERequestContext& ctx) { GetProcessor(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); image_transfer_processor.SetTransferMemoryPointer(transfer_memory); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -298,7 +302,8 @@ void IRS::RunTeraPluginProcessor(Kernel::HLERequestContext& ctx) { auto& image_transfer_processor = GetProcessor(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -348,7 +353,8 @@ void IRS::RunPointingProcessor(Kernel::HLERequestContext& ctx) { MakeProcessor(camera_handle, device); auto& image_transfer_processor = GetProcessor(camera_handle); image_transfer_processor.SetConfig(processor_config); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -459,7 +465,8 @@ void IRS::RunImageTransferExProcessor(Kernel::HLERequestContext& ctx) { GetProcessor(parameters.camera_handle); image_transfer_processor.SetConfig(parameters.processor_config); image_transfer_processor.SetTransferMemoryPointer(transfer_memory); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -486,7 +493,8 @@ void IRS::RunIrLedProcessor(Kernel::HLERequestContext& ctx) { MakeProcessor(camera_handle, device); auto& image_transfer_processor = GetProcessor(camera_handle); image_transfer_processor.SetConfig(processor_config); - npad_device->SetPollingMode(Common::Input::PollingMode::IR); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); } IPC::ResponseBuilder rb{ctx, 2}; @@ -512,7 +520,8 @@ void IRS::StopImageProcessorAsync(Kernel::HLERequestContext& ctx) { auto result = IsIrCameraHandleValid(parameters.camera_handle); if (result.IsSuccess()) { // TODO: Stop image processor async - npad_device->SetPollingMode(Common::Input::PollingMode::Active); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); result = ResultSuccess; } diff --git a/src/core/hle/service/nfc/nfc_device.cpp b/src/core/hle/service/nfc/nfc_device.cpp index c9815edbc..9a3234e8c 100755 --- a/src/core/hle/service/nfc/nfc_device.cpp +++ b/src/core/hle/service/nfc/nfc_device.cpp @@ -130,7 +130,8 @@ Result NfcDevice::StartDetection(NFP::TagProtocol allowed_protocol) { return WrongDeviceState; } - if (npad_device->SetPollingMode(Common::Input::PollingMode::NFC) != + if (npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::NFC) != Common::Input::DriverResult::Success) { LOG_ERROR(Service_NFC, "Nfc not supported"); return NfcDisabled; @@ -142,7 +143,8 @@ Result NfcDevice::StartDetection(NFP::TagProtocol allowed_protocol) { } Result NfcDevice::StopDetection() { - npad_device->SetPollingMode(Common::Input::PollingMode::Active); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); if (device_state == NFP::DeviceState::Initialized) { return ResultSuccess; diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index 8aff01dff..dbfaaf605 100755 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp @@ -152,7 +152,8 @@ Result NfpDevice::StartDetection(TagProtocol allowed_protocol) { return WrongDeviceState; } - if (npad_device->SetPollingMode(Common::Input::PollingMode::NFC) != + if (npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::NFC) != Common::Input::DriverResult::Success) { LOG_ERROR(Service_NFP, "Nfc not supported"); return NfcDisabled; @@ -164,7 +165,8 @@ Result NfpDevice::StartDetection(TagProtocol allowed_protocol) { } Result NfpDevice::StopDetection() { - npad_device->SetPollingMode(Common::Input::PollingMode::Active); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); if (device_state == DeviceState::Initialized) { return ResultSuccess; diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp index fff886ca8..70bdf89e8 100755 --- a/src/input_common/drivers/joycon.cpp +++ b/src/input_common/drivers/joycon.cpp @@ -60,15 +60,12 @@ void Joycons::Setup() { device = std::make_shared(port++); } - if (!scan_thread_running) { - scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); }); - } + scan_thread = std::jthread([this](std::stop_token stop_token) { ScanThread(stop_token); }); } void Joycons::ScanThread(std::stop_token stop_token) { constexpr u16 nintendo_vendor_id = 0x057e; - Common::SetCurrentThreadName("yuzu:input:JoyconScanThread"); - scan_thread_running = true; + Common::SetCurrentThreadName("JoyconScanThread"); while (!stop_token.stop_requested()) { SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0); SDL_hid_device_info* cur_dev = devs; @@ -82,9 +79,9 @@ void Joycons::ScanThread(std::stop_token stop_token) { cur_dev = cur_dev->next; } + SDL_hid_free_enumeration(devs); std::this_thread::sleep_for(std::chrono::seconds(5)); } - scan_thread_running = false; } bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const { @@ -409,13 +406,25 @@ std::shared_ptr Joycons::GetHandle(PadIdentifier identifie } PadIdentifier Joycons::GetIdentifier(std::size_t port, Joycon::ControllerType type) const { + const std::array guid{0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, static_cast(type)}; return { - .guid = Common::UUID{Common::InvalidUUID}, + .guid = Common::UUID{guid}, .port = port, .pad = static_cast(type), }; } +Common::ParamPackage Joycons::GetParamPackage(std::size_t port, Joycon::ControllerType type) const { + const auto identifier = GetIdentifier(port, type); + return { + {"engine", GetEngineName()}, + {"guid", identifier.guid.RawString()}, + {"port", std::to_string(identifier.port)}, + {"pad", std::to_string(identifier.pad)}, + }; +} + std::vector Joycons::GetInputDevices() const { std::vector devices{}; @@ -426,14 +435,11 @@ std::vector Joycons::GetInputDevices() const { if (!device->IsConnected()) { return; } + auto param = GetParamPackage(device->GetDevicePort(), device->GetHandleDeviceType()); std::string name = fmt::format("{} {}", JoyconName(device->GetHandleDeviceType()), device->GetDevicePort() + 1); - devices.emplace_back(Common::ParamPackage{ - {"engine", GetEngineName()}, - {"display", std::move(name)}, - {"port", std::to_string(device->GetDevicePort())}, - {"pad", std::to_string(static_cast(device->GetHandleDeviceType()))}, - }); + param.Set("display", std::move(name)); + devices.emplace_back(param); }; for (const auto& controller : left_joycons) { @@ -451,14 +457,15 @@ std::vector Joycons::GetInputDevices() const { if (!left_joycons[i]->IsConnected() || !right_joycons[i]->IsConnected()) { continue; } - constexpr auto type = Joycon::ControllerType::Dual; + auto main_param = GetParamPackage(i, left_joycons[i]->GetHandleDeviceType()); + const auto second_param = GetParamPackage(i, right_joycons[i]->GetHandleDeviceType()); + const auto type = Joycon::ControllerType::Dual; std::string name = fmt::format("{} {}", JoyconName(type), i + 1); - devices.emplace_back(Common::ParamPackage{ - {"engine", GetEngineName()}, - {"display", std::move(name)}, - {"port", std::to_string(i)}, - {"pad", std::to_string(static_cast(type))}, - }); + + main_param.Set("display", std::move(name)); + main_param.Set("guid2", second_param.Get("guid", "")); + main_param.Set("pad", std::to_string(static_cast(type))); + devices.emplace_back(main_param); } return devices; @@ -494,26 +501,21 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par ButtonMapping mapping{}; for (const auto& [switch_button, joycon_button, side] : switch_to_joycon_button) { - int pad = params.Get("pad", 0); - if (pad == static_cast(Joycon::ControllerType::Dual)) { - pad = side ? static_cast(Joycon::ControllerType::Right) - : static_cast(Joycon::ControllerType::Left); + const std::size_t port = static_cast(params.Get("port", 0)); + auto pad = static_cast(params.Get("pad", 0)); + if (pad == Joycon::ControllerType::Dual) { + pad = side ? Joycon::ControllerType::Right : Joycon::ControllerType::Left; } - Common::ParamPackage button_params{}; - button_params.Set("engine", GetEngineName()); - button_params.Set("port", params.Get("port", 0)); - button_params.Set("pad", pad); + Common::ParamPackage button_params = GetParamPackage(port, pad); button_params.Set("button", static_cast(joycon_button)); mapping.insert_or_assign(switch_button, std::move(button_params)); } // Map SL and SR buttons for left joycons if (params.Get("pad", 0) == static_cast(Joycon::ControllerType::Left)) { - Common::ParamPackage button_params{}; - button_params.Set("engine", GetEngineName()); - button_params.Set("port", params.Get("port", 0)); - button_params.Set("pad", static_cast(Joycon::ControllerType::Left)); + const std::size_t port = static_cast(params.Get("port", 0)); + Common::ParamPackage button_params = GetParamPackage(port, Joycon::ControllerType::Left); Common::ParamPackage sl_button_params = button_params; Common::ParamPackage sr_button_params = button_params; @@ -525,10 +527,8 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par // Map SL and SR buttons for right joycons if (params.Get("pad", 0) == static_cast(Joycon::ControllerType::Right)) { - Common::ParamPackage button_params{}; - button_params.Set("engine", GetEngineName()); - button_params.Set("port", params.Get("port", 0)); - button_params.Set("pad", static_cast(Joycon::ControllerType::Right)); + const std::size_t port = static_cast(params.Get("port", 0)); + Common::ParamPackage button_params = GetParamPackage(port, Joycon::ControllerType::Right); Common::ParamPackage sl_button_params = button_params; Common::ParamPackage sr_button_params = button_params; @@ -546,25 +546,20 @@ AnalogMapping Joycons::GetAnalogMappingForDevice(const Common::ParamPackage& par return {}; } - int pad_left = params.Get("pad", 0); - int pad_right = pad_left; - if (pad_left == static_cast(Joycon::ControllerType::Dual)) { - pad_left = static_cast(Joycon::ControllerType::Left); - pad_right = static_cast(Joycon::ControllerType::Right); + const std::size_t port = static_cast(params.Get("port", 0)); + auto pad_left = static_cast(params.Get("pad", 0)); + auto pad_right = pad_left; + if (pad_left == Joycon::ControllerType::Dual) { + pad_left = Joycon::ControllerType::Left; + pad_right = Joycon::ControllerType::Right; } AnalogMapping mapping = {}; - Common::ParamPackage left_analog_params; - left_analog_params.Set("engine", GetEngineName()); - left_analog_params.Set("port", params.Get("port", 0)); - left_analog_params.Set("pad", pad_left); + Common::ParamPackage left_analog_params = GetParamPackage(port, pad_left); left_analog_params.Set("axis_x", static_cast(Joycon::PadAxes::LeftStickX)); left_analog_params.Set("axis_y", static_cast(Joycon::PadAxes::LeftStickY)); mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params)); - Common::ParamPackage right_analog_params; - right_analog_params.Set("engine", GetEngineName()); - right_analog_params.Set("port", params.Get("port", 0)); - right_analog_params.Set("pad", pad_right); + Common::ParamPackage right_analog_params = GetParamPackage(port, pad_right); right_analog_params.Set("axis_x", static_cast(Joycon::PadAxes::RightStickX)); right_analog_params.Set("axis_y", static_cast(Joycon::PadAxes::RightStickY)); mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params)); @@ -576,24 +571,19 @@ MotionMapping Joycons::GetMotionMappingForDevice(const Common::ParamPackage& par return {}; } - int pad_left = params.Get("pad", 0); - int pad_right = pad_left; - if (pad_left == static_cast(Joycon::ControllerType::Dual)) { - pad_left = static_cast(Joycon::ControllerType::Left); - pad_right = static_cast(Joycon::ControllerType::Right); + const std::size_t port = static_cast(params.Get("port", 0)); + auto pad_left = static_cast(params.Get("pad", 0)); + auto pad_right = pad_left; + if (pad_left == Joycon::ControllerType::Dual) { + pad_left = Joycon::ControllerType::Left; + pad_right = Joycon::ControllerType::Right; } MotionMapping mapping = {}; - Common::ParamPackage left_motion_params; - left_motion_params.Set("engine", GetEngineName()); - left_motion_params.Set("port", params.Get("port", 0)); - left_motion_params.Set("pad", pad_left); + Common::ParamPackage left_motion_params = GetParamPackage(port, pad_left); left_motion_params.Set("motion", 0); mapping.insert_or_assign(Settings::NativeMotion::MotionLeft, std::move(left_motion_params)); - Common::ParamPackage right_Motion_params; - right_Motion_params.Set("engine", GetEngineName()); - right_Motion_params.Set("port", params.Get("port", 0)); - right_Motion_params.Set("pad", pad_right); + Common::ParamPackage right_Motion_params = GetParamPackage(port, pad_right); right_Motion_params.Set("motion", 1); mapping.insert_or_assign(Settings::NativeMotion::MotionRight, std::move(right_Motion_params)); return mapping; @@ -676,7 +666,7 @@ std::string Joycons::JoyconName(Joycon::ControllerType type) const { case Joycon::ControllerType::Dual: return "Dual Joycon"; default: - return "Unknow Joycon"; + return "Unknown Joycon"; } } } // namespace InputCommon diff --git a/src/input_common/drivers/joycon.h b/src/input_common/drivers/joycon.h index f5cc787db..316d383d8 100755 --- a/src/input_common/drivers/joycon.h +++ b/src/input_common/drivers/joycon.h @@ -88,9 +88,12 @@ private: /// Returns a JoyconHandle corresponding to a PadIdentifier std::shared_ptr GetHandle(PadIdentifier identifier) const; - /// Returns a PadIdentifier corresponding to the port number + /// Returns a PadIdentifier corresponding to the port number and joycon type PadIdentifier GetIdentifier(std::size_t port, Joycon::ControllerType type) const; + /// Returns a ParamPackage corresponding to the port number and joycon type + Common::ParamPackage GetParamPackage(std::size_t port, Joycon::ControllerType type) const; + std::string JoyconName(std::size_t port) const; Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; @@ -99,7 +102,6 @@ private: std::string JoyconName(Joycon::ControllerType type) const; std::jthread scan_thread; - bool scan_thread_running{}; // Joycon types are split by type to ease supporting dualjoycon configurations std::array, MaxSupportedControllers> left_joycons{}; diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index db3173b4f..e1f98f9e5 100755 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -321,7 +321,7 @@ void SDLDriver::InitJoystick(int joystick_index) { if (Settings::values.enable_joycon_driver) { if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e && (guid.uuid[8] == 0x06 || guid.uuid[8] == 0x07)) { - LOG_ERROR(Input, "Device black listed {}", joystick_index); + LOG_WARNING(Input, "Preferring joycon driver for device index {}", joystick_index); SDL_JoystickClose(sdl_joystick); return; } diff --git a/src/input_common/helpers/joycon_driver.cpp b/src/input_common/helpers/joycon_driver.cpp index 552572343..cc7cdeb6f 100755 --- a/src/input_common/helpers/joycon_driver.cpp +++ b/src/input_common/helpers/joycon_driver.cpp @@ -123,7 +123,7 @@ DriverResult JoyconDriver::InitializeDevice() { } void JoyconDriver::InputThread(std::stop_token stop_token) { - LOG_INFO(Input, "JC Adapter input thread started"); + LOG_INFO(Input, "Joycon Adapter input thread started"); Common::SetCurrentThreadName("JoyconInput"); input_thread_running = true; @@ -157,7 +157,7 @@ void JoyconDriver::InputThread(std::stop_token stop_token) { is_connected = false; input_thread_running = false; - LOG_INFO(Input, "JC Adapter input thread stopped"); + LOG_INFO(Input, "Joycon Adapter input thread stopped"); } void JoyconDriver::OnNewData(std::span buffer) { diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.cpp b/src/input_common/helpers/joycon_protocol/common_protocol.cpp index 153a3908c..e8c4a7d0e 100755 --- a/src/input_common/helpers/joycon_protocol/common_protocol.cpp +++ b/src/input_common/helpers/joycon_protocol/common_protocol.cpp @@ -120,7 +120,7 @@ DriverResult JoyconCommonProtocol::SendSubCommand(SubCommand sc, std::span buffer) { +DriverResult JoyconCommonProtocol::SendMCUCommand(SubCommand sc, std::span buffer) { std::vector local_buffer(MaxResponseSize); local_buffer[0] = static_cast(OutputReport::MCU_DATA); diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.h b/src/input_common/helpers/joycon_protocol/common_protocol.h index 2a3feaf59..d693f2165 100755 --- a/src/input_common/helpers/joycon_protocol/common_protocol.h +++ b/src/input_common/helpers/joycon_protocol/common_protocol.h @@ -79,7 +79,7 @@ public: * @param sc sub command to be send * @param buffer data to be send */ - DriverResult SendMcuCommand(SubCommand sc, std::span buffer); + DriverResult SendMCUCommand(SubCommand sc, std::span buffer); /** * Sends vibration data to the joycon @@ -150,4 +150,17 @@ private: std::shared_ptr hidapi_handle; }; +class ScopedSetBlocking { +public: + explicit ScopedSetBlocking(JoyconCommonProtocol* self) : m_self{self} { + m_self->SetBlocking(); + } + + ~ScopedSetBlocking() { + m_self->SetNonBlocking(); + } + +private: + JoyconCommonProtocol* m_self{}; +}; } // namespace InputCommon::Joycon diff --git a/src/input_common/helpers/joycon_protocol/irs.cpp b/src/input_common/helpers/joycon_protocol/irs.cpp index 9dfa503c2..077b5b79a 100755 --- a/src/input_common/helpers/joycon_protocol/irs.cpp +++ b/src/input_common/helpers/joycon_protocol/irs.cpp @@ -208,7 +208,7 @@ DriverResult IrsProtocol::WriteRegistersStep1() { // First time we need to set the report mode if (result == DriverResult::Success && tries == 0) { - result = SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); + result = SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); } if (result == DriverResult::Success && tries == 0) { GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output); @@ -272,7 +272,7 @@ DriverResult IrsProtocol::RequestFrame(u8 frame) { mcu_request[3] = frame; mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); mcu_request[37] = 0xFF; - return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); + return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); } DriverResult IrsProtocol::ResendFrame(u8 frame) { @@ -282,7 +282,7 @@ DriverResult IrsProtocol::ResendFrame(u8 frame) { mcu_request[3] = 0x0; mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); mcu_request[37] = 0xFF; - return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); + return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request); } std::vector IrsProtocol::GetImage() const { diff --git a/src/input_common/helpers/joycon_protocol/nfc.cpp b/src/input_common/helpers/joycon_protocol/nfc.cpp index 8755e310b..27147591e 100755 --- a/src/input_common/helpers/joycon_protocol/nfc.cpp +++ b/src/input_common/helpers/joycon_protocol/nfc.cpp @@ -176,7 +176,7 @@ loop1: auto result = SendReadAmiiboRequest(output, ntag_pages); int attempt = 0; - while (1) { + while (true) { if (attempt != 0) { result = GetMCUDataResponse(ReportMode::NFC_IR_MODE_60HZ, output); } @@ -364,45 +364,50 @@ DriverResult NfcProtocol::SendReadAmiiboRequest(std::vector& output, std::si } NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(std::size_t pages) const { + constexpr NFCReadBlockCommand block0{ + .block_count = 1, + }; + constexpr NFCReadBlockCommand block45{ + .block_count = 1, + .blocks = + { + NFCReadBlock{0x00, 0x2C}, + }, + }; + constexpr NFCReadBlockCommand block135{ + .block_count = 3, + .blocks = + { + NFCReadBlock{0x00, 0x3b}, + {0x3c, 0x77}, + {0x78, 0x86}, + }, + }; + constexpr NFCReadBlockCommand block231{ + .block_count = 4, + .blocks = + { + NFCReadBlock{0x00, 0x3b}, + {0x3c, 0x77}, + {0x78, 0x83}, + {0xb4, 0xe6}, + }, + }; + if (pages == 0) { - return { - .block_count = 1, - }; + return block0; } if (pages == 45) { - return { - .block_count = 1, - .blocks = - { - NFCReadBlock{0x00, 0x2C}, - }, - }; + return block45; } if (pages == 135) { - return { - .block_count = 3, - .blocks = - { - NFCReadBlock{0x00, 0x3b}, - {0x3c, 0x77}, - {0x78, 0x86}, - }, - }; + return block135; } if (pages == 231) { - return { - .block_count = 4, - .blocks = - { - NFCReadBlock{0x00, 0x3b}, - {0x3c, 0x77}, - {0x78, 0x83}, - {0xb4, 0xe6}, - }, - }; + return block231; } return {}; diff --git a/src/input_common/helpers/joycon_protocol/poller.cpp b/src/input_common/helpers/joycon_protocol/poller.cpp index 940b20b7f..7f8e093fa 100755 --- a/src/input_common/helpers/joycon_protocol/poller.cpp +++ b/src/input_common/helpers/joycon_protocol/poller.cpp @@ -224,9 +224,9 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) { Joycon::PasivePadButton::StickL, }; - for (std::size_t i = 0; i < left_buttons.size(); ++i) { - const bool button_status = (input.button_input & static_cast(left_buttons[i])) != 0; - const int button = static_cast(left_buttons[i]); + for (auto left_button : left_buttons) { + const bool button_status = (input.button_input & static_cast(left_button)) != 0; + const int button = static_cast(left_button); callbacks.on_button_data(button, button_status); } } @@ -241,9 +241,9 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) { Joycon::PasivePadButton::StickR, }; - for (std::size_t i = 0; i < right_buttons.size(); ++i) { - const bool button_status = (input.button_input & static_cast(right_buttons[i])) != 0; - const int button = static_cast(right_buttons[i]); + for (auto right_button : right_buttons) { + const bool button_status = (input.button_input & static_cast(right_button)) != 0; + const int button = static_cast(right_button); callbacks.on_button_data(button, button_status); } } @@ -259,9 +259,9 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) { Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickR, }; - for (std::size_t i = 0; i < pro_buttons.size(); ++i) { - const bool button_status = (input.button_input & static_cast(pro_buttons[i])) != 0; - const int button = static_cast(pro_buttons[i]); + for (auto pro_button : pro_buttons) { + const bool button_status = (input.button_input & static_cast(pro_button)) != 0; + const int button = static_cast(pro_button); callbacks.on_button_data(button, button_status); } } diff --git a/src/input_common/helpers/joycon_protocol/rumble.cpp b/src/input_common/helpers/joycon_protocol/rumble.cpp index fad67a94b..a83e86828 100755 --- a/src/input_common/helpers/joycon_protocol/rumble.cpp +++ b/src/input_common/helpers/joycon_protocol/rumble.cpp @@ -66,9 +66,9 @@ u8 RumbleProtocol::EncodeLowFrequency(f32 frequency) const { } u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { - /* More information about these values can be found here: - * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md - */ + // More information about these values can be found here: + // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md + static constexpr std::array, 101> high_fequency_amplitude{ std::pair{0.0f, 0x0}, {0.01f, 0x2}, @@ -183,9 +183,9 @@ u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { } u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const { - /* More information about these values can be found here: - * https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md - */ + // More information about these values can be found here: + // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md + static constexpr std::array, 101> high_fequency_amplitude{ std::pair{0.0f, 0x0040}, {0.01f, 0x8040}, diff --git a/src/yuzu/configuration/configure_input_advanced.ui b/src/yuzu/configuration/configure_input_advanced.ui index 029277e43..5c918f47b 100755 --- a/src/yuzu/configuration/configure_input_advanced.ui +++ b/src/yuzu/configuration/configure_input_advanced.ui @@ -2724,7 +2724,7 @@ - + Mouse sensitivity diff --git a/src/yuzu/configuration/configure_ringcon.cpp b/src/yuzu/configuration/configure_ringcon.cpp index bbc9b3b4f..79a7ea281 100755 --- a/src/yuzu/configuration/configure_ringcon.cpp +++ b/src/yuzu/configuration/configure_ringcon.cpp @@ -214,7 +214,8 @@ ConfigureRingController::ConfigureRingController(QWidget* parent, } ConfigureRingController::~ConfigureRingController() { - emulated_controller->SetPollingMode(Common::Input::PollingMode::Active); + emulated_controller->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); emulated_controller->DisableConfiguration(); if (is_controller_set) { @@ -290,7 +291,8 @@ void ConfigureRingController::EnableRingController() { // SetPollingMode is blocking. Allow to update the button status before calling the command repaint(); - const auto result = emulated_controller->SetPollingMode(Common::Input::PollingMode::Ring); + const auto result = emulated_controller->SetPollingMode( + Core::HID::EmulatedDeviceIndex::RightIndex, Common::Input::PollingMode::Ring); switch (result) { case Common::Input::DriverResult::Success: is_ring_enabled = true;