Copy Corsair Commander Pro updates to Lighting Node Pro driver. Need to consolidate these eventually

This commit is contained in:
Adam Honse 2020-01-17 22:26:02 -06:00
parent d13971b7ce
commit ab03311717
3 changed files with 521 additions and 179 deletions

View file

@ -69,171 +69,122 @@ CorsairNodeProController::~CorsairNodeProController()
{
}
void CorsairNodeProController::SendKeepalive()
{
unsigned char usb_apply[] =
{
0x33, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
int actual;
/*-----------------------------------------------------*\
| Send apply packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_apply, 64, &actual, 0);
}
void CorsairNodeProController::KeepaliveThread()
{
while(1)
{
SendKeepalive();
SendCommit();
Sleep(5000);
}
}
void CorsairNodeProController::SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors)
void CorsairNodeProController::SetChannelEffect(unsigned char channel,
unsigned char mode,
unsigned char speed,
unsigned char direction,
bool random,
unsigned char red1,
unsigned char grn1,
unsigned char blu1,
unsigned char red2,
unsigned char grn2,
unsigned char blu2
)
{
unsigned char usb_start[] =
{
0x38, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
unsigned char usb_data[] =
{
0x32, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
unsigned char usb_apply[] =
{
0x33, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
int actual;
/*-----------------------------------------------------*\
| Send Reset packet |
\*-----------------------------------------------------*/
SendReset(channel);
/*-----------------------------------------------------*\
| Set channel in USB packets |
| Send Begin packet |
\*-----------------------------------------------------*/
usb_data[0x01] = channel;
usb_start[0x01] = channel;
SendBegin(channel);
/*-----------------------------------------------------*\
| Send start packet |
| Set Port State packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_start, 64, &actual, 0);
SendPortState(channel, CORSAIR_CMDR_PRO_PORT_STATE_HARDWARE);
/*-----------------------------------------------------*\
| Set Effect Configuration packet |
\*-----------------------------------------------------*/
SendEffectConfig
(
channel,
0,
CORSAIR_CMDR_PRO_LED_TYPE_LED_STRIP,
mode,
speed,
direction,
random,
red1,
grn1,
blu1,
red2,
grn2,
blu2,
0,
0,
0,
0,
0,
0
);
/*-----------------------------------------------------*\
| Send Commit packet |
\*-----------------------------------------------------*/
SendCommit();
}
void CorsairNodeProController::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
{
unsigned char color_data[50];
unsigned char pkt_max;
/*-----------------------------------------------------*\
| Send Port State packet |
\*-----------------------------------------------------*/
SendPortState(channel, CORSAIR_CMDR_PRO_PORT_STATE_SOFTWARE);
/*-----------------------------------------------------*\
| Send red channel packet 1 |
\*-----------------------------------------------------*/
std::size_t pkt_max = 50;
pkt_max = 50;
if(pkt_max > colors.size())
{
pkt_max = colors.size();
pkt_max = (unsigned char)colors.size();
}
usb_data[0x02] = 0;
usb_data[0x03] = pkt_max;
usb_data[0x04] = 0x00; //red
for (std::size_t idx = 0; idx < pkt_max; idx++)
for(int idx = 0; idx < pkt_max; idx++)
{
RGBColor color = colors[idx];
usb_data[idx + 5] = RGBGetRValue(color);
color_data[idx] = RGBGetRValue(colors[idx]);
}
libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0);
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED, color_data);
/*-----------------------------------------------------*\
| Send red channel packet 2 if necessary |
\*-----------------------------------------------------*/
for(int idx = 4; idx < 64; idx++)
{
usb_data[idx] = 0;
}
pkt_max = 0;
pkt_max = 0;
if (colors.size() > 50)
{
pkt_max = colors.size() - 50;
pkt_max = (unsigned char)(colors.size() - 50);
}
if(pkt_max > 0)
{
usb_data[0x02] = 50;
usb_data[0x03] = pkt_max;
usb_data[0x04] = 0x00; //red
for (std::size_t idx = 0; idx < pkt_max; idx++)
{
RGBColor color = colors[idx + 50];
usb_data[idx + 5] = RGBGetRValue(color);
color_data[idx] = RGBGetRValue(colors[idx+50]);
}
libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0);
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_RED, color_data);
}
/*-----------------------------------------------------*\
| Send green channel packet 1 |
\*-----------------------------------------------------*/
@ -241,49 +192,34 @@ void CorsairNodeProController::SetChannelLEDs(unsigned int channel, std::vector<
if(pkt_max > colors.size())
{
pkt_max = colors.size();
pkt_max = (unsigned char)colors.size();
}
usb_data[0x02] = 0;
usb_data[0x03] = pkt_max;
usb_data[0x04] = 0x01; //green
for (std::size_t idx = 0; idx < pkt_max; idx++)
for(int idx = 0; idx < pkt_max; idx++)
{
RGBColor color = colors[idx];
usb_data[idx + 5] = RGBGetGValue(color);
color_data[idx] = RGBGetGValue(colors[idx]);
}
libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0);
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN, color_data);
/*-----------------------------------------------------*\
| Send green channel packet 2 if necessary |
\*-----------------------------------------------------*/
for(int idx = 4; idx < 64; idx++)
{
usb_data[idx] = 0;
}
pkt_max = 0;
pkt_max = 0;
if (colors.size() > 50)
{
pkt_max = colors.size() - 50;
pkt_max = (unsigned char)(colors.size() - 50);
}
if(pkt_max > 0)
{
usb_data[0x02] = 50;
usb_data[0x03] = pkt_max;
usb_data[0x04] = 0x01; //green
for (std::size_t idx = 0; idx < pkt_max; idx++)
{
RGBColor color = colors[idx + 50];
usb_data[idx + 5] = RGBGetGValue(color);
color_data[idx] = RGBGetGValue(colors[idx+50]);
}
libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0);
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_GREEN, color_data);
}
/*-----------------------------------------------------*\
@ -293,53 +229,275 @@ void CorsairNodeProController::SetChannelLEDs(unsigned int channel, std::vector<
if(pkt_max > colors.size())
{
pkt_max = colors.size();
pkt_max = (unsigned char)colors.size();
}
usb_data[0x02] = 0;
usb_data[0x03] = pkt_max;
usb_data[0x04] = 0x02; //blue
for (std::size_t idx = 0; idx < pkt_max; idx++)
for(int idx = 0; idx < pkt_max; idx++)
{
RGBColor color = colors[idx];
usb_data[idx + 5] = RGBGetBValue(color);
color_data[idx] = RGBGetBValue(colors[idx]);
}
libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0);
SendDirect(channel, 0, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE, color_data);
/*-----------------------------------------------------*\
| Send blue channel packet 2 if necessary |
\*-----------------------------------------------------*/
for(int idx = 4; idx < 64; idx++)
{
usb_data[idx] = 0;
}
pkt_max = 0;
pkt_max = 0;
if (colors.size() > 50)
{
pkt_max = colors.size() - 50;
pkt_max = (unsigned char)(colors.size() - 50);
}
if(pkt_max > 0)
{
usb_data[0x02] = 50;
usb_data[0x03] = pkt_max;
usb_data[0x04] = 0x02; //blue
for (std::size_t idx = 0; idx < pkt_max; idx++)
{
RGBColor color = colors[idx + 50];
usb_data[idx + 5] = RGBGetBValue(color);
color_data[idx] = RGBGetBValue(colors[idx+50]);
}
libusb_interrupt_transfer(dev, 0x01, usb_data, 64, &actual, 0);
SendDirect(channel, 50, pkt_max, CORSAIR_CMDR_PRO_DIRECT_CHANNEL_BLUE, color_data);
}
/*-----------------------------------------------------*\
| Send apply packet |
| Send Commit packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_apply, 64, &actual, 0);
SendCommit();
}
/*-------------------------------------------------------------------------------------------------*\
| Private packet sending functions. |
\*-------------------------------------------------------------------------------------------------*/
void CorsairNodeProController::SendDirect
(
unsigned char channel,
unsigned char start,
unsigned char count,
unsigned char color_channel,
unsigned char* color_data
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Direct packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_DIRECT;
usb_buf[0x01] = channel;
usb_buf[0x02] = start;
usb_buf[0x03] = count;
usb_buf[0x04] = color_channel;
/*-----------------------------------------------------*\
| Copy in color data bytes |
\*-----------------------------------------------------*/
memcpy(&usb_buf[0x05], color_data, count);
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
}
void CorsairNodeProController::SendCommit()
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Commit packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_COMMIT;
usb_buf[0x01] = 0xFF;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
}
void CorsairNodeProController::SendBegin
(
unsigned char channel
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Begin packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_BEGIN;
usb_buf[0x01] = channel;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
}
void CorsairNodeProController::SendEffectConfig
(
unsigned char channel,
unsigned char count,
unsigned char led_type,
unsigned char mode,
unsigned char speed,
unsigned char direction,
unsigned char change_style,
unsigned char color_0_red,
unsigned char color_0_green,
unsigned char color_0_blue,
unsigned char color_1_red,
unsigned char color_1_green,
unsigned char color_1_blue,
unsigned char color_2_red,
unsigned char color_2_green,
unsigned char color_2_blue,
unsigned short temperature_0,
unsigned short temperature_1,
unsigned short temperature_2
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Effect Config packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_EFFECT_CONFIG;
usb_buf[0x01] = channel;
usb_buf[0x02] = count * 10;
usb_buf[0x03] = led_type;
/*-----------------------------------------------------*\
| Set up mode parameters |
\*-----------------------------------------------------*/
usb_buf[0x04] = mode;
usb_buf[0x05] = speed;
usb_buf[0x06] = direction;
usb_buf[0x07] = change_style;
usb_buf[0x08] = 0;
/*-----------------------------------------------------*\
| Set up mode colors |
\*-----------------------------------------------------*/
usb_buf[0x09] = color_0_red;
usb_buf[0x10] = color_0_green;
usb_buf[0x11] = color_0_blue;
usb_buf[0x12] = color_1_red;
usb_buf[0x13] = color_1_green;
usb_buf[0x14] = color_1_blue;
usb_buf[0x15] = color_2_red;
usb_buf[0x16] = color_2_green;
usb_buf[0x17] = color_2_blue;
/*-----------------------------------------------------*\
| Set up temperatures |
\*-----------------------------------------------------*/
usb_buf[0x12] = (temperature_0 >> 8);
usb_buf[0x13] = (temperature_0 & 0xFF);
usb_buf[0x14] = (temperature_1 >> 8);
usb_buf[0x15] = (temperature_1 & 0xFF);
usb_buf[0x16] = (temperature_2 >> 8);
usb_buf[0x17] = (temperature_2 & 0xFF);
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
}
void CorsairNodeProController::SendTemperature()
{
}
void CorsairNodeProController::SendReset
(
unsigned char channel
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Reset packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_RESET;
usb_buf[0x01] = channel;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
}
void CorsairNodeProController::SendPortState
(
unsigned char channel,
unsigned char state
)
{
int actual;
unsigned char usb_buf[64];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Port State packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = CORSAIR_CMDR_PRO_PACKET_ID_PORT_STATE;
usb_buf[0x01] = channel;
usb_buf[0x02] = state;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
}
void CorsairNodeProController::SendBrightness()
{
}
void CorsairNodeProController::SendLEDCount()
{
}
void CorsairNodeProController::SendProtocol()
{
}