Updated CM ARGB Controller to v0023 protocol
* All RGB Modes are working * All ARGB Modes are working sans Direct * Direct Mode left available so zones are resizable Commits squashed and amended for code style by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
1cd0269f60
commit
e46325cbea
4 changed files with 298 additions and 187 deletions
|
|
@ -18,12 +18,6 @@ static unsigned char argb_colour_index_data[2][2][2] =
|
|||
{ 0x04, 0x07 }, } //G1 R1
|
||||
};
|
||||
|
||||
static unsigned char argb_mode_data[2][9] =
|
||||
{
|
||||
{ 0x05, 0x01, 0x02, 0x03, 0x04, 0x01, 0x01, 0x01, 0x01 }, //12v RGB Mode values
|
||||
{ 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09 } //5v ARGB Mode values
|
||||
};
|
||||
|
||||
CMARGBController::CMARGBController(hid_device* dev_handle, char *_path, unsigned char _zone_idx)
|
||||
{
|
||||
const int szTemp = 256;
|
||||
|
|
@ -32,7 +26,6 @@ CMARGBController::CMARGBController(hid_device* dev_handle, char *_path, unsigned
|
|||
dev = dev_handle;
|
||||
location = _path;
|
||||
zone_index = _zone_idx;
|
||||
current_speed = CM_ARGB_SPEED_NORMAL;
|
||||
|
||||
hid_get_manufacturer_string(dev, tmpName, szTemp);
|
||||
std::wstring wName = std::wstring(tmpName);
|
||||
|
|
@ -56,28 +49,37 @@ CMARGBController::~CMARGBController()
|
|||
|
||||
void CMARGBController::GetStatus()
|
||||
{
|
||||
unsigned char buffer[0x40] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
int header = zone_index - 1;
|
||||
unsigned char buffer[CM_ARGB_PACKET_SIZE] = { 0x00, 0x80, 0x0B, 0x01 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
int rgb_offset = 0;
|
||||
int zone;
|
||||
|
||||
/*buffer[CM_ARGB_REPORT_BYTE] = 0x80;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x01;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = 0x01;
|
||||
if (argb_header_data[zone_index].digital)
|
||||
{
|
||||
zone = argb_header_data[zone_index].header;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x0B;
|
||||
}
|
||||
else
|
||||
{
|
||||
zone = 0x00;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x0A;
|
||||
rgb_offset = 1;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| If this is the group then just return the first status |
|
||||
\*---------------------------------------------------------*/
|
||||
buffer[CM_ARGB_ZONE_BYTE] = ( zone > 0x08 ) ? 0x01 : zone;
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x0b;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = 0x03;
|
||||
buffer[CM_ARGB_ZONE_BYTE] = 0xFF;
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
|
||||
int i = 0;
|
||||
do{
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
i++;
|
||||
}while( (i < 4) );
|
||||
|
||||
current_mode = argb_mode_data[1][buffer[4]];
|
||||
current_speed = buffer[5];*/
|
||||
current_mode = buffer[4 - rgb_offset];
|
||||
bool_random = ( buffer[5 - rgb_offset] == 0x00 );
|
||||
current_speed = buffer[6 - rgb_offset];
|
||||
current_brightness = buffer[7 - rgb_offset];
|
||||
current_red = buffer[8 - rgb_offset];
|
||||
current_green = buffer[9 - rgb_offset];
|
||||
current_blue = buffer[10 - rgb_offset];
|
||||
}
|
||||
|
||||
std::string CMARGBController::GetDeviceName()
|
||||
|
|
@ -125,6 +127,11 @@ unsigned char CMARGBController::GetLedSpeed()
|
|||
return current_speed;
|
||||
}
|
||||
|
||||
bool CMARGBController::GetRandomColours()
|
||||
{
|
||||
return bool_random;
|
||||
}
|
||||
|
||||
unsigned int CMARGBController::GetLargestColour(unsigned int red, unsigned int green, unsigned int blue)
|
||||
{
|
||||
unsigned int largest;
|
||||
|
|
@ -142,65 +149,79 @@ unsigned int CMARGBController::GetLargestColour(unsigned int red, unsigned int g
|
|||
|
||||
unsigned char CMARGBController::GetColourIndex(unsigned char red, unsigned char green, unsigned char blue)
|
||||
{
|
||||
//The Coolermaster ARGB controller uses a limited colour pallette referenced by an index
|
||||
//Starting at 0x00 Random, 0x01 Red, 0x02 Green, 0x03 Blue, 0x04 Yellow, 0x05 Purple, 0x06 Cyan, 0x07 White
|
||||
//The index can be calculated by normalising the input colour, rounding those values
|
||||
//and using them as the indicies of a 3d array containing the correct index
|
||||
/*---------------------------------------------------------------------------------------------------------*\
|
||||
| The Cooler Master ARGB controller V0008 uses a limited colour pallette referenced by an index |
|
||||
| Starting at 0x00 Random, 0x01 Red, 0x02 Green, 0x03 Blue, 0x04 Yellow, 0x05 Purple, 0x06 Cyan, 0x07 White |
|
||||
| The index can be calculated by normalising the input colour, rounding those values |
|
||||
| and using them as the indicies of a 3d array containing the correct index |
|
||||
\*---------------------------------------------------------------------------------------------------------*/
|
||||
unsigned int divisor = GetLargestColour( red, green, blue);
|
||||
unsigned int r = round( red / divisor );
|
||||
unsigned int g = round( green / divisor );
|
||||
unsigned int b = round( blue / divisor );
|
||||
unsigned char idx = argb_colour_index_data[r][g][b];
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
void CMARGBController::SetMode(unsigned char mode, unsigned char speed)
|
||||
void CMARGBController::SetLedCount(int zone, int led_count)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
unsigned char buffer[CM_ARGB_PACKET_SIZE] = { 0x00, 0x80, 0x0D, 0x02 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
|
||||
SendUpdate();
|
||||
buffer[CM_ARGB_ZONE_BYTE] = zone;
|
||||
buffer[CM_ARGB_MODE_BYTE] = led_count;
|
||||
buffer[CM_ARGB_COLOUR_INDEX_BYTE] = (0x0F - led_count > 0) ? 0x0F - led_count : 0x01;
|
||||
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
}
|
||||
|
||||
void CMARGBController::SetColor(unsigned char red, unsigned char green, unsigned char blue)
|
||||
void CMARGBController::SetMode(unsigned char mode, unsigned char speed, RGBColor colour, bool random_colours)
|
||||
{
|
||||
current_red = red;
|
||||
current_green = green;
|
||||
current_blue = blue;
|
||||
bool needs_update = !( (current_mode == mode) && (current_speed == speed) && (current_brightness == 0xFF) && (ToRGBColor(current_red, current_green, current_blue) == colour));
|
||||
|
||||
SendUpdate();
|
||||
if (needs_update)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
current_brightness = 0xFF;
|
||||
current_red = RGBGetRValue(colour);
|
||||
current_green = RGBGetGValue(colour);
|
||||
current_blue = RGBGetBValue(colour);
|
||||
bool_random = random_colours;
|
||||
|
||||
SendUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_count)
|
||||
{
|
||||
const unsigned char buffer_size = 0x41;
|
||||
unsigned char buffer[buffer_size] = { 0x00 };
|
||||
unsigned char packet_count = 0x00;
|
||||
const unsigned char buffer_size = CM_ARGB_PACKET_SIZE;
|
||||
unsigned char buffer[buffer_size] = { 0x00, 0x10, 0x02 };
|
||||
unsigned char packet_count = 0;
|
||||
std::vector<unsigned char> colours;
|
||||
|
||||
//Set up the RGB triplets to send
|
||||
/*---------------------------------------------*\
|
||||
| Set up the RGB triplets to send |
|
||||
\*---------------------------------------------*/
|
||||
for(int i = 0; i < led_count; i++)
|
||||
{
|
||||
RGBColor colour = led_colours[i];
|
||||
unsigned char r = RGBGetRValue(colour);
|
||||
unsigned char g = RGBGetGValue(colour);
|
||||
unsigned char b = RGBGetBValue(colour);
|
||||
|
||||
colours.push_back(r);
|
||||
colours.push_back(g);
|
||||
colours.push_back(b);
|
||||
colours.push_back( RGBGetRValue(colour) );
|
||||
colours.push_back( RGBGetGValue(colour) );
|
||||
colours.push_back( RGBGetBValue(colour) );
|
||||
}
|
||||
|
||||
//buffer[CM_ARGB_REPORT_BYTE] = packet_count;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x10;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = 0x02;
|
||||
buffer[CM_ARGB_ZONE_BYTE] = argb_header_data[zone_index].header;
|
||||
buffer[CM_ARGB_MODE_BYTE] = 0x30; //30 might be the LED count??
|
||||
unsigned char buffer_idx = CM_ARGB_MODE_BYTE + 1; //Start colour info from
|
||||
buffer[CM_ARGB_MODE_BYTE] = led_count;
|
||||
unsigned char buffer_idx = CM_ARGB_MODE_BYTE + 1;
|
||||
|
||||
for (std::vector<unsigned char>::iterator it = colours.begin(); it != colours.end(); buffer_idx = 0)
|
||||
for(std::vector<unsigned char>::iterator it = colours.begin(); it != colours.end(); buffer_idx = 0)
|
||||
{
|
||||
//Fill the write buffer till its full or the colour buffer is empty
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Fill the write buffer till its full or the colour buffer is empty |
|
||||
\*-----------------------------------------------------------------*/
|
||||
buffer[CM_ARGB_REPORT_BYTE] = packet_count;
|
||||
while (( buffer_idx < buffer_size) && ( it != colours.end() ))
|
||||
{
|
||||
|
|
@ -212,17 +233,20 @@ void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_cou
|
|||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
|
||||
//reset the write buffer
|
||||
memset(buffer, 0x00, sizeof(buffer) );
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Reset the write buffer |
|
||||
\*-----------------------------------------------------------------*/
|
||||
memset(buffer, 0x00, buffer_size );
|
||||
packet_count++;
|
||||
}
|
||||
|
||||
buffer[CM_ARGB_REPORT_BYTE] = 0x82;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x62;
|
||||
/*buffer[CM_ARGB_COMMAND_BYTE] = 0x62;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = 0x00;
|
||||
buffer[CM_ARGB_ZONE_BYTE] = 0x73;
|
||||
buffer[CM_ARGB_MODE_BYTE] = 0x00;
|
||||
buffer[CM_ARGB_COLOUR_INDEX_BYTE] = 0x33;
|
||||
buffer[CM_ARGB_SPEED_BYTE] = 0x1B;
|
||||
buffer[CM_ARGB_SPEED_BYTE] = 0x1B;*/
|
||||
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
|
|
@ -230,52 +254,53 @@ void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_cou
|
|||
|
||||
void CMARGBController::SendUpdate()
|
||||
{
|
||||
unsigned char buffer[0x40] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
bool boolARGB_header = argb_header_data[zone_index].digital;
|
||||
bool boolPassthru = ( current_mode == CM_ARGB_MODE_PASSTHRU );
|
||||
bool boolDirect = ( current_mode == CM_ARGB_MODE_DIRECT );
|
||||
unsigned char function = boolPassthru ? 0x02 : ( boolARGB_header ? 0x03 : 0x01);
|
||||
buffer[CM_ARGB_REPORT_BYTE] = 0x80;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = boolDirect ? 0x10 : 0x01;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = boolDirect ? 0x01 : function;
|
||||
unsigned char buffer[CM_ARGB_PACKET_SIZE] = { 0x00 };
|
||||
int buffer_size = (sizeof(buffer) / sizeof(buffer[0]));
|
||||
bool boolARGB_header = argb_header_data[zone_index].digital;
|
||||
bool boolPassthru = ( current_mode == CM_ARGB_MODE_PASSTHRU ) || ( current_mode == CM_RGB_MODE_PASSTHRU );
|
||||
bool boolDirect = ( current_mode == CM_ARGB_MODE_DIRECT );
|
||||
unsigned char function = boolPassthru ? (boolARGB_header ? 0x02 : 0x04) : (boolARGB_header ? 0x01 : 0x03);
|
||||
buffer[CM_ARGB_REPORT_BYTE] = 0x80;
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x01;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = boolDirect ? 0x01 : function;
|
||||
|
||||
if ( boolDirect )
|
||||
{
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x10;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = 0x01;
|
||||
buffer[CM_ARGB_ZONE_BYTE] = argb_header_data[zone_index].header;
|
||||
buffer[CM_ARGB_MODE_BYTE] = 0x30; //30 might be the LED count??
|
||||
|
||||
//hid_write(dev, buffer, buffer_size);
|
||||
//hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x01;
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = function;
|
||||
}
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
|
||||
|
||||
if ( boolARGB_header )
|
||||
/*-----------------------------------------------------------------*\
|
||||
| Direct mode is now set up and no other mode packet is required |
|
||||
\*-----------------------------------------------------------------*/
|
||||
if(boolDirect)
|
||||
{
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x0b; //ARGB sends 0x0b (1011) RGB sends 0x04 (0100)
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = (false) ? 0x01 : 0x02; //This controls custom mode TODO
|
||||
buffer[CM_ARGB_ZONE_BYTE] = argb_header_data[zone_index].header;
|
||||
buffer[CM_ARGB_MODE_BYTE] = argb_mode_data[1][current_mode];
|
||||
buffer[CM_ARGB_COLOUR_INDEX_BYTE] = GetColourIndex( current_red, current_green, current_blue );
|
||||
buffer[CM_ARGB_SPEED_BYTE] = current_speed;
|
||||
return;
|
||||
}
|
||||
|
||||
if(boolARGB_header)
|
||||
{
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x0b; //ARGB sends 0x0b (1011) RGB sends 0x04 (0100)
|
||||
buffer[CM_ARGB_FUNCTION_BYTE] = (false) ? 0x01 : 0x02; //This controls direct mode TODO
|
||||
buffer[CM_ARGB_ZONE_BYTE] = argb_header_data[zone_index].header;
|
||||
buffer[CM_ARGB_MODE_BYTE] = current_mode;
|
||||
buffer[CM_ARGB_COLOUR_INDEX_BYTE] = bool_random ? 0x00 : 0x10;
|
||||
buffer[CM_ARGB_SPEED_BYTE] = current_speed;
|
||||
buffer[CM_ARGB_BRIGHTNESS_BYTE] = current_brightness;
|
||||
buffer[CM_ARGB_RED_BYTE] = current_red;
|
||||
buffer[CM_ARGB_GREEN_BYTE] = current_green;
|
||||
buffer[CM_ARGB_BLUE_BYTE] = current_blue;
|
||||
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = 0x04; //ARGB sends 0x0b (1011) RGB sends 0x04 (0100)
|
||||
buffer[CM_ARGB_MODE_BYTE + CM_RGB_OFFSET] = argb_mode_data[0][current_mode];
|
||||
buffer[CM_ARGB_COLOUR_INDEX_BYTE + CM_RGB_OFFSET] = GetColourIndex( current_red, current_green, current_blue );
|
||||
buffer[CM_ARGB_COMMAND_BYTE] = boolPassthru ? 0x01 : 0x04; //ARGB sends 0x0b (1011) RGB sends 0x04 (0100)
|
||||
buffer[CM_ARGB_MODE_BYTE + CM_RGB_OFFSET] = current_mode;
|
||||
buffer[CM_ARGB_COLOUR_INDEX_BYTE + CM_RGB_OFFSET] = bool_random ? 0x00 : 0x10;
|
||||
buffer[CM_ARGB_SPEED_BYTE + CM_RGB_OFFSET] = current_speed;
|
||||
buffer[CM_ARGB_BRIGHTNESS_BYTE + CM_RGB_OFFSET] = current_brightness;
|
||||
buffer[CM_ARGB_RED_BYTE + CM_RGB_OFFSET] = current_red;
|
||||
buffer[CM_ARGB_GREEN_BYTE + CM_RGB_OFFSET] = current_green;
|
||||
buffer[CM_ARGB_BLUE_BYTE + CM_RGB_OFFSET] = current_blue;
|
||||
|
||||
hid_write(dev, buffer, buffer_size);
|
||||
hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue