2018-10-17 13:15:50 -04:00
|
|
|
|
using Ryujinx.Common.Logging;
|
2019-04-19 21:56:55 -04:00
|
|
|
|
using Ryujinx.HLE.Exceptions;
|
2018-10-17 13:15:50 -04:00
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2019-04-19 22:23:13 -04:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
2019-04-19 21:56:55 -04:00
|
|
|
|
using System;
|
2018-10-07 11:12:11 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Irs
|
|
|
|
|
{
|
|
|
|
|
class IIrSensorServer : IpcService
|
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
2019-04-19 22:23:13 -04:00
|
|
|
|
private KSharedMemory _irsSharedMem;
|
|
|
|
|
|
|
|
|
|
public IIrSensorServer(KSharedMemory irsSharedMem)
|
2018-10-07 11:12:11 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-10-07 11:12:11 -04:00
|
|
|
|
{
|
2019-04-25 09:03:00 -04:00
|
|
|
|
{ 302, ActivateIrsensor },
|
|
|
|
|
{ 303, DeactivateIrsensor },
|
|
|
|
|
{ 304, GetIrsensorSharedMemoryHandle },
|
|
|
|
|
{ 311, GetNpadIrCameraHandle },
|
|
|
|
|
{ 319, ActivateIrsensorWithFunctionLevel }
|
2018-10-07 11:12:11 -04:00
|
|
|
|
};
|
2019-04-19 22:23:13 -04:00
|
|
|
|
|
|
|
|
|
_irsSharedMem = irsSharedMem;
|
2018-10-07 11:12:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long ActivateIrsensor(ServiceCtx context)
|
2018-10-07 11:12:11 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
2019-01-10 19:11:46 -05:00
|
|
|
|
Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public long DeactivateIrsensor(ServiceCtx context)
|
2018-10-07 11:12:11 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
2019-01-10 19:11:46 -05:00
|
|
|
|
Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-04-19 21:56:55 -04:00
|
|
|
|
|
2019-04-19 22:23:13 -04:00
|
|
|
|
// GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
|
|
|
|
|
public long GetIrsensorSharedMemoryHandle(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
var handleTable = context.Process.HandleTable;
|
|
|
|
|
|
|
|
|
|
if (handleTable.GenerateHandle(_irsSharedMem, out int handle) != KernelResult.Success)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Out of handles!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context.Response.HandleDesc = IpcHandleDesc.MakeCopy(handle);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 21:56:55 -04:00
|
|
|
|
// GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
|
|
|
|
|
public long GetNpadIrCameraHandle(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
uint npadId = context.RequestData.ReadUInt32();
|
|
|
|
|
|
|
|
|
|
if (npadId >= 8 && npadId != 16 && npadId != 32)
|
|
|
|
|
{
|
|
|
|
|
return ErrorCode.MakeError(ErrorModule.Hid, 0x2c5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (((1 << (int)npadId) & 0x1000100FF) == 0)
|
|
|
|
|
{
|
|
|
|
|
return ErrorCode.MakeError(ErrorModule.Hid, 0x2c5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int npadTypeId = GetNpadTypeId(npadId);
|
|
|
|
|
|
|
|
|
|
context.ResponseData.Write(npadTypeId);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetNpadTypeId(uint npadId)
|
|
|
|
|
{
|
|
|
|
|
switch(npadId)
|
|
|
|
|
{
|
|
|
|
|
case 0: return 0;
|
|
|
|
|
case 1: return 1;
|
|
|
|
|
case 2: return 2;
|
|
|
|
|
case 3: return 3;
|
|
|
|
|
case 4: return 4;
|
|
|
|
|
case 5: return 5;
|
|
|
|
|
case 6: return 6;
|
|
|
|
|
case 7: return 7;
|
|
|
|
|
case 32: return 8;
|
|
|
|
|
case 16: return 9;
|
|
|
|
|
default: throw new ArgumentOutOfRangeException(nameof(npadId));
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-25 09:03:00 -04:00
|
|
|
|
|
|
|
|
|
// ActivateIrsensorWithFunctionLevel(nn::applet::AppletResourceUserId, nn::irsensor::PackedFunctionLevel, pid)
|
|
|
|
|
public long ActivateIrsensorWithFunctionLevel(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
|
|
|
|
long packedFunctionLevel = context.RequestData.ReadInt64();
|
|
|
|
|
|
|
|
|
|
Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel });
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-10-07 11:12:11 -04:00
|
|
|
|
}
|
|
|
|
|
}
|