2021-05-02 20:01:30 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.TouchScreen;
|
2020-04-03 00:10:02 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Hid
|
|
|
|
{
|
|
|
|
public class TouchDevice : BaseDevice
|
|
|
|
{
|
|
|
|
public TouchDevice(Switch device, bool active) : base(device, active) { }
|
|
|
|
|
|
|
|
public void Update(params TouchPoint[] points)
|
|
|
|
{
|
2021-05-02 20:01:30 +00:00
|
|
|
ref RingLifo<TouchScreenState> lifo = ref _device.Hid.SharedMemory.TouchScreen;
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
ref TouchScreenState previousEntry = ref lifo.GetCurrentEntryRef();
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
TouchScreenState newState = new TouchScreenState
|
2020-04-03 00:10:02 +00:00
|
|
|
{
|
2021-05-02 20:01:30 +00:00
|
|
|
SamplingNumber = previousEntry.SamplingNumber + 1
|
|
|
|
};
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
if (Active)
|
|
|
|
{
|
|
|
|
newState.TouchesCount = points.Length;
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
int pointsLength = Math.Min(points.Length, newState.Touches.Length);
|
2020-04-03 00:10:02 +00:00
|
|
|
|
2021-05-02 20:01:30 +00:00
|
|
|
for (int i = 0; i < pointsLength; ++i)
|
2020-04-03 00:10:02 +00:00
|
|
|
{
|
2021-05-02 20:01:30 +00:00
|
|
|
TouchPoint pi = points[i];
|
|
|
|
newState.Touches[i] = new TouchState
|
|
|
|
{
|
|
|
|
DeltaTime = newState.SamplingNumber,
|
|
|
|
X = pi.X,
|
|
|
|
Y = pi.Y,
|
|
|
|
FingerId = (uint)i,
|
|
|
|
DiameterX = pi.DiameterX,
|
|
|
|
DiameterY = pi.DiameterY,
|
|
|
|
RotationAngle = pi.Angle
|
|
|
|
};
|
|
|
|
}
|
2020-04-03 00:10:02 +00:00
|
|
|
}
|
2021-05-02 20:01:30 +00:00
|
|
|
|
|
|
|
lifo.Write(ref newState);
|
2020-04-03 00:10:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|