aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Hid
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2019-06-27 18:02:41 +0200
committerThomas Guillemard <me@thog.eu>2019-06-27 18:02:41 +0200
commita8965aad970549b3fca87520616674aa3600a9dd (patch)
treedd05ec75127076d7ce4dae45aa4fa49b4b3c5cc7 /Ryujinx.HLE/HOS/Services/Hid
parent36f62cbe72d16c94f0c87fa1712ffff314ab080a (diff)
irs: Little service cleanup (#712)
* irs: Little service cleanup * more cleanup * Fix nit * Fix condition
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Hid')
-rw-r--r--Ryujinx.HLE/HOS/Services/Hid/HidUtils.cs27
-rw-r--r--Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs112
-rw-r--r--Ryujinx.HLE/HOS/Services/Hid/Irs/IrsError.cs8
-rw-r--r--Ryujinx.HLE/HOS/Services/Hid/NpadIdType.cs16
4 files changed, 163 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Hid/HidUtils.cs b/Ryujinx.HLE/HOS/Services/Hid/HidUtils.cs
new file mode 100644
index 00000000..64252ce8
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Hid/HidUtils.cs
@@ -0,0 +1,27 @@
+using Ryujinx.HLE.Input;
+using System;
+
+namespace Ryujinx.HLE.HOS.Services.Hid
+{
+ static class HidUtils
+ {
+ public static HidControllerId GetIndexFromNpadIdType(NpadIdType npadIdType)
+ {
+ switch (npadIdType)
+ {
+ case NpadIdType.Player1: return HidControllerId.ControllerPlayer1;
+ case NpadIdType.Player2: return HidControllerId.ControllerPlayer2;
+ case NpadIdType.Player3: return HidControllerId.ControllerPlayer3;
+ case NpadIdType.Player4: return HidControllerId.ControllerPlayer4;
+ case NpadIdType.Player5: return HidControllerId.ControllerPlayer5;
+ case NpadIdType.Player6: return HidControllerId.ControllerPlayer6;
+ case NpadIdType.Player7: return HidControllerId.ControllerPlayer7;
+ case NpadIdType.Player8: return HidControllerId.ControllerPlayer8;
+ case NpadIdType.Handheld: return HidControllerId.ControllerHandheld;
+ case NpadIdType.Unknown: return HidControllerId.ControllerUnknown;
+
+ default: throw new ArgumentOutOfRangeException(nameof(npadIdType));
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs b/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs
new file mode 100644
index 00000000..da1fbc18
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Hid/Irs/IIrSensorServer.cs
@@ -0,0 +1,112 @@
+using Ryujinx.Common.Logging;
+using Ryujinx.HLE.HOS.Ipc;
+using Ryujinx.HLE.HOS.Kernel.Common;
+using Ryujinx.HLE.Input;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.HLE.HOS.Services.Hid.Irs
+{
+ class IIrSensorServer : IpcService
+ {
+ private int _irsensorSharedMemoryHandle = 0;
+
+ private Dictionary<int, ServiceProcessRequest> _commands;
+
+ public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
+
+ public IIrSensorServer()
+ {
+ _commands = new Dictionary<int, ServiceProcessRequest>
+ {
+ { 302, ActivateIrsensor },
+ { 303, DeactivateIrsensor },
+ { 304, GetIrsensorSharedMemoryHandle },
+ //{ 305, StopImageProcessor },
+ //{ 306, RunMomentProcessor },
+ //{ 307, RunClusteringProcessor },
+ //{ 308, RunImageTransferProcessor },
+ //{ 309, GetImageTransferProcessorState },
+ //{ 310, RunTeraPluginProcessor },
+ { 311, GetNpadIrCameraHandle },
+ //{ 312, RunPointingProcessor },
+ //{ 313, SuspendImageProcessor },
+ //{ 314, CheckFirmwareVersion }, // 3.0.0+
+ //{ 315, SetFunctionLevel }, // 4.0.0+
+ //{ 316, RunImageTransferExProcessor }, // 4.0.0+
+ //{ 317, RunIrLedProcessor }, // 4.0.0+
+ //{ 318, StopImageProcessorAsync }, // 4.0.0+
+ { 319, ActivateIrsensorWithFunctionLevel }, // 4.0.0+
+ };
+ }
+
+ // ActivateIrsensor(nn::applet::AppletResourceUserId, pid)
+ public long ActivateIrsensor(ServiceCtx context)
+ {
+ long appletResourceUserId = context.RequestData.ReadInt64();
+
+ Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
+
+ return 0;
+ }
+
+ // DeactivateIrsensor(nn::applet::AppletResourceUserId, pid)
+ public long DeactivateIrsensor(ServiceCtx context)
+ {
+ long appletResourceUserId = context.RequestData.ReadInt64();
+
+ Logger.PrintStub(LogClass.ServiceIrs, new { appletResourceUserId });
+
+ return 0;
+ }
+
+ // GetIrsensorSharedMemoryHandle(nn::applet::AppletResourceUserId, pid) -> handle<copy>
+ public long GetIrsensorSharedMemoryHandle(ServiceCtx context)
+ {
+ if (_irsensorSharedMemoryHandle == 0)
+ {
+ if (context.Process.HandleTable.GenerateHandle(context.Device.System.IirsSharedMem, out _irsensorSharedMemoryHandle) != KernelResult.Success)
+ {
+ throw new InvalidOperationException("Out of handles!");
+ }
+ }
+
+ context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_irsensorSharedMemoryHandle);
+
+ return 0;
+ }
+
+ // GetNpadIrCameraHandle(u32) -> nn::irsensor::IrCameraHandle
+ public long GetNpadIrCameraHandle(ServiceCtx context)
+ {
+ NpadIdType npadIdType = (NpadIdType)context.RequestData.ReadUInt32();
+
+ if (npadIdType > NpadIdType.Player8 &&
+ npadIdType != NpadIdType.Unknown &&
+ npadIdType != NpadIdType.Handheld)
+ {
+ return ErrorCode.MakeError(ErrorModule.Irsensor, IrsError.NpadIdOutOfRange);
+ }
+
+ HidControllerId irCameraHandle = HidUtils.GetIndexFromNpadIdType(npadIdType);
+
+ context.ResponseData.Write((int)irCameraHandle);
+
+ // NOTE: If the irCameraHandle pointer is null this error is returned, Doesn't occur in our case.
+ // return ErrorCode.MakeError(ErrorModule.Irsensor, IrsError.HandlePointerIsNull);
+
+ return 0;
+ }
+
+ // 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;
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Hid/Irs/IrsError.cs b/Ryujinx.HLE/HOS/Services/Hid/Irs/IrsError.cs
new file mode 100644
index 00000000..fca38507
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Hid/Irs/IrsError.cs
@@ -0,0 +1,8 @@
+namespace Ryujinx.HLE.HOS.Services.Hid.Irs
+{
+ static class IrsError
+ {
+ public const int HandlePointerIsNull = 212;
+ public const int NpadIdOutOfRange = 709;
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Hid/NpadIdType.cs b/Ryujinx.HLE/HOS/Services/Hid/NpadIdType.cs
new file mode 100644
index 00000000..5f6a68cb
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Hid/NpadIdType.cs
@@ -0,0 +1,16 @@
+namespace Ryujinx.HLE.HOS.Services.Hid
+{
+ public enum NpadIdType
+ {
+ Player1 = 0,
+ Player2 = 1,
+ Player3 = 2,
+ Player4 = 3,
+ Player5 = 4,
+ Player6 = 5,
+ Player7 = 6,
+ Player8 = 7,
+ Unknown = 16,
+ Handheld = 32
+ }
+} \ No newline at end of file