2021-09-28 22:10:10 +00:00
|
|
|
using Ryujinx.Common;
|
2021-06-19 11:53:18 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-10-17 17:15:50 +00:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2019-04-20 02:23:13 +00:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
2019-09-19 00:45:11 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.HidServer;
|
2021-09-28 22:10:10 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Irs.Types;
|
2019-04-20 01:56:55 +00:00
|
|
|
using System;
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2019-06-27 16:02:41 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Hid.Irs
|
2018-10-07 15:12:11 +00:00
|
|
|
{
|
2019-07-10 15:59:54 +00:00
|
|
|
[Service("irs")]
|
2018-10-07 15:12:11 +00:00
|
|
|
class IIrSensorServer : IpcService
|
|
|
|
{
|
2019-06-27 16:02:41 +00:00
|
|
|
private int _irsensorSharedMemoryHandle = 0;
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
public IIrSensorServer(ServiceCtx context) { }
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(302)]
|
2018-10-07 15:12:11 +00:00
|
|
|
// ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode ActivateIrsensor(ServiceCtx context)
|
2018-10-07 15:12:11 +00:00
|
|
|
{
|
2021-09-28 22:10:10 +00:00
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
// NOTE: This seems to initialize the shared memory for irs service.
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-10-07 15:12:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(303)]
|
2018-10-07 15:12:11 +00:00
|
|
|
// DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode DeactivateIrsensor(ServiceCtx context)
|
2018-10-07 15:12:11 +00:00
|
|
|
{
|
2021-09-28 22:10:10 +00:00
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
// NOTE: This seems to deinitialize the shared memory for irs service.
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-10-07 15:12:11 +00:00
|
|
|
}
|
2019-04-20 01:56:55 +00:00
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(304)]
|
2019-04-20 02:23:13 +00:00
|
|
|
// GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetIrsensorSharedMemoryHandle(ServiceCtx context)
|
2019-04-20 02:23:13 +00:00
|
|
|
{
|
2021-09-28 22:10:10 +00:00
|
|
|
// NOTE: Shared memory should use the appletResourceUserId.
|
|
|
|
// ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
|
2019-06-27 16:02:41 +00:00
|
|
|
if (_irsensorSharedMemoryHandle == 0)
|
2019-04-20 02:23:13 +00:00
|
|
|
{
|
2019-06-27 16:02:41 +00:00
|
|
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != KernelResult.Success)
|
|
|
|
{
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
}
|
2019-04-20 02:23:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-27 16:02:41 +00:00
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_irsensorSharedMemoryHandle);
|
2019-04-20 02:23:13 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2019-04-20 02:23:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 22:10:10 +00:00
|
|
|
[CommandHipc(305)]
|
|
|
|
// StopImageProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId)
|
|
|
|
public ResultCode StopImageProcessor(ServiceCtx context)
|
|
|
|
{
|
|
|
|
IrCameraHandle irCameraHandle = context.RequestData.ReadStruct<IrCameraHandle>();
|
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
CheckCameraHandle(irCameraHandle);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(306)]
|
|
|
|
// RunMomentProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedMomentProcessorConfig)
|
|
|
|
public ResultCode RunMomentProcessor(ServiceCtx context)
|
|
|
|
{
|
|
|
|
IrCameraHandle irCameraHandle = context.RequestData.ReadStruct<IrCameraHandle>();
|
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
var packedMomentProcessorConfig = context.RequestData.ReadStruct<PackedMomentProcessorConfig>();
|
|
|
|
|
|
|
|
CheckCameraHandle(irCameraHandle);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedMomentProcessorConfig.ExposureTime });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(307)]
|
|
|
|
// RunClusteringProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedClusteringProcessorConfig)
|
|
|
|
public ResultCode RunClusteringProcessor(ServiceCtx context)
|
|
|
|
{
|
|
|
|
IrCameraHandle irCameraHandle = context.RequestData.ReadStruct<IrCameraHandle>();
|
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
var packedClusteringProcessorConfig = context.RequestData.ReadStruct<PackedClusteringProcessorConfig>();
|
|
|
|
|
|
|
|
CheckCameraHandle(irCameraHandle);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedClusteringProcessorConfig.ExposureTime });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(308)]
|
|
|
|
// RunImageTransferProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedImageTransferProcessorConfig, u64 TransferMemorySize, TransferMemoryHandle)
|
|
|
|
public ResultCode RunImageTransferProcessor(ServiceCtx context)
|
|
|
|
{
|
|
|
|
IrCameraHandle irCameraHandle = context.RequestData.ReadStruct<IrCameraHandle>();
|
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
var packedImageTransferProcessorConfig = context.RequestData.ReadStruct<PackedImageTransferProcessorConfig>();
|
|
|
|
|
|
|
|
CheckCameraHandle(irCameraHandle);
|
|
|
|
|
|
|
|
// TODO: Handle the Transfer Memory.
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedImageTransferProcessorConfig.ExposureTime });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(309)]
|
|
|
|
// GetImageTransferProcessorState(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId)
|
|
|
|
public ResultCode GetImageTransferProcessorState(ServiceCtx context)
|
|
|
|
{
|
|
|
|
IrCameraHandle irCameraHandle = context.RequestData.ReadStruct<IrCameraHandle>();
|
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
|
|
|
|
// ulong imageTransferBufferAddress = context.Request.ReceiveBuff[0].Position;
|
|
|
|
ulong imageTransferBufferSize = context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
if (imageTransferBufferSize == 0)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidBufferSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckCameraHandle(irCameraHandle);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType });
|
|
|
|
|
|
|
|
// TODO: Uses the buffer to copy the JoyCon IR data (by using a JoyCon driver) and update the following struct.
|
|
|
|
context.ResponseData.WriteStruct(new ImageTransferProcessorState()
|
|
|
|
{
|
|
|
|
SamplingNumber = 0,
|
|
|
|
AmbientNoiseLevel = 0
|
|
|
|
});
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
[CommandHipc(310)]
|
|
|
|
// RunTeraPluginProcessor(pid, nn::irsensor::IrCameraHandle, nn::applet::AppletResourceUserId, PackedTeraPluginProcessorConfig)
|
|
|
|
public ResultCode RunTeraPluginProcessor(ServiceCtx context)
|
|
|
|
{
|
|
|
|
IrCameraHandle irCameraHandle = context.RequestData.ReadStruct<IrCameraHandle>();
|
|
|
|
ulong appletResourceUserId = context.RequestData.ReadUInt64();
|
|
|
|
var packedTeraPluginProcessorConfig = context.RequestData.ReadStruct<PackedTeraPluginProcessorConfig>();
|
|
|
|
|
|
|
|
CheckCameraHandle(irCameraHandle);
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle.PlayerNumber, irCameraHandle.DeviceType, packedTeraPluginProcessorConfig.RequiredMcuVersion });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(311)]
|
2019-04-20 01:56:55 +00:00
|
|
|
// GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetNpadIrCameraHandle(ServiceCtx context)
|
2019-04-20 01:56:55 +00:00
|
|
|
{
|
2020-04-03 00:10:02 +00:00
|
|
|
NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32();
|
2019-04-20 01:56:55 +00:00
|
|
|
|
2020-04-03 00:10:02 +00:00
|
|
|
if (npadIdType > NpadIdType.Player8 &&
|
|
|
|
npadIdType != NpadIdType.Unknown &&
|
|
|
|
npadIdType != NpadIdType.Handheld)
|
2019-04-20 01:56:55 +00:00
|
|
|
{
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.NpadIdOutOfRange;
|
2019-04-20 01:56:55 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 00:10:02 +00:00
|
|
|
PlayerIndex irCameraHandle = HidUtils.GetIndexFromNpadIdType(npadIdType);
|
2019-04-20 01:56:55 +00:00
|
|
|
|
2019-06-27 16:02:41 +00:00
|
|
|
context.ResponseData.Write((int)irCameraHandle);
|
2019-04-20 01:56:55 +00:00
|
|
|
|
2019-06-27 16:02:41 +00:00
|
|
|
// NOTE: If the irCameraHandle pointer is null this error is returned, Doesn't occur in our case.
|
2019-07-14 19:04:38 +00:00
|
|
|
// return ResultCode.HandlePointerIsNull;
|
2019-04-20 01:56:55 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2019-04-20 01:56:55 +00:00
|
|
|
}
|
|
|
|
|
2021-06-19 11:53:18 +00:00
|
|
|
[CommandHipc(314)] // 3.0.0+
|
|
|
|
// CheckFirmwareVersion(nn::irsensor::IrCameraHandle, nn::irsensor::PackedMcuVersion, nn::applet::AppletResourceUserId, pid)
|
|
|
|
public ResultCode CheckFirmwareVersion(ServiceCtx context)
|
|
|
|
{
|
|
|
|
int irCameraHandle = context.RequestData.ReadInt32();
|
|
|
|
short packedMcuVersionMajor = context.RequestData.ReadInt16();
|
|
|
|
short packedMcuVersionMinor = context.RequestData.ReadInt16();
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, irCameraHandle, packedMcuVersionMajor, packedMcuVersionMinor });
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
|
|
|
|
2021-04-13 22:01:24 +00:00
|
|
|
[CommandHipc(319)] // 4.0.0+
|
2019-04-25 13:03:00 +00:00
|
|
|
// ActivateIrsensorWithFunctionLevel(nn::applet::AppletResourceUserId, nn::irsensor::PackedFunctionLevel, pid)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode ActivateIrsensorWithFunctionLevel(ServiceCtx context)
|
2019-04-25 13:03:00 +00:00
|
|
|
{
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
|
|
|
long packedFunctionLevel = context.RequestData.ReadInt64();
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel });
|
2019-04-25 13:03:00 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2019-04-25 13:03:00 +00:00
|
|
|
}
|
2021-09-28 22:10:10 +00:00
|
|
|
|
|
|
|
private ResultCode CheckCameraHandle(IrCameraHandle irCameraHandle)
|
|
|
|
{
|
|
|
|
if (irCameraHandle.DeviceType == 1 || (PlayerIndex)irCameraHandle.PlayerNumber >= PlayerIndex.Unknown)
|
|
|
|
{
|
|
|
|
return ResultCode.InvalidCameraHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
}
|
2018-10-07 15:12:11 +00:00
|
|
|
}
|
|
|
|
}
|