early-access version 3309
This commit is contained in:
parent
862510daee
commit
3aab951444
20 changed files with 201 additions and 148 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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<std::size_t>(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<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];
|
||||
|
||||
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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<MomentProcessor>(parameters.camera_handle, device);
|
||||
auto& image_transfer_processor = GetProcessor<MomentProcessor>(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<ClusteringProcessor>(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<ImageTransferProcessor>(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<TeraPluginProcessor>(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<PointingProcessor>(camera_handle, device);
|
||||
auto& image_transfer_processor = GetProcessor<PointingProcessor>(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<ImageTransferProcessor>(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<IrLedProcessor>(camera_handle, device);
|
||||
auto& image_transfer_processor = GetProcessor<IrLedProcessor>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -60,15 +60,12 @@ void Joycons::Setup() {
|
|||
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) {
|
||||
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<Joycon::JoyconDriver> Joycons::GetHandle(PadIdentifier identifie
|
|||
}
|
||||
|
||||
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 {
|
||||
.guid = Common::UUID{Common::InvalidUUID},
|
||||
.guid = Common::UUID{guid},
|
||||
.port = port,
|
||||
.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> devices{};
|
||||
|
||||
|
@ -426,14 +435,11 @@ std::vector<Common::ParamPackage> 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<std::size_t>(device->GetHandleDeviceType()))},
|
||||
});
|
||||
param.Set("display", std::move(name));
|
||||
devices.emplace_back(param);
|
||||
};
|
||||
|
||||
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()) {
|
||||
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<std::size_t>(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<size_t>(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<int>(Joycon::ControllerType::Dual)) {
|
||||
pad = side ? static_cast<int>(Joycon::ControllerType::Right)
|
||||
: static_cast<int>(Joycon::ControllerType::Left);
|
||||
const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
|
||||
auto pad = static_cast<Joycon::ControllerType>(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<int>(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<int>(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<int>(Joycon::ControllerType::Left));
|
||||
const std::size_t port = static_cast<std::size_t>(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<int>(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<int>(Joycon::ControllerType::Right));
|
||||
const std::size_t port = static_cast<std::size_t>(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<int>(Joycon::ControllerType::Dual)) {
|
||||
pad_left = static_cast<int>(Joycon::ControllerType::Left);
|
||||
pad_right = static_cast<int>(Joycon::ControllerType::Right);
|
||||
const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
|
||||
auto pad_left = static_cast<Joycon::ControllerType>(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<int>(Joycon::PadAxes::LeftStickX));
|
||||
left_analog_params.Set("axis_y", static_cast<int>(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<int>(Joycon::PadAxes::RightStickX));
|
||||
right_analog_params.Set("axis_y", static_cast<int>(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<int>(Joycon::ControllerType::Dual)) {
|
||||
pad_left = static_cast<int>(Joycon::ControllerType::Left);
|
||||
pad_right = static_cast<int>(Joycon::ControllerType::Right);
|
||||
const std::size_t port = static_cast<std::size_t>(params.Get("port", 0));
|
||||
auto pad_left = static_cast<Joycon::ControllerType>(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
|
||||
|
|
|
@ -88,9 +88,12 @@ private:
|
|||
/// Returns a JoyconHandle corresponding to a PadIdentifier
|
||||
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;
|
||||
|
||||
/// 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<std::shared_ptr<Joycon::JoyconDriver>, MaxSupportedControllers> left_joycons{};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<u8> buffer) {
|
||||
|
|
|
@ -120,7 +120,7 @@ DriverResult JoyconCommonProtocol::SendSubCommand(SubCommand sc, std::span<const
|
|||
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);
|
||||
|
||||
local_buffer[0] = static_cast<u8>(OutputReport::MCU_DATA);
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
* @param sc sub command 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
|
||||
|
@ -150,4 +150,17 @@ private:
|
|||
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
|
||||
|
|
|
@ -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<u8> IrsProtocol::GetImage() const {
|
||||
|
|
|
@ -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<u8>& 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 {};
|
||||
|
|
|
@ -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<u32>(left_buttons[i])) != 0;
|
||||
const int button = static_cast<int>(left_buttons[i]);
|
||||
for (auto left_button : left_buttons) {
|
||||
const bool button_status = (input.button_input & static_cast<u32>(left_button)) != 0;
|
||||
const int button = static_cast<int>(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<u32>(right_buttons[i])) != 0;
|
||||
const int button = static_cast<int>(right_buttons[i]);
|
||||
for (auto right_button : right_buttons) {
|
||||
const bool button_status = (input.button_input & static_cast<u32>(right_button)) != 0;
|
||||
const int button = static_cast<int>(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<u32>(pro_buttons[i])) != 0;
|
||||
const int button = static_cast<int>(pro_buttons[i]);
|
||||
for (auto pro_button : pro_buttons) {
|
||||
const bool button_status = (input.button_input & static_cast<u32>(pro_button)) != 0;
|
||||
const int button = static_cast<int>(pro_button);
|
||||
callbacks.on_button_data(button, button_status);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<std::pair<f32, int>, 101> high_fequency_amplitude{
|
||||
std::pair<f32, int>{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<std::pair<f32, int>, 101> high_fequency_amplitude{
|
||||
std::pair<f32, int>{0.0f, 0x0040},
|
||||
{0.01f, 0x8040},
|
||||
|
|
|
@ -2724,7 +2724,7 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="2">
|
||||
<item row="6" column="2">
|
||||
<widget class="QSpinBox" name="mouse_panning_sensitivity">
|
||||
<property name="toolTip">
|
||||
<string>Mouse sensitivity</string>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue