Added animatrix control thanks to https://github.com/vddCore/Starlight

This commit is contained in:
seerge
2023-03-04 00:11:59 +01:00
parent e9fa181d4e
commit 43d2ed656a
14 changed files with 742 additions and 73 deletions

61
Communication/Packet.cs Normal file
View File

@@ -0,0 +1,61 @@
// Source thanks to https://github.com/vddCore/Starlight :)
using System.ComponentModel;
using HidSharp;
namespace Starlight.Communication
{
public abstract class Packet
{
private int _currentDataIndex = 1;
public byte[] Data { get; }
internal Packet(byte reportId, int packetLength, params byte[] data)
{
if (packetLength < 1)
{
throw new ArgumentOutOfRangeException(
nameof(packetLength),
"Packet length must be at least 1."
);
}
Data = new byte[packetLength];
Data[0] = reportId;
if (data.Length > 0)
{
if (_currentDataIndex >= Data.Length)
{
throw new ArgumentOutOfRangeException(
nameof(data),
"Your packet length does not allow for initial data to be appended."
);
}
AppendData(data);
}
}
public Packet AppendData(params byte[] data)
=> AppendData(out _, data);
public Packet AppendData(out int bytesWritten, params byte[] data)
{
bytesWritten = 0;
for (var i = 0;
i < data.Length && _currentDataIndex < Data.Length - 1;
i++, bytesWritten++, _currentDataIndex++)
{
if (_currentDataIndex > Data.Length - 1)
break;
Data[_currentDataIndex] = data[i];
}
return this;
}
}
}