diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs index 2a43d14..5cd1a8e 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.PicoPi public string Model { get; } public object? LayoutMetadata { get; set; } - public int Id { get; } + public string Id { get; } public int Version { get; } public int Channel { get; } public int LedCount { get; } @@ -21,7 +21,7 @@ namespace RGB.NET.Devices.PicoPi #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.Model = model; diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs index bc4a88b..8c61776 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs @@ -5,6 +5,7 @@ using System.Linq; using HidSharp; using LibUsbDotNet.LibUsb; using LibUsbDotNet.Main; +using RGB.NET.Core; namespace RGB.NET.Devices.PicoPi { @@ -41,9 +42,9 @@ namespace RGB.NET.Devices.PicoPi public bool IsBulkSupported { get; private set; } - public int Id { get; } + public string Id { get; } public int Version { get; } - public IReadOnlyList<(int channel, int ledCount)> Channels { get; } + public IReadOnlyList<(int channel, int ledCount, int pin)> Channels { get; } #endregion @@ -60,7 +61,7 @@ namespace RGB.NET.Devices.PicoPi Id = GetId(); 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]; } @@ -69,6 +70,32 @@ namespace RGB.NET.Devices.PicoPi #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() { try @@ -108,10 +135,10 @@ namespace RGB.NET.Devices.PicoPi } } - private int GetId() + private string GetId() { SendHID(0x00, COMMAND_ID); - return Read()[1]; + return ConversionHelper.ToHex(Read().Skip(1).Take(8).ToArray()); } private int GetVersion() @@ -120,7 +147,7 @@ namespace RGB.NET.Devices.PicoPi return Read()[1]; } - private IEnumerable<(int channel, int ledCount)> GetChannels() + private IEnumerable<(int channel, int ledCount, int pin)> GetChannels() { SendHID(0x00, COMMAND_CHANNEL_COUNT); int channelCount = Read()[1]; @@ -129,8 +156,11 @@ namespace RGB.NET.Devices.PicoPi { SendHID(0x00, (byte)((i << 4) | COMMAND_LEDCOUNTS)); 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); } } diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index c153965..c444a23 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -76,8 +76,8 @@ namespace RGB.NET.Devices.PicoPi { PicoPiSDK sdk = new(device); _sdks.Add(sdk); - IDeviceUpdateTrigger updateTrigger = GetUpdateTrigger(sdk.Id); - foreach ((int channel, int ledCount) in sdk.Channels) + IDeviceUpdateTrigger updateTrigger = GetUpdateTrigger(sdk.Id.GetHashCode()); + 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); picoPiDevice.Initialize();