mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-03-24 15:58:45 +00:00
Compare commits
No commits in common. "1a3ad689d8fb7b9b1663da8cab0a3daeee7ca519" and "3e53e5711fdd4f4009beed0f9f8b8c0e38c44f46" have entirely different histories.
1a3ad689d8
...
3e53e5711f
@ -9,6 +9,12 @@ namespace RGB.NET.Devices.PicoPi;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class PicoPiHIDUpdateQueue : UpdateQueue
|
public class PicoPiHIDUpdateQueue : UpdateQueue
|
||||||
{
|
{
|
||||||
|
#region Constants
|
||||||
|
|
||||||
|
private const int OFFSET_MULTIPLIER = 60;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly PicoPiSDK _sdk;
|
private readonly PicoPiSDK _sdk;
|
||||||
@ -56,7 +62,15 @@ public class PicoPiHIDUpdateQueue : UpdateQueue
|
|||||||
buffer[offset + 2] = b;
|
buffer[offset + 2] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
_sdk.SendHidUpdate(buffer, _channel);
|
int chunks = _dataBuffer.Length / OFFSET_MULTIPLIER;
|
||||||
|
if ((chunks * OFFSET_MULTIPLIER) < buffer.Length) chunks++;
|
||||||
|
for (int i = 0; i < chunks; i++)
|
||||||
|
{
|
||||||
|
int offset = i * OFFSET_MULTIPLIER;
|
||||||
|
int length = Math.Min(buffer.Length - offset, OFFSET_MULTIPLIER);
|
||||||
|
bool update = i == (chunks - 1);
|
||||||
|
_sdk.SendHidUpdate(buffer.Slice(offset, length), _channel, i, update);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -37,8 +36,6 @@ public class PicoPiSDK : IDisposable
|
|||||||
private const byte COMMAND_UPDATE = 0x01;
|
private const byte COMMAND_UPDATE = 0x01;
|
||||||
private const byte COMMAND_UPDATE_BULK = 0x02;
|
private const byte COMMAND_UPDATE_BULK = 0x02;
|
||||||
|
|
||||||
public const int HID_OFFSET_MULTIPLIER = 60;
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
@ -207,24 +204,6 @@ public class PicoPiSDK : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sends a update to the device using the HID-endpoint and fragments the data if needed.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="data">The data to send.</param>
|
|
||||||
/// <param name="channel">The channel to update.</param>
|
|
||||||
public void SendHidUpdate(in Span<byte> buffer, int channel)
|
|
||||||
{
|
|
||||||
int chunks = buffer.Length / HID_OFFSET_MULTIPLIER;
|
|
||||||
if ((chunks * HID_OFFSET_MULTIPLIER) < buffer.Length) chunks++;
|
|
||||||
for (int i = 0; i < chunks; i++)
|
|
||||||
{
|
|
||||||
int offset = i * HID_OFFSET_MULTIPLIER;
|
|
||||||
int length = Math.Min(buffer.Length - offset, HID_OFFSET_MULTIPLIER);
|
|
||||||
bool update = i == (chunks - 1);
|
|
||||||
SendHidUpdate(buffer.Slice(offset, length), channel, i, update);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends a update to the device using the HID-endpoint.
|
/// Sends a update to the device using the HID-endpoint.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -281,15 +260,6 @@ public class PicoPiSDK : IDisposable
|
|||||||
_bulkTransferLength = 0;
|
_bulkTransferLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Resets all leds to black.
|
|
||||||
/// </summary>
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
foreach ((int channel, int ledCount, _) in Channels)
|
|
||||||
SendHidUpdate(new byte[ledCount * 3], channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendHID(params byte[] data) => _hidStream.Write(data);
|
private void SendHID(params byte[] data) => _hidStream.Write(data);
|
||||||
private void SendBulk(byte[] data, int count) => _bulkWriter!.Write(data, 0, count, 1000, out int _);
|
private void SendBulk(byte[] data, int count) => _bulkWriter!.Write(data, 0, count, 1000, out int _);
|
||||||
|
|
||||||
@ -298,8 +268,6 @@ public class PicoPiSDK : IDisposable
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Reset();
|
|
||||||
|
|
||||||
_hidStream.Dispose();
|
_hidStream.Dispose();
|
||||||
_bulkDevice?.Dispose();
|
_bulkDevice?.Dispose();
|
||||||
_usbContext?.Dispose();
|
_usbContext?.Dispose();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user