mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Fixed wrong id fetch and added config methods to PpicoSDK
This commit is contained in:
parent
5e7ef211f7
commit
16aa017e77
@ -12,7 +12,7 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
public string Model { get; }
|
public string Model { get; }
|
||||||
public object? LayoutMetadata { get; set; }
|
public object? LayoutMetadata { get; set; }
|
||||||
|
|
||||||
public int Id { get; }
|
public string Id { get; }
|
||||||
public int Version { get; }
|
public int Version { get; }
|
||||||
public int Channel { get; }
|
public int Channel { get; }
|
||||||
public int LedCount { get; }
|
public int LedCount { get; }
|
||||||
@ -21,7 +21,7 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
internal PicoPiRGBDeviceInfo(RGBDeviceType deviceType, string model, int id, int version, int channel, int ledCount)
|
internal PicoPiRGBDeviceInfo(RGBDeviceType deviceType, string model, string id, int version, int channel, int ledCount)
|
||||||
{
|
{
|
||||||
this.DeviceType = deviceType;
|
this.DeviceType = deviceType;
|
||||||
this.Model = model;
|
this.Model = model;
|
||||||
|
|||||||
@ -5,6 +5,7 @@ using System.Linq;
|
|||||||
using HidSharp;
|
using HidSharp;
|
||||||
using LibUsbDotNet.LibUsb;
|
using LibUsbDotNet.LibUsb;
|
||||||
using LibUsbDotNet.Main;
|
using LibUsbDotNet.Main;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.PicoPi
|
namespace RGB.NET.Devices.PicoPi
|
||||||
{
|
{
|
||||||
@ -41,9 +42,9 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
|
|
||||||
public bool IsBulkSupported { get; private set; }
|
public bool IsBulkSupported { get; private set; }
|
||||||
|
|
||||||
public int Id { get; }
|
public string Id { get; }
|
||||||
public int Version { get; }
|
public int Version { get; }
|
||||||
public IReadOnlyList<(int channel, int ledCount)> Channels { get; }
|
public IReadOnlyList<(int channel, int ledCount, int pin)> Channels { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
|
|
||||||
Id = GetId();
|
Id = GetId();
|
||||||
Version = GetVersion();
|
Version = GetVersion();
|
||||||
Channels = new ReadOnlyCollection<(int channel, int ledCount)>(GetChannels().ToList());
|
Channels = new ReadOnlyCollection<(int channel, int ledCount, int pin)>(GetChannels().ToList());
|
||||||
|
|
||||||
_bulkSendBuffer = new byte[(Channels.Sum(c => c.ledCount + 1) * 3) + 5];
|
_bulkSendBuffer = new byte[(Channels.Sum(c => c.ledCount + 1) * 3) + 5];
|
||||||
}
|
}
|
||||||
@ -69,6 +70,32 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
|
|
||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
|
public void SetLedCounts(params (int channel, int ledCount)[] ledCounts)
|
||||||
|
{
|
||||||
|
byte[] data = new byte[Channels.Count + 2];
|
||||||
|
data[1] = COMMAND_LEDCOUNTS;
|
||||||
|
foreach ((int channel, int ledCount, _) in Channels)
|
||||||
|
data[channel + 1] = (byte)ledCount;
|
||||||
|
|
||||||
|
foreach ((int channel, int ledCount) in ledCounts)
|
||||||
|
data[channel + 1] = (byte)ledCount;
|
||||||
|
|
||||||
|
SendHID(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPins(params (int channel, int pin)[] pins)
|
||||||
|
{
|
||||||
|
byte[] data = new byte[Channels.Count + 2];
|
||||||
|
data[1] = COMMAND_PINS;
|
||||||
|
foreach ((int channel, _, int pin) in Channels)
|
||||||
|
data[channel + 1] = (byte)pin;
|
||||||
|
|
||||||
|
foreach ((int channel, int pin) in pins)
|
||||||
|
data[channel + 1] = (byte)pin;
|
||||||
|
|
||||||
|
SendHID(data);
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadBulkDevice()
|
private void LoadBulkDevice()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -108,10 +135,10 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetId()
|
private string GetId()
|
||||||
{
|
{
|
||||||
SendHID(0x00, COMMAND_ID);
|
SendHID(0x00, COMMAND_ID);
|
||||||
return Read()[1];
|
return ConversionHelper.ToHex(Read().Skip(1).Take(8).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetVersion()
|
private int GetVersion()
|
||||||
@ -120,7 +147,7 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
return Read()[1];
|
return Read()[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<(int channel, int ledCount)> GetChannels()
|
private IEnumerable<(int channel, int ledCount, int pin)> GetChannels()
|
||||||
{
|
{
|
||||||
SendHID(0x00, COMMAND_CHANNEL_COUNT);
|
SendHID(0x00, COMMAND_CHANNEL_COUNT);
|
||||||
int channelCount = Read()[1];
|
int channelCount = Read()[1];
|
||||||
@ -129,8 +156,11 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
{
|
{
|
||||||
SendHID(0x00, (byte)((i << 4) | COMMAND_LEDCOUNTS));
|
SendHID(0x00, (byte)((i << 4) | COMMAND_LEDCOUNTS));
|
||||||
int ledCount = Read()[1];
|
int ledCount = Read()[1];
|
||||||
if (ledCount > 0)
|
|
||||||
yield return (i, ledCount);
|
SendHID(0x00, (byte)((i << 4) | COMMAND_PINS));
|
||||||
|
int pin = Read()[1];
|
||||||
|
|
||||||
|
yield return (i, ledCount, pin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,8 +76,8 @@ namespace RGB.NET.Devices.PicoPi
|
|||||||
{
|
{
|
||||||
PicoPiSDK sdk = new(device);
|
PicoPiSDK sdk = new(device);
|
||||||
_sdks.Add(sdk);
|
_sdks.Add(sdk);
|
||||||
IDeviceUpdateTrigger updateTrigger = GetUpdateTrigger(sdk.Id);
|
IDeviceUpdateTrigger updateTrigger = GetUpdateTrigger(sdk.Id.GetHashCode());
|
||||||
foreach ((int channel, int ledCount) in sdk.Channels)
|
foreach ((int channel, int ledCount, _) in sdk.Channels.Where(c => c.ledCount > 0))
|
||||||
{
|
{
|
||||||
PicoPiRGBDevice picoPiDevice = new(new PicoPiRGBDeviceInfo(definition.DeviceType, definition.Name, sdk.Id, sdk.Version, channel, ledCount), GetUpdateQueue(updateTrigger, sdk, channel, ledCount), definition.LedMapping);
|
PicoPiRGBDevice picoPiDevice = new(new PicoPiRGBDeviceInfo(definition.DeviceType, definition.Name, sdk.Id, sdk.Version, channel, ledCount), GetUpdateQueue(updateTrigger, sdk, channel, ledCount), definition.LedMapping);
|
||||||
picoPiDevice.Initialize();
|
picoPiDevice.Initialize();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user