Commander Core: Add led count detection

This commit is contained in:
ParkerMc 2023-12-14 17:25:59 +00:00 committed by Adam Honse
parent 1f4e214e5a
commit 6efc7ff294
3 changed files with 86 additions and 19 deletions

View file

@ -98,6 +98,24 @@ std::string CorsairCommanderCoreController::GetLocationString()
return("HID: " + location);
}
std::vector<unsigned short int> CorsairCommanderCoreController::GetLedCounts()
{
/*-----------------------------------------------------*\
| Get the LED count per device |
\*-----------------------------------------------------*/
std::vector<unsigned short int> led_counts;
unsigned char endpoint[2] = {0x20, 0x00};
unsigned char* res = new unsigned char[command_res_size];
ReadData(endpoint, res);
for(int i = 0; i < res[2]; i++)
{
led_counts.push_back(res[i*4+6] << 8 | res[i*4+5]);
}
delete[] res;
return led_counts;
}
void CorsairCommanderCoreController::KeepaliveThread()
{
while(keepalive_thread_run.load())
@ -191,7 +209,7 @@ void CorsairCommanderCoreController::WriteData(unsigned char endpoint[2], unsign
/*---------------------------------------------------------*\
| Open endpoint |
\*---------------------------------------------------------*/
unsigned char command[2] = {0x0d, 0x00};
unsigned char command[2] = {0x0D, 0x00};
SendCommand(command, endpoint, 2, NULL);
/*---------------------------------------------------------*\
@ -255,6 +273,35 @@ void CorsairCommanderCoreController::WriteData(unsigned char endpoint[2], unsign
SendCommand(command, NULL, 0, NULL);
}
void CorsairCommanderCoreController::ReadData(unsigned char endpoint[2], unsigned char data[])
{
/*---------------------------------------------------------*\
| Private function to read data from an endpoint |
| Note: Right now we only know how to read the first packet.|
| It is not currently know how to read more. |
\*---------------------------------------------------------*/
/*---------------------------------------------------------*\
| Open endpoint |
\*---------------------------------------------------------*/
unsigned char command[2] = {0x0D, 0x00};
SendCommand(command, endpoint, 2, NULL);
/*---------------------------------------------------------*\
| Read data |
\*---------------------------------------------------------*/
command[0] = 0x08;
command[1] = 0x00;
SendCommand(command, NULL, 0, data);
/*---------------------------------------------------------*\
| Close endpoint |
\*---------------------------------------------------------*/
command[0] = 0x05;
command[1] = 0x01;
SendCommand(command, NULL, 0, NULL);
}
void CorsairCommanderCoreController::SetDirectColor
(
std::vector<RGBColor> colors,
@ -282,24 +329,17 @@ void CorsairCommanderCoreController::SetDirectColor
usb_buf[packet_offset] = RGBGetRValue(colors[i]);
usb_buf[packet_offset+1] = RGBGetGValue(colors[i]);
usb_buf[packet_offset+2] = RGBGetBValue(colors[i]);
packet_offset += 3;
}
led_idx = led_idx + zones[zone_idx].leds_count;
/*-------------------------------------------------*\
| Move offset for pump zone with less than 29 LEDs |
\*-------------------------------------------------*/
if(zone_idx == 0)
{
packet_offset += 3 * (29 - zones[zone_idx].leds_count);
}
else
{
/*-------------------------------------------------*\
| Move offset for fans with less than 34 LEDs |
\*-------------------------------------------------*/
if(zone_idx != 0)
{
packet_offset += 3 * (34 - zones[zone_idx].leds_count);
}

View file

@ -37,6 +37,7 @@ public:
~CorsairCommanderCoreController();
std::string GetFirmwareString();
std::vector<unsigned short int> GetLedCounts();
std::string GetLocationString();
void SetDirectColor
@ -65,6 +66,7 @@ private:
void SendCommand(unsigned char command[2], unsigned char data[], unsigned short int data_len, unsigned char res[]);
void WriteData(unsigned char endpoint[2], unsigned char data_type[2], unsigned char data[], unsigned short int data_len);
void ReadData(unsigned char endpoint[2], unsigned char data[]);
void SendCommit();
void InitController();

View file

@ -21,7 +21,7 @@
\*-------------------------------------------------------------------*/
#define NA 0xFFFFFFFF
static unsigned int matrix_map[7][7] =
static unsigned int matrix_map29[7][7] =
{
{ 28, NA, 27, NA, 26, NA, 25 },
{ NA, 16, NA, 15, NA, 14, NA },
@ -32,6 +32,21 @@ static unsigned int matrix_map[7][7] =
{ 19, NA, 20, NA, 21, NA, 22 },
};
static unsigned int matrix_map24[11][11] =
{
{ NA, NA, NA, NA, NA, 6, NA, NA, NA, NA, NA },
{ NA, NA, NA, 4, 5, NA, 7, 8, NA, NA, NA },
{ NA, NA, 3, NA, NA, NA, NA, NA, 9, NA, NA },
{ NA, 2, NA, NA, NA, NA, NA, NA, NA, 10, NA },
{ NA, 1, NA, NA, NA, NA, NA, NA, NA, 11, NA },
{ 0, NA, NA, NA, NA, NA, NA, NA, NA, NA, 12 },
{ NA, 23, NA, NA, NA, NA, NA, NA, NA, 13, NA },
{ NA, 22, NA, NA, NA, NA, NA, NA, NA, 14, NA },
{ NA, NA, 21, NA, NA, NA, NA, NA, 15, NA, NA },
{ NA, NA, NA, 20, 19, NA, 17, 16, NA, NA, NA },
{ NA, NA, NA, NA, NA, 18, NA, NA, NA, NA, NA }
};
RGBController_CorsairCommanderCore::RGBController_CorsairCommanderCore(CorsairCommanderCoreController* controller_ptr)
{
controller = controller_ptr;
@ -67,16 +82,26 @@ void RGBController_CorsairCommanderCore::SetupZones()
first_run = 1;
}
std::vector<unsigned short int> led_count = controller->GetLedCounts();
zones.resize(7);
zones[0].name = "Pump";
zones[0].type = ZONE_TYPE_MATRIX;
zones[0].leds_min = 29;
zones[0].leds_max = 29;
zones[0].leds_count = 29;
zones[0].leds_min = led_count.at(0);
zones[0].leds_max = led_count.at(0);
zones[0].leds_count = led_count.at(0);
zones[0].matrix_map = new matrix_map_type;
zones[0].matrix_map->height = 7;
zones[0].matrix_map->width = 7;
zones[0].matrix_map->map = (unsigned int *)&matrix_map;
if(led_count.at(0) == 24)
{
zones[0].matrix_map->height = 11;
zones[0].matrix_map->width = 11;
zones[0].matrix_map->map = (unsigned int *)&matrix_map24;
}
else
{
zones[0].matrix_map->height = 7;
zones[0].matrix_map->width = 7;
zones[0].matrix_map->map = (unsigned int *)&matrix_map29;
}
for(unsigned int i = 1; i < (CORSAIR_COMMANDER_CORE_NUM_CHANNELS + 1); i++)
{
@ -87,7 +112,7 @@ void RGBController_CorsairCommanderCore::SetupZones()
if(first_run)
{
zones[i].leds_count = 0;
zones[i].leds_count = (led_count.size() > i) ? led_count.at(i) : 0;
}
}