IIrSensorServer.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.Kernel.Common;
  4. using Ryujinx.HLE.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace Ryujinx.HLE.HOS.Services.Hid.Irs
  8. {
  9. class IIrSensorServer : IpcService
  10. {
  11. private int _irsensorSharedMemoryHandle = 0;
  12. private Dictionary<int, ServiceProcessRequest> _commands;
  13. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  14. public IIrSensorServer()
  15. {
  16. _commands = new Dictionary<int, ServiceProcessRequest>
  17. {
  18. { 302, ActivateIrsensor },
  19. { 303, DeactivateIrsensor },
  20. { 304, GetIrsensorSharedMemoryHandle },
  21. //{ 305, StopImageProcessor },
  22. //{ 306, RunMomentProcessor },
  23. //{ 307, RunClusteringProcessor },
  24. //{ 308, RunImageTransferProcessor },
  25. //{ 309, GetImageTransferProcessorState },
  26. //{ 310, RunTeraPluginProcessor },
  27. { 311, GetNpadIrCameraHandle },
  28. //{ 312, RunPointingProcessor },
  29. //{ 313, SuspendImageProcessor },
  30. //{ 314, CheckFirmwareVersion }, // 3.0.0+
  31. //{ 315, SetFunctionLevel }, // 4.0.0+
  32. //{ 316, RunImageTransferExProcessor }, // 4.0.0+
  33. //{ 317, RunIrLedProcessor }, // 4.0.0+
  34. //{ 318, StopImageProcessorAsync }, // 4.0.0+
  35. { 319, ActivateIrsensorWithFunctionLevel }, // 4.0.0+
  36. };
  37. }
  38. // ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
  39. public long ActivateIrsensor(ServiceCtx context)
  40. {
  41. long appletResourceUserId = context.RequestData.ReadInt64();
  42. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  43. return 0;
  44. }
  45. // DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
  46. public long DeactivateIrsensor(ServiceCtx context)
  47. {
  48. long appletResourceUserId = context.RequestData.ReadInt64();
  49. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
  50. return 0;
  51. }
  52. // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
  53. public long GetIrsensorSharedMemoryHandle(ServiceCtx context)
  54. {
  55. if (_irsensorSharedMemoryHandle == 0)
  56. {
  57. if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != KernelResult.Success)
  58. {
  59. throw new InvalidOperationException("Out of handles!");
  60. }
  61. }
  62. context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_irsensorSharedMemoryHandle);
  63. return 0;
  64. }
  65. // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
  66. public long GetNpadIrCameraHandle(ServiceCtx context)
  67. {
  68. NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32();
  69. if (npadIdType > NpadIdType.Player8 &&
  70. npadIdType != NpadIdType.Unknown &&
  71. npadIdType != NpadIdType.Handheld)
  72. {
  73. return ErrorCode.MakeError(ErrorModule.Irsensor, IrsError.NpadIdOutOfRange);
  74. }
  75. HidControllerId irCameraHandle = HidUtils.GetIndexFromNpadIdType(npadIdType);
  76. context.ResponseData.Write((int)irCameraHandle);
  77. // NOTE: If the irCameraHandle pointer is null this error is returned, Doesn't occur in our case.
  78. // return ErrorCode.MakeError(ErrorModule.Irsensor, IrsError.HandlePointerIsNull);
  79. return 0;
  80. }
  81. // ActivateIrsensorWithFunctionLevel(nn::applet::AppletResourceUserId, nn::irsensor::PackedFunctionLevel, pid)
  82. public long ActivateIrsensorWithFunctionLevel(ServiceCtx context)
  83. {
  84. long appletResourceUserId = context.RequestData.ReadInt64();
  85. long packedFunctionLevel = context.RequestData.ReadInt64();
  86. Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId, packedFunctionLevel });
  87. return 0;
  88. }
  89. }
  90. }