public void SetColors(byte channel, byte[] colorData)
{
int max_leds = 64;
byte reportId = 9;
//Automatically determine the correct report id to send the data to
if (colorData.Length <= 8 * 3)
{
max_leds = 8;
reportId = 6;
}
else if (colorData.Length <= 16 * 3)
{
max_leds = 16;
reportId = 7;
}
else if (colorData.Length <= 32 * 3)
{
max_leds = 32;
reportId = 8;
}
else if (colorData.Length <= 64 * 3)
{
max_leds = 64;
reportId = 9;
}
else if (colorData.Length <= 128 * 3)
{
max_leds = 64;
reportId = 10;
}
byte [] data = new byte[max_leds * 3 + 2];
data[0] = reportId;
data[1] = channel; // chanel index
for (int i = 0; i < Math.Min(colorData.Length, data.Length - 2); i++)
{
data[i + 2] = colorData[i];
}
for (int i = colorData.Length + 2; i < data.Length; i++)
{
data[i] = 0;
}
SetFeature(data);
if (reportId == 10)
{
for (int i = 0; i < Math.Min(data.Length - 2, colorData.Length - 64 * 3); i++)
{
data[i + 2] = colorData[64 * 3 + i];
}
for (int i = colorData.Length + 2 - 64 * 3; i < data.Length; i++)
{
data[i] = 0;
}
data[0] = (byte)(reportId + 1);
SetFeature(data);
}
}