IIrSensorServer.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.HOS.Services.Hid.HidServer;
  5. using System;
  6. namespace Ryujinx.HLE.HOS.Services.Hid.Irs
  7. {
  8. [Service("irs")]
  9. class IIrSensorServer : IpcService
  10. {
  11. private int _irsensorSharedMemoryHandle = 0;
  12. public IIrSensorServer(ServiceCtx context) { }
  13. [Command(302)]
  14. // ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
  15. public ResultCode ActivateIrsensor(ServiceCtx context)
  16. {
  17. long appletResourceUserId = context.RequestData.ReadInt64();
  18. Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  19. return ResultCode.Success;
  20. }
  21. [Command(303)]
  22. // DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
  23. public ResultCode DeactivateIrsensor(ServiceCtx context)
  24. {
  25. long appletResourceUserId = context.RequestData.ReadInt64();
  26. Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  27. return ResultCode.Success;
  28. }
  29. [Command(304)]
  30. // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
  31. public ResultCode GetIrsensorSharedMemoryHandle(ServiceCtx context)
  32. {
  33. if (_irsensorSharedMemoryHandle == 0)
  34. {
  35. if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != KernelResult.Success)
  36. {
  37. throw new InvalidOperationException("Out of handles!");
  38. }
  39. }
  40. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_irsensorSharedMemoryHandle);
  41. return ResultCode.Success;
  42. }
  43. [Command(311)]
  44. // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
  45. public ResultCode GetNpadIrCameraHandle(ServiceCtx context)
  46. {
  47. NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32();
  48. if (npadIdType > NpadIdType.Player8 &&
  49. npadIdType != NpadIdType.Unknown &&
  50. npadIdType != NpadIdType.Handheld)
  51. {
  52. return ResultCode.NpadIdOutOfRange;
  53. }
  54. PlayerIndex irCameraHandle = HidUtils.GetIndexFromNpadIdType(npadIdType);
  55. context.ResponseData.Write((int)irCameraHandle);
  56. // NOTE: If the irCameraHandle pointer is null this error is returned, Doesn't occur in our case.
  57. // return ResultCode.HandlePointerIsNull;
  58. return ResultCode.Success;
  59. }
  60. [Command(319)] // 4.0.0+
  61. // ActivateIrsensorWithFunctionLevel(nn::applet::AppletResourceUserId, nn::irsensor::PackedFunctionLevel, pid)
  62. public ResultCode ActivateIrsensorWithFunctionLevel(ServiceCtx context)
  63. {
  64. long appletResourceUserId = context.RequestData.ReadInt64();
  65. long packedFunctionLevel = context.RequestData.ReadInt64();
  66. Logger.Stub?.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel });
  67. return ResultCode.Success;
  68. }
  69. }
  70. }