1
0
Fork 0
forked from suyu/suyu

core: hid: Only set the polling mode to the correct side

This commit is contained in:
Narr the Reg 2023-01-13 13:39:33 -06:00
parent b40aefb39e
commit 4a307a7b3a
8 changed files with 71 additions and 28 deletions

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

@ -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;