early-access version 3309

main
pineappleEA 2023-01-15 21:36:14 +01:00
parent 862510daee
commit 3aab951444
20 changed files with 201 additions and 148 deletions

View File

@ -1,7 +1,7 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 3308. This is the source code for early-access 3309.
## Legal Notice ## Legal Notice

View File

@ -1208,19 +1208,31 @@ bool EmulatedController::IsVibrationEnabled(std::size_t device_index) {
} }
Common::Input::DriverResult EmulatedController::SetPollingMode( Common::Input::DriverResult EmulatedController::SetPollingMode(
Common::Input::PollingMode polling_mode) { EmulatedDeviceIndex device_index, Common::Input::PollingMode polling_mode) {
LOG_INFO(Service_HID, "Set polling mode {}", polling_mode); LOG_INFO(Service_HID, "Set polling mode {}, device_index={}", polling_mode, device_index);
auto& output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
auto& left_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Left)];
auto& right_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
auto& nfc_output_device = output_devices[3]; auto& nfc_output_device = output_devices[3];
const auto virtual_nfc_result = nfc_output_device->SetPollingMode(polling_mode); if (device_index == EmulatedDeviceIndex::LeftIndex) {
const auto mapped_nfc_result = output_device->SetPollingMode(polling_mode); return left_output_device->SetPollingMode(polling_mode);
if (virtual_nfc_result == Common::Input::DriverResult::Success) {
return virtual_nfc_result;
} }
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( bool EmulatedController::SetCameraFormat(

View File

@ -363,10 +363,12 @@ public:
/** /**
* Sets the desired data to be polled from a controller * 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. * @param polling_mode type of input desired buttons, gyro, nfc, ir, etc.
* @return driver result from this command * @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 * Sets the desired camera format to be polled from a controller

View File

@ -337,7 +337,19 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) {
controller.is_connected = true; controller.is_connected = true;
controller.device->Connect(); controller.device->Connect();
controller.device->SetLedPattern(); 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); SignalStyleSetChangedEvent(npad_id);
WriteEmptyEntry(controller.shared_memory); WriteEmptyEntry(controller.shared_memory);
} }

View File

@ -18,12 +18,14 @@ RingController::RingController(Core::HID::HIDCore& hid_core_,
RingController::~RingController() = default; RingController::~RingController() = default;
void RingController::OnInit() { void RingController::OnInit() {
input->SetPollingMode(Common::Input::PollingMode::Ring); input->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Ring);
return; return;
} }
void RingController::OnRelease() { void RingController::OnRelease() {
input->SetPollingMode(Common::Input::PollingMode::Active); input->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
return; return;
}; };

View File

@ -108,7 +108,8 @@ void IRS::StopImageProcessor(Kernel::HLERequestContext& ctx) {
auto result = IsIrCameraHandleValid(parameters.camera_handle); auto result = IsIrCameraHandleValid(parameters.camera_handle);
if (result.IsSuccess()) { if (result.IsSuccess()) {
// TODO: Stop Image processor // TODO: Stop Image processor
npad_device->SetPollingMode(Common::Input::PollingMode::Active); npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
result = ResultSuccess; result = ResultSuccess;
} }
@ -140,7 +141,8 @@ void IRS::RunMomentProcessor(Kernel::HLERequestContext& ctx) {
MakeProcessor<MomentProcessor>(parameters.camera_handle, device); MakeProcessor<MomentProcessor>(parameters.camera_handle, device);
auto& image_transfer_processor = GetProcessor<MomentProcessor>(parameters.camera_handle); auto& image_transfer_processor = GetProcessor<MomentProcessor>(parameters.camera_handle);
image_transfer_processor.SetConfig(parameters.processor_config); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -172,7 +174,8 @@ void IRS::RunClusteringProcessor(Kernel::HLERequestContext& ctx) {
auto& image_transfer_processor = auto& image_transfer_processor =
GetProcessor<ClusteringProcessor>(parameters.camera_handle); GetProcessor<ClusteringProcessor>(parameters.camera_handle);
image_transfer_processor.SetConfig(parameters.processor_config); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -222,7 +225,8 @@ void IRS::RunImageTransferProcessor(Kernel::HLERequestContext& ctx) {
GetProcessor<ImageTransferProcessor>(parameters.camera_handle); GetProcessor<ImageTransferProcessor>(parameters.camera_handle);
image_transfer_processor.SetConfig(parameters.processor_config); image_transfer_processor.SetConfig(parameters.processor_config);
image_transfer_processor.SetTransferMemoryPointer(transfer_memory); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -298,7 +302,8 @@ void IRS::RunTeraPluginProcessor(Kernel::HLERequestContext& ctx) {
auto& image_transfer_processor = auto& image_transfer_processor =
GetProcessor<TeraPluginProcessor>(parameters.camera_handle); GetProcessor<TeraPluginProcessor>(parameters.camera_handle);
image_transfer_processor.SetConfig(parameters.processor_config); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -348,7 +353,8 @@ void IRS::RunPointingProcessor(Kernel::HLERequestContext& ctx) {
MakeProcessor<PointingProcessor>(camera_handle, device); MakeProcessor<PointingProcessor>(camera_handle, device);
auto& image_transfer_processor = GetProcessor<PointingProcessor>(camera_handle); auto& image_transfer_processor = GetProcessor<PointingProcessor>(camera_handle);
image_transfer_processor.SetConfig(processor_config); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -459,7 +465,8 @@ void IRS::RunImageTransferExProcessor(Kernel::HLERequestContext& ctx) {
GetProcessor<ImageTransferProcessor>(parameters.camera_handle); GetProcessor<ImageTransferProcessor>(parameters.camera_handle);
image_transfer_processor.SetConfig(parameters.processor_config); image_transfer_processor.SetConfig(parameters.processor_config);
image_transfer_processor.SetTransferMemoryPointer(transfer_memory); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -486,7 +493,8 @@ void IRS::RunIrLedProcessor(Kernel::HLERequestContext& ctx) {
MakeProcessor<IrLedProcessor>(camera_handle, device); MakeProcessor<IrLedProcessor>(camera_handle, device);
auto& image_transfer_processor = GetProcessor<IrLedProcessor>(camera_handle); auto& image_transfer_processor = GetProcessor<IrLedProcessor>(camera_handle);
image_transfer_processor.SetConfig(processor_config); 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}; IPC::ResponseBuilder rb{ctx, 2};
@ -512,7 +520,8 @@ void IRS::StopImageProcessorAsync(Kernel::HLERequestContext& ctx) {
auto result = IsIrCameraHandleValid(parameters.camera_handle); auto result = IsIrCameraHandleValid(parameters.camera_handle);
if (result.IsSuccess()) { if (result.IsSuccess()) {
// TODO: Stop image processor async // 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; result = ResultSuccess;
} }

View File

@ -130,7 +130,8 @@ Result NfcDevice::StartDetection(NFP::TagProtocol allowed_protocol) {
return WrongDeviceState; 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) { Common::Input::DriverResult::Success) {
LOG_ERROR(Service_NFC, "Nfc not supported"); LOG_ERROR(Service_NFC, "Nfc not supported");
return NfcDisabled; return NfcDisabled;
@ -142,7 +143,8 @@ Result NfcDevice::StartDetection(NFP::TagProtocol allowed_protocol) {
} }
Result NfcDevice::StopDetection() { 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) { if (device_state == NFP::DeviceState::Initialized) {
return ResultSuccess; return ResultSuccess;

View File

@ -152,7 +152,8 @@ Result NfpDevice::StartDetection(TagProtocol allowed_protocol) {
return WrongDeviceState; 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) { Common::Input::DriverResult::Success) {
LOG_ERROR(Service_NFP, "Nfc not supported"); LOG_ERROR(Service_NFP, "Nfc not supported");
return NfcDisabled; return NfcDisabled;
@ -164,7 +165,8 @@ Result NfpDevice::StartDetection(TagProtocol allowed_protocol) {
} }
Result NfpDevice::StopDetection() { 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) { if (device_state == DeviceState::Initialized) {
return ResultSuccess; return ResultSuccess;

View File

@ -60,15 +60,12 @@ void Joycons::Setup() {
device = std::make_shared<Joycon::JoyconDriver>(port++); device = std::make_shared<Joycon::JoyconDriver>(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) { void Joycons::ScanThread(std::stop_token stop_token) {
constexpr u16 nintendo_vendor_id = 0x057e; constexpr u16 nintendo_vendor_id = 0x057e;
Common::SetCurrentThreadName("yuzu:input:JoyconScanThread"); Common::SetCurrentThreadName("JoyconScanThread");
scan_thread_running = true;
while (!stop_token.stop_requested()) { while (!stop_token.stop_requested()) {
SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0); SDL_hid_device_info* devs = SDL_hid_enumerate(nintendo_vendor_id, 0x0);
SDL_hid_device_info* cur_dev = devs; SDL_hid_device_info* cur_dev = devs;
@ -82,9 +79,9 @@ void Joycons::ScanThread(std::stop_token stop_token) {
cur_dev = cur_dev->next; cur_dev = cur_dev->next;
} }
SDL_hid_free_enumeration(devs);
std::this_thread::sleep_for(std::chrono::seconds(5)); std::this_thread::sleep_for(std::chrono::seconds(5));
} }
scan_thread_running = false;
} }
bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const { bool Joycons::IsDeviceNew(SDL_hid_device_info* device_info) const {
@ -409,13 +406,25 @@ std::shared_ptr<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
} }
PadIdentifier Joycons::GetIdentifier(std::size_t port, Joycon::ControllerType type) const { PadIdentifier Joycons::GetIdentifier(std::size_t port, Joycon::ControllerType type) const {
const std::array<u8, 16> guid{0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, static_cast<u8>(type)};
return { return {
.guid = Common::UUID{Common::InvalidUUID}, .guid = Common::UUID{guid},
.port = port, .port = port,
.pad = static_cast<std::size_t>(type), .pad = static_cast<std::size_t>(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<Common::ParamPackage> Joycons::GetInputDevices() const { std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
std::vector<Common::ParamPackage> devices{}; std::vector<Common::ParamPackage> devices{};
@ -426,14 +435,11 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
if (!device->IsConnected()) { if (!device->IsConnected()) {
return; return;
} }
auto param = GetParamPackage(device->GetDevicePort(), device->GetHandleDeviceType());
std::string name = fmt::format("{} {}", JoyconName(device->GetHandleDeviceType()), std::string name = fmt::format("{} {}", JoyconName(device->GetHandleDeviceType()),
device->GetDevicePort() + 1); device->GetDevicePort() + 1);
devices.emplace_back(Common::ParamPackage{ param.Set("display", std::move(name));
{"engine", GetEngineName()}, devices.emplace_back(param);
{"display", std::move(name)},
{"port", std::to_string(device->GetDevicePort())},
{"pad", std::to_string(static_cast<std::size_t>(device->GetHandleDeviceType()))},
});
}; };
for (const auto& controller : left_joycons) { for (const auto& controller : left_joycons) {
@ -451,14 +457,15 @@ std::vector<Common::ParamPackage> Joycons::GetInputDevices() const {
if (!left_joycons[i]->IsConnected() || !right_joycons[i]->IsConnected()) { if (!left_joycons[i]->IsConnected() || !right_joycons[i]->IsConnected()) {
continue; 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); std::string name = fmt::format("{} {}", JoyconName(type), i + 1);
devices.emplace_back(Common::ParamPackage{
{"engine", GetEngineName()}, main_param.Set("display", std::move(name));
{"display", std::move(name)}, main_param.Set("guid2", second_param.Get("guid", ""));
{"port", std::to_string(i)}, main_param.Set("pad", std::to_string(static_cast<size_t>(type)));
{"pad", std::to_string(static_cast<std::size_t>(type))}, devices.emplace_back(main_param);
});
} }
return devices; return devices;
@ -494,26 +501,21 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par
ButtonMapping mapping{}; ButtonMapping mapping{};
for (const auto& [switch_button, joycon_button, side] : switch_to_joycon_button) { for (const auto& [switch_button, joycon_button, side] : switch_to_joycon_button) {
int pad = params.Get("pad", 0); const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
if (pad == static_cast<int>(Joycon::ControllerType::Dual)) { auto pad = static_cast<Joycon::ControllerType>(params.Get("pad", 0));
pad = side ? static_cast<int>(Joycon::ControllerType::Right) if (pad == Joycon::ControllerType::Dual) {
: static_cast<int>(Joycon::ControllerType::Left); pad = side ? Joycon::ControllerType::Right : Joycon::ControllerType::Left;
} }
Common::ParamPackage button_params{}; Common::ParamPackage button_params = GetParamPackage(port, pad);
button_params.Set("engine", GetEngineName());
button_params.Set("port", params.Get("port", 0));
button_params.Set("pad", pad);
button_params.Set("button", static_cast<int>(joycon_button)); button_params.Set("button", static_cast<int>(joycon_button));
mapping.insert_or_assign(switch_button, std::move(button_params)); mapping.insert_or_assign(switch_button, std::move(button_params));
} }
// Map SL and SR buttons for left joycons // Map SL and SR buttons for left joycons
if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Left)) { if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Left)) {
Common::ParamPackage button_params{}; const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
button_params.Set("engine", GetEngineName()); Common::ParamPackage button_params = GetParamPackage(port, Joycon::ControllerType::Left);
button_params.Set("port", params.Get("port", 0));
button_params.Set("pad", static_cast<int>(Joycon::ControllerType::Left));
Common::ParamPackage sl_button_params = button_params; Common::ParamPackage sl_button_params = button_params;
Common::ParamPackage sr_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 // Map SL and SR buttons for right joycons
if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Right)) { if (params.Get("pad", 0) == static_cast<int>(Joycon::ControllerType::Right)) {
Common::ParamPackage button_params{}; const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
button_params.Set("engine", GetEngineName()); Common::ParamPackage button_params = GetParamPackage(port, Joycon::ControllerType::Right);
button_params.Set("port", params.Get("port", 0));
button_params.Set("pad", static_cast<int>(Joycon::ControllerType::Right));
Common::ParamPackage sl_button_params = button_params; Common::ParamPackage sl_button_params = button_params;
Common::ParamPackage sr_button_params = button_params; Common::ParamPackage sr_button_params = button_params;
@ -546,25 +546,20 @@ AnalogMapping Joycons::GetAnalogMappingForDevice(const Common::ParamPackage& par
return {}; return {};
} }
int pad_left = params.Get("pad", 0); const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
int pad_right = pad_left; auto pad_left = static_cast<Joycon::ControllerType>(params.Get("pad", 0));
if (pad_left == static_cast<int>(Joycon::ControllerType::Dual)) { auto pad_right = pad_left;
pad_left = static_cast<int>(Joycon::ControllerType::Left); if (pad_left == Joycon::ControllerType::Dual) {
pad_right = static_cast<int>(Joycon::ControllerType::Right); pad_left = Joycon::ControllerType::Left;
pad_right = Joycon::ControllerType::Right;
} }
AnalogMapping mapping = {}; AnalogMapping mapping = {};
Common::ParamPackage left_analog_params; Common::ParamPackage left_analog_params = GetParamPackage(port, pad_left);
left_analog_params.Set("engine", GetEngineName());
left_analog_params.Set("port", params.Get("port", 0));
left_analog_params.Set("pad", pad_left);
left_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::LeftStickX)); left_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::LeftStickX));
left_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::LeftStickY)); left_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::LeftStickY));
mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params)); mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params));
Common::ParamPackage right_analog_params; Common::ParamPackage right_analog_params = GetParamPackage(port, pad_right);
right_analog_params.Set("engine", GetEngineName());
right_analog_params.Set("port", params.Get("port", 0));
right_analog_params.Set("pad", pad_right);
right_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::RightStickX)); right_analog_params.Set("axis_x", static_cast<int>(Joycon::PadAxes::RightStickX));
right_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::RightStickY)); right_analog_params.Set("axis_y", static_cast<int>(Joycon::PadAxes::RightStickY));
mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params)); mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params));
@ -576,24 +571,19 @@ MotionMapping Joycons::GetMotionMappingForDevice(const Common::ParamPackage& par
return {}; return {};
} }
int pad_left = params.Get("pad", 0); const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
int pad_right = pad_left; auto pad_left = static_cast<Joycon::ControllerType>(params.Get("pad", 0));
if (pad_left == static_cast<int>(Joycon::ControllerType::Dual)) { auto pad_right = pad_left;
pad_left = static_cast<int>(Joycon::ControllerType::Left); if (pad_left == Joycon::ControllerType::Dual) {
pad_right = static_cast<int>(Joycon::ControllerType::Right); pad_left = Joycon::ControllerType::Left;
pad_right = Joycon::ControllerType::Right;
} }
MotionMapping mapping = {}; MotionMapping mapping = {};
Common::ParamPackage left_motion_params; Common::ParamPackage left_motion_params = GetParamPackage(port, pad_left);
left_motion_params.Set("engine", GetEngineName());
left_motion_params.Set("port", params.Get("port", 0));
left_motion_params.Set("pad", pad_left);
left_motion_params.Set("motion", 0); left_motion_params.Set("motion", 0);
mapping.insert_or_assign(Settings::NativeMotion::MotionLeft, std::move(left_motion_params)); mapping.insert_or_assign(Settings::NativeMotion::MotionLeft, std::move(left_motion_params));
Common::ParamPackage right_Motion_params; Common::ParamPackage right_Motion_params = GetParamPackage(port, pad_right);
right_Motion_params.Set("engine", GetEngineName());
right_Motion_params.Set("port", params.Get("port", 0));
right_Motion_params.Set("pad", pad_right);
right_Motion_params.Set("motion", 1); right_Motion_params.Set("motion", 1);
mapping.insert_or_assign(Settings::NativeMotion::MotionRight, std::move(right_Motion_params)); mapping.insert_or_assign(Settings::NativeMotion::MotionRight, std::move(right_Motion_params));
return mapping; return mapping;
@ -676,7 +666,7 @@ std::string Joycons::JoyconName(Joycon::ControllerType type) const {
case Joycon::ControllerType::Dual: case Joycon::ControllerType::Dual:
return "Dual Joycon"; return "Dual Joycon";
default: default:
return "Unknow Joycon"; return "Unknown Joycon";
} }
} }
} // namespace InputCommon } // namespace InputCommon

View File

@ -88,9 +88,12 @@ private:
/// Returns a JoyconHandle corresponding to a PadIdentifier /// Returns a JoyconHandle corresponding to a PadIdentifier
std::shared_ptr<Joycon::JoyconDriver> GetHandle(PadIdentifier identifier) const; std::shared_ptr<Joycon::JoyconDriver> 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; 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; std::string JoyconName(std::size_t port) const;
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
@ -99,7 +102,6 @@ private:
std::string JoyconName(Joycon::ControllerType type) const; std::string JoyconName(Joycon::ControllerType type) const;
std::jthread scan_thread; std::jthread scan_thread;
bool scan_thread_running{};
// Joycon types are split by type to ease supporting dualjoycon configurations // Joycon types are split by type to ease supporting dualjoycon configurations
std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{}; std::array<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};

View File

@ -321,7 +321,7 @@ void SDLDriver::InitJoystick(int joystick_index) {
if (Settings::values.enable_joycon_driver) { if (Settings::values.enable_joycon_driver) {
if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e && if (guid.uuid[5] == 0x05 && guid.uuid[4] == 0x7e &&
(guid.uuid[8] == 0x06 || guid.uuid[8] == 0x07)) { (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); SDL_JoystickClose(sdl_joystick);
return; return;
} }

View File

@ -123,7 +123,7 @@ DriverResult JoyconDriver::InitializeDevice() {
} }
void JoyconDriver::InputThread(std::stop_token stop_token) { 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"); Common::SetCurrentThreadName("JoyconInput");
input_thread_running = true; input_thread_running = true;
@ -157,7 +157,7 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
is_connected = false; is_connected = false;
input_thread_running = 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<u8> buffer) { void JoyconDriver::OnNewData(std::span<u8> buffer) {

View File

@ -120,7 +120,7 @@ DriverResult JoyconCommonProtocol::SendSubCommand(SubCommand sc, std::span<const
return DriverResult::Success; return DriverResult::Success;
} }
DriverResult JoyconCommonProtocol::SendMcuCommand(SubCommand sc, std::span<const u8> buffer) { DriverResult JoyconCommonProtocol::SendMCUCommand(SubCommand sc, std::span<const u8> buffer) {
std::vector<u8> local_buffer(MaxResponseSize); std::vector<u8> local_buffer(MaxResponseSize);
local_buffer[0] = static_cast<u8>(OutputReport::MCU_DATA); local_buffer[0] = static_cast<u8>(OutputReport::MCU_DATA);

View File

@ -79,7 +79,7 @@ public:
* @param sc sub command to be send * @param sc sub command to be send
* @param buffer data to be send * @param buffer data to be send
*/ */
DriverResult SendMcuCommand(SubCommand sc, std::span<const u8> buffer); DriverResult SendMCUCommand(SubCommand sc, std::span<const u8> buffer);
/** /**
* Sends vibration data to the joycon * Sends vibration data to the joycon
@ -150,4 +150,17 @@ private:
std::shared_ptr<JoyconHandle> hidapi_handle; std::shared_ptr<JoyconHandle> 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 } // namespace InputCommon::Joycon

View File

@ -208,7 +208,7 @@ DriverResult IrsProtocol::WriteRegistersStep1() {
// First time we need to set the report mode // First time we need to set the report mode
if (result == DriverResult::Success && tries == 0) { 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) { if (result == DriverResult::Success && tries == 0) {
GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output); GetSubCommandResponse(SubCommand::SET_MCU_CONFIG, output);
@ -272,7 +272,7 @@ DriverResult IrsProtocol::RequestFrame(u8 frame) {
mcu_request[3] = frame; mcu_request[3] = frame;
mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36);
mcu_request[37] = 0xFF; 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) { DriverResult IrsProtocol::ResendFrame(u8 frame) {
@ -282,7 +282,7 @@ DriverResult IrsProtocol::ResendFrame(u8 frame) {
mcu_request[3] = 0x0; mcu_request[3] = 0x0;
mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36); mcu_request[36] = CalculateMCU_CRC8(mcu_request.data(), 36);
mcu_request[37] = 0xFF; mcu_request[37] = 0xFF;
return SendMcuCommand(SubCommand::SET_REPORT_MODE, mcu_request); return SendMCUCommand(SubCommand::SET_REPORT_MODE, mcu_request);
} }
std::vector<u8> IrsProtocol::GetImage() const { std::vector<u8> IrsProtocol::GetImage() const {

View File

@ -176,7 +176,7 @@ loop1:
auto result = SendReadAmiiboRequest(output, ntag_pages); auto result = SendReadAmiiboRequest(output, ntag_pages);
int attempt = 0; int attempt = 0;
while (1) { while (true) {
if (attempt != 0) { if (attempt != 0) {
result = GetMCUDataResponse(ReportMode::NFC_IR_MODE_60HZ, output); result = GetMCUDataResponse(ReportMode::NFC_IR_MODE_60HZ, output);
} }
@ -364,45 +364,50 @@ DriverResult NfcProtocol::SendReadAmiiboRequest(std::vector<u8>& output, std::si
} }
NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(std::size_t pages) const { 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) { if (pages == 0) {
return { return block0;
.block_count = 1,
};
} }
if (pages == 45) { if (pages == 45) {
return { return block45;
.block_count = 1,
.blocks =
{
NFCReadBlock{0x00, 0x2C},
},
};
} }
if (pages == 135) { if (pages == 135) {
return { return block135;
.block_count = 3,
.blocks =
{
NFCReadBlock{0x00, 0x3b},
{0x3c, 0x77},
{0x78, 0x86},
},
};
} }
if (pages == 231) { if (pages == 231) {
return { return block231;
.block_count = 4,
.blocks =
{
NFCReadBlock{0x00, 0x3b},
{0x3c, 0x77},
{0x78, 0x83},
{0xb4, 0xe6},
},
};
} }
return {}; return {};

View File

@ -224,9 +224,9 @@ void JoyconPoller::UpdatePasiveLeftPadInput(const InputReportPassive& input) {
Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickL,
}; };
for (std::size_t i = 0; i < left_buttons.size(); ++i) { for (auto left_button : left_buttons) {
const bool button_status = (input.button_input & static_cast<u32>(left_buttons[i])) != 0; const bool button_status = (input.button_input & static_cast<u32>(left_button)) != 0;
const int button = static_cast<int>(left_buttons[i]); const int button = static_cast<int>(left_button);
callbacks.on_button_data(button, button_status); callbacks.on_button_data(button, button_status);
} }
} }
@ -241,9 +241,9 @@ void JoyconPoller::UpdatePasiveRightPadInput(const InputReportPassive& input) {
Joycon::PasivePadButton::StickR, Joycon::PasivePadButton::StickR,
}; };
for (std::size_t i = 0; i < right_buttons.size(); ++i) { for (auto right_button : right_buttons) {
const bool button_status = (input.button_input & static_cast<u32>(right_buttons[i])) != 0; const bool button_status = (input.button_input & static_cast<u32>(right_button)) != 0;
const int button = static_cast<int>(right_buttons[i]); const int button = static_cast<int>(right_button);
callbacks.on_button_data(button, button_status); callbacks.on_button_data(button, button_status);
} }
} }
@ -259,9 +259,9 @@ void JoyconPoller::UpdatePasiveProPadInput(const InputReportPassive& input) {
Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickR, Joycon::PasivePadButton::StickL, Joycon::PasivePadButton::StickR,
}; };
for (std::size_t i = 0; i < pro_buttons.size(); ++i) { for (auto pro_button : pro_buttons) {
const bool button_status = (input.button_input & static_cast<u32>(pro_buttons[i])) != 0; const bool button_status = (input.button_input & static_cast<u32>(pro_button)) != 0;
const int button = static_cast<int>(pro_buttons[i]); const int button = static_cast<int>(pro_button);
callbacks.on_button_data(button, button_status); callbacks.on_button_data(button, button_status);
} }
} }

View File

@ -66,9 +66,9 @@ u8 RumbleProtocol::EncodeLowFrequency(f32 frequency) const {
} }
u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const {
/* More information about these values can be found here: // More information about these values can be found here:
* https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
*/
static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{
std::pair<f32, int>{0.0f, 0x0}, std::pair<f32, int>{0.0f, 0x0},
{0.01f, 0x2}, {0.01f, 0x2},
@ -183,9 +183,9 @@ u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const {
} }
u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const { u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const {
/* More information about these values can be found here: // More information about these values can be found here:
* https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md
*/
static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{
std::pair<f32, int>{0.0f, 0x0040}, std::pair<f32, int>{0.0f, 0x0040},
{0.01f, 0x8040}, {0.01f, 0x8040},

View File

@ -2724,7 +2724,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="2"> <item row="6" column="2">
<widget class="QSpinBox" name="mouse_panning_sensitivity"> <widget class="QSpinBox" name="mouse_panning_sensitivity">
<property name="toolTip"> <property name="toolTip">
<string>Mouse sensitivity</string> <string>Mouse sensitivity</string>

View File

@ -214,7 +214,8 @@ ConfigureRingController::ConfigureRingController(QWidget* parent,
} }
ConfigureRingController::~ConfigureRingController() { ConfigureRingController::~ConfigureRingController() {
emulated_controller->SetPollingMode(Common::Input::PollingMode::Active); emulated_controller->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex,
Common::Input::PollingMode::Active);
emulated_controller->DisableConfiguration(); emulated_controller->DisableConfiguration();
if (is_controller_set) { if (is_controller_set) {
@ -290,7 +291,8 @@ void ConfigureRingController::EnableRingController() {
// SetPollingMode is blocking. Allow to update the button status before calling the command // SetPollingMode is blocking. Allow to update the button status before calling the command
repaint(); 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) { switch (result) {
case Common::Input::DriverResult::Success: case Common::Input::DriverResult::Success:
is_ring_enabled = true; is_ring_enabled = true;