Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,485 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| CorsairCommanderCoreController.cpp |
|
||||
| |
|
||||
| Driver for Corsair Commander Core |
|
||||
| |
|
||||
| Jeff P. |
|
||||
| Nikola Jurkovic (jurkovic.nikola) 14 Aug 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include "CorsairCommanderCoreController.h"
|
||||
#include "CorsairDeviceGuard.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
CorsairCommanderCoreController::CorsairCommanderCoreController(hid_device* dev_handle, const char* path, int pid, std::string dev_name)
|
||||
{
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
name = dev_name;
|
||||
keepalive_thread_run = 1;
|
||||
controller_ready = 0;
|
||||
packet_size = CORSAIR_COMMANDER_CORE_PACKET_SIZE_V2;
|
||||
command_res_size = packet_size - 4;
|
||||
this->pid = pid;
|
||||
guard_manager_ptr = new DeviceGuardManager(new CorsairDeviceGuard());
|
||||
|
||||
if(pid == CORSAIR_COMMANDER_CORE2_PID)
|
||||
{
|
||||
packet_size = CORSAIR_COMMANDER_CORE_PACKET_SIZE_V3;
|
||||
command_res_size = packet_size - 4;
|
||||
}
|
||||
else if(pid == CORSAIR_COMMANDER_CORE_XT_PID)
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Commander Core XT |
|
||||
\*-----------------------------------------------------*/
|
||||
packet_size = CORSAIR_COMMANDER_CORE_XT_PACKET_SIZE;
|
||||
command_res_size = packet_size - 4;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Initialize controller |
|
||||
\*-----------------------------------------------------*/
|
||||
InitController();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Start keepalive thread |
|
||||
\*-----------------------------------------------------*/
|
||||
keepalive_thread = new std::thread(&CorsairCommanderCoreController::KeepaliveThread, this);
|
||||
}
|
||||
|
||||
CorsairCommanderCoreController::~CorsairCommanderCoreController()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Hardware mode |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char command[2] = {0x01, 0x03};
|
||||
unsigned char cmd_data[2] = {0x00, 0x01};
|
||||
SendCommand(command, cmd_data, 2, NULL);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Close keepalive thread |
|
||||
\*-----------------------------------------------------*/
|
||||
keepalive_thread_run = 0;
|
||||
keepalive_thread->join();
|
||||
delete keepalive_thread;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Close HID device |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_close(dev);
|
||||
delete guard_manager_ptr;
|
||||
}
|
||||
|
||||
void CorsairCommanderCoreController::InitController()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Get version |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char command[2] = {0x02, 0x13};
|
||||
unsigned char* res = new unsigned char[command_res_size];
|
||||
|
||||
SendCommand(command, NULL, 0, res);
|
||||
version[0] = res[0];
|
||||
version[1] = res[1];
|
||||
version[2] = res[2];
|
||||
delete[] res;
|
||||
|
||||
if(pid == CORSAIR_COMMANDER_CORE_PID && version[0] == 1)
|
||||
{
|
||||
packet_size = CORSAIR_COMMANDER_CORE_PACKET_SIZE_V1;
|
||||
command_res_size = packet_size - 4;
|
||||
}
|
||||
|
||||
SetFanMode(false);
|
||||
}
|
||||
|
||||
std::string CorsairCommanderCoreController::GetFirmwareString()
|
||||
{
|
||||
return "v"+std::to_string(version[0]) + "." + std::to_string(version[1]) + "." + std::to_string(version[2]);
|
||||
}
|
||||
|
||||
std::string CorsairCommanderCoreController::GetLocationString()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string CorsairCommanderCoreController::GetNameString()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
int CorsairCommanderCoreController::GetPidInt()
|
||||
{
|
||||
return(this->pid);
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
if(controller_ready)
|
||||
{
|
||||
if((std::chrono::steady_clock::now() - last_commit_time) > std::chrono::seconds(10))
|
||||
{
|
||||
SendCommit();
|
||||
}
|
||||
}
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairCommanderCoreController::SendCommit()
|
||||
{
|
||||
if(!lastcolors.empty())
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| If colors remain to be sent, send them |
|
||||
\*-----------------------------------------------------*/
|
||||
SetDirectColor(lastcolors, lastzones);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Update last commit time |
|
||||
\*-----------------------------------------------------*/
|
||||
last_commit_time = std::chrono::steady_clock::now();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Keepalive |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char command[2] = {0x02, 0x13};
|
||||
SendCommand(command, NULL, 2, NULL, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CorsairCommanderCoreController::SendCommand(unsigned char command[2], unsigned char data[], unsigned short int data_len, unsigned char res[], bool dev_read)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Private function to send a command |
|
||||
| data_len must be <= 93 for V2 or <= 1021 for V1 |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char* buf = new unsigned char[packet_size];
|
||||
|
||||
memset(buf, 0, packet_size);
|
||||
buf[0] = 0x00;
|
||||
buf[1] = 0x08;
|
||||
|
||||
memcpy(&buf[2], command, 2);
|
||||
if(data != NULL)
|
||||
{
|
||||
memcpy(&buf[4], data, data_len);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| HID I/O start |
|
||||
\*---------------------------------------------------------*/
|
||||
{
|
||||
DeviceGuardLock _ = guard_manager_ptr->AwaitExclusiveAccess();
|
||||
|
||||
hid_write(dev, buf, packet_size);
|
||||
if(dev_read)
|
||||
{
|
||||
do
|
||||
{
|
||||
hid_read(dev, buf, packet_size);
|
||||
}
|
||||
while(buf[0] != 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| HID I/O end (lock released) |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
if(res != NULL)
|
||||
{
|
||||
memcpy(res, &buf[3], command_res_size);
|
||||
}
|
||||
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void CorsairCommanderCoreController::WriteData(unsigned char endpoint[2], unsigned char data_type[2], unsigned char data[], unsigned short int data_len)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| Private function to write data to an endpoint |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Open endpoint |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char command[2] = {0x0D, 0x00};
|
||||
SendCommand(command, endpoint, 2, NULL);
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Write data |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short int data_start_index = 0;
|
||||
while(data_start_index < data_len)
|
||||
{
|
||||
if(data_start_index == 0)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| First packet |
|
||||
\*---------------------------------------------------------*/
|
||||
int packet_data_len = packet_size - 10;
|
||||
if(data_len < packet_data_len)
|
||||
{
|
||||
packet_data_len = data_len;
|
||||
}
|
||||
unsigned char* buf = new unsigned char[packet_data_len+6];
|
||||
unsigned short int real_len = data_len+2;
|
||||
/*---------------------------------------------------------*\
|
||||
| Convert length to little endian |
|
||||
\*---------------------------------------------------------*/
|
||||
buf[0] = (unsigned char) real_len & 0xFF;
|
||||
buf[1] = (unsigned char) (real_len >> 8) & 0xFF;
|
||||
buf[2] = 0x00;
|
||||
buf[3] = 0x00;
|
||||
memcpy(&buf[4], data_type, 2);
|
||||
memcpy(&buf[6], data, packet_data_len);
|
||||
|
||||
command[0] = 0x06;
|
||||
command[1] = 0x00;
|
||||
SendCommand(command, buf, packet_data_len+6, NULL);
|
||||
delete[] buf;
|
||||
data_start_index += packet_data_len;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| The rest of the packets |
|
||||
| This command is not in v1 but it should never be reached as all data should fit in the first packet |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
int packet_data_len = packet_size - 4;
|
||||
if(data_len-data_start_index < packet_data_len)
|
||||
{
|
||||
packet_data_len = data_len-data_start_index;
|
||||
}
|
||||
|
||||
command[0] = 0x07;
|
||||
command[1] = 0x00;
|
||||
SendCommand(command, &data[data_start_index], packet_data_len, NULL);
|
||||
data_start_index += packet_data_len;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Close endpoint |
|
||||
\*---------------------------------------------------------*/
|
||||
command[0] = 0x05;
|
||||
command[1] = 0x01;
|
||||
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,
|
||||
std::vector<zone> zones
|
||||
)
|
||||
{
|
||||
if(controller_ready == 1 && ((std::chrono::steady_clock::now() - last_commit_time) > std::chrono::milliseconds(33)))
|
||||
{
|
||||
lastcolors = colors;
|
||||
lastzones = zones;
|
||||
int packet_offset = 0;
|
||||
int led_idx = 0;
|
||||
int channel_idx = 0;
|
||||
int packet_len = CORSAIR_COMMANDER_CORE_RGB_DATA_LENGTH;
|
||||
|
||||
if(pid == CORSAIR_COMMANDER_CORE_XT_PID)
|
||||
{
|
||||
packet_len = CORSAIR_COMMANDER_CORE_XT_RGB_DATA_LENGTH;
|
||||
}
|
||||
|
||||
unsigned char* usb_buf = new unsigned char[packet_len];
|
||||
|
||||
for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Add led colors |
|
||||
\*-------------------------------------------------*/
|
||||
for(unsigned int i = led_idx; i < led_idx + zones[zone_idx].leds_count; i++)
|
||||
{
|
||||
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;
|
||||
|
||||
if(zone_idx != 0)
|
||||
{
|
||||
packet_offset += 3 * (34 - zones[zone_idx].leds_count);
|
||||
}
|
||||
|
||||
channel_idx++;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Sending a direct mode color packet resets the timeout |
|
||||
\*-----------------------------------------------------*/
|
||||
last_commit_time = std::chrono::steady_clock::now();
|
||||
|
||||
unsigned char endpoint[2] = {0x22, 0x00};
|
||||
unsigned char data_type[2] = {0x12, 0x00};
|
||||
WriteData(endpoint, data_type, usb_buf, packet_offset);
|
||||
|
||||
delete[] usb_buf;
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairCommanderCoreController::SetFanMode(bool external_rgb_port)
|
||||
{
|
||||
controller_ready = 0;
|
||||
DeviceGuardLock _ = guard_manager_ptr->AwaitExclusiveAccess();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Force controller to 6 QL fan mode to expose maximum |
|
||||
| number of LEDs per rgb port (34 LEDs per port) |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned int index = 3;
|
||||
unsigned int max_index = 15;
|
||||
unsigned char endpoint[2] = {0x1E, 0x00};
|
||||
unsigned char data_type[2] = {0x0D, 0x00};
|
||||
|
||||
unsigned char buf[15];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(buf, 0x00, 15);
|
||||
|
||||
buf[0] = 0x07;
|
||||
if(pid == CORSAIR_COMMANDER_CORE_XT_PID)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Commander Core XT external RGB port |
|
||||
\*-------------------------------------------------*/
|
||||
if(external_rgb_port)
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Enable external port |
|
||||
\*---------------------------------------------*/
|
||||
buf[1] = 0x01;
|
||||
buf[2] = 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*---------------------------------------------*\
|
||||
| Shift packet start position and maximum index |
|
||||
\*---------------------------------------------*/
|
||||
buf[1] = 0x00;
|
||||
buf[2] = 0x00;
|
||||
index = 2;
|
||||
max_index = 14;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Commander Core, Set AIO mode |
|
||||
\*-------------------------------------------------*/
|
||||
buf[1] = 0x01;
|
||||
buf[2] = 0x08;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| SET fan modes |
|
||||
\*-----------------------------------------------------*/
|
||||
for(unsigned int i = index; i < max_index; i = i + 2)
|
||||
{
|
||||
buf[i] = 0x01;
|
||||
buf[i + 1] = 0x06;
|
||||
}
|
||||
|
||||
WriteData(endpoint, data_type, buf, 15);
|
||||
controller_ready = 1;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Wake up device, needs to be done after setting fan |
|
||||
| mode to reinitialize device if fan mode has changed |
|
||||
\*-----------------------------------------------------*/
|
||||
unsigned char command[2] = {0x01, 0x03};
|
||||
unsigned char cmd_data[2] = {0x00, 0x02};
|
||||
SendCommand(command, cmd_data, 2, NULL);
|
||||
}
|
||||
|
||||
void CorsairCommanderCoreController::SetLedAmount(int led_amount)
|
||||
{
|
||||
controller_ready = 0;
|
||||
DeviceGuardLock _ = guard_manager_ptr->AwaitExclusiveAccess();
|
||||
|
||||
unsigned char buf[15];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(buf, 0x00, 15);
|
||||
|
||||
unsigned char endpoint[2] = {0x1D, 0x00};
|
||||
unsigned char data_type[2] = {0x0C, 0x00};
|
||||
|
||||
buf[0] = 0x07;
|
||||
buf[1] = led_amount;
|
||||
|
||||
WriteData(endpoint, data_type, buf, 15);
|
||||
controller_ready = 1;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| CorsairCommanderCoreController.h |
|
||||
| |
|
||||
| Driver for Corsair Commander Core |
|
||||
| |
|
||||
| Jeff P. |
|
||||
| Nikola Jurkovic (jurkovic.nikola) 14 Aug 2025 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
#include "DeviceGuardManager.h"
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Packet size per device |
|
||||
\*-----------------------------------------------------*/
|
||||
#define CORSAIR_COMMANDER_CORE_PACKET_SIZE_V1 1025
|
||||
#define CORSAIR_COMMANDER_CORE_PACKET_SIZE_V2 97
|
||||
#define CORSAIR_COMMANDER_CORE_PACKET_SIZE_V3 65
|
||||
#define CORSAIR_COMMANDER_CORE_XT_PACKET_SIZE 385
|
||||
|
||||
#define CORSAIR_COMMANDER_CORE_RGB_DATA_LENGTH 699
|
||||
#define CORSAIR_COMMANDER_CORE_XT_RGB_DATA_LENGTH 1224
|
||||
|
||||
#define CORSAIR_QL_FAN_ZONE_OFFSET 102
|
||||
#define CORSAIR_COMMANDER_CORE_NUM_CHANNELS 6
|
||||
|
||||
#define CORSAIR_COMMANDER_CORE_PID 0x0C1C
|
||||
#define CORSAIR_COMMANDER_CORE2_PID 0x0C32
|
||||
#define CORSAIR_COMMANDER_CORE3_PID 0x0C1D
|
||||
#define CORSAIR_COMMANDER_CORE4_PID 0x0C3C
|
||||
#define CORSAIR_COMMANDER_CORE5_PID 0x0C3D
|
||||
#define CORSAIR_COMMANDER_CORE6_PID 0x0C3E
|
||||
#define CORSAIR_COMMANDER_CORE_XT_PID 0x0C2A
|
||||
|
||||
enum
|
||||
{
|
||||
CORSAIR_COMMANDER_CORE_MODE_DIRECT = 0x00,
|
||||
};
|
||||
|
||||
class CorsairCommanderCoreController
|
||||
{
|
||||
public:
|
||||
CorsairCommanderCoreController(hid_device* dev_handle, const char* path, int pid, std::string dev_name);
|
||||
~CorsairCommanderCoreController();
|
||||
|
||||
std::string GetFirmwareString();
|
||||
std::vector<unsigned short int> GetLedCounts();
|
||||
std::string GetLocationString();
|
||||
std::string GetNameString();
|
||||
int GetPidInt();
|
||||
|
||||
void SetDirectColor
|
||||
(
|
||||
std::vector<RGBColor>,
|
||||
std::vector<zone>
|
||||
);
|
||||
|
||||
void KeepaliveThread();
|
||||
void SetFanMode(bool external_rgb_port);
|
||||
void SetLedAmount(int led_amount);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::thread* keepalive_thread;
|
||||
std::atomic<bool> keepalive_thread_run;
|
||||
std::atomic<bool> controller_ready;
|
||||
std::string location;
|
||||
std::vector<RGBColor> lastcolors;
|
||||
std::vector<zone> lastzones;
|
||||
std::string name;
|
||||
unsigned short int version[3] = {0, 0, 0};
|
||||
int packet_size;
|
||||
int command_res_size;
|
||||
int pid;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_commit_time;
|
||||
DeviceGuardManager* guard_manager_ptr;
|
||||
|
||||
void SendCommand(unsigned char command[2], unsigned char data[], unsigned short int data_len, unsigned char res[], bool dev_read = true);
|
||||
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();
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| CorsairCommanderCoreControllerDetect.cpp |
|
||||
| |
|
||||
| Detector for Corsair Commander Core |
|
||||
| |
|
||||
| Jeff P. |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <hidapi.h>
|
||||
#include "Detector.h"
|
||||
#include "CorsairCommanderCoreController.h"
|
||||
#include "RGBController_CorsairCommanderCore.h"
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Corsair vendor ID |
|
||||
\*-----------------------------------------------------*/
|
||||
#define CORSAIR_VID 0x1B1C
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectCorsairCommanderCoreControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Corsair RGB Cooler controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectCorsairCommanderCoreControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
CorsairCommanderCoreController* controller = new CorsairCommanderCoreController(dev, info->path, info->product_id, name);
|
||||
RGBController_CorsairCommanderCore* rgb_controller = new RGBController_CorsairCommanderCore(controller);
|
||||
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE_PID, 0x00, 0xFF42, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE2_PID, 0x00, 0xFF42, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE3_PID, 0x00, 0xFF42, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE4_PID, 0x00, 0xFF42, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE5_PID, 0x00, 0xFF42, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE6_PID, 0x00, 0xFF42, 0x01);
|
||||
REGISTER_HID_DETECTOR_IPU("Corsair Commander Core XT", DetectCorsairCommanderCoreControllers, CORSAIR_VID, CORSAIR_COMMANDER_CORE_XT_PID, 0x00, 0xFF42, 0x01);
|
||||
@@ -0,0 +1,198 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_CorsairCCommanderCore.cpp |
|
||||
| |
|
||||
| RGBController for Corsair Commander Core |
|
||||
| |
|
||||
| Jeff P. |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_CorsairCommanderCore.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Corsair Commander Core
|
||||
@category Cooler
|
||||
@type USB
|
||||
@save :x:
|
||||
@direct :white_check_mark:
|
||||
@effects :x:
|
||||
@detectors DetectCorsairCommanderCoreControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#define NA 0xFFFFFFFF
|
||||
static unsigned int matrix_map29[7][7] =
|
||||
{
|
||||
{ 28, NA, 27, NA, 26, NA, 25 },
|
||||
{ NA, 16, NA, 15, NA, 14, NA },
|
||||
{ 17, NA, 0, 5, 3, NA, 24 },
|
||||
{ NA, 9, 4, 8, 6, 13, NA },
|
||||
{ 18, NA, 1, 7, 2, NA, 23 },
|
||||
{ NA, 10, NA, 11, NA, 12, NA },
|
||||
{ 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;
|
||||
|
||||
name = controller->GetNameString();
|
||||
vendor = "Corsair";
|
||||
description = "Corsair Commander Core Device";
|
||||
version = controller->GetFirmwareString();
|
||||
type = DEVICE_TYPE_COOLER;
|
||||
location = controller->GetLocationString();
|
||||
SetupZones();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = 0;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
}
|
||||
|
||||
RGBController_CorsairCommanderCore::~RGBController_CorsairCommanderCore()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_CorsairCommanderCore::SetupZones()
|
||||
{
|
||||
std::atomic<bool> first_run;
|
||||
first_run = 0;
|
||||
|
||||
if(zones.size() == 0)
|
||||
{
|
||||
first_run = 1;
|
||||
}
|
||||
|
||||
std::vector<unsigned short int> led_count = controller->GetLedCounts();
|
||||
zones.resize(7);
|
||||
if(controller->GetPidInt() == CORSAIR_COMMANDER_CORE_XT_PID)
|
||||
{
|
||||
zones[0].name = "External RGB Port";
|
||||
zones[0].type = ZONE_TYPE_LINEAR;
|
||||
zones[0].leds_min = zones[0].leds_min;
|
||||
zones[0].leds_max = 204;
|
||||
zones[0].leds_count = zones[0].leds_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
zones[0].name = "Pump";
|
||||
zones[0].type = ZONE_TYPE_MATRIX;
|
||||
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;
|
||||
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++)
|
||||
{
|
||||
zones[i].name = "RGB Port " + std::to_string(i);
|
||||
zones[i].type = ZONE_TYPE_LINEAR;
|
||||
zones[i].leds_min = 0;
|
||||
zones[i].leds_max = 34;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[i].leds_count = (led_count.size() > i) ? led_count.at(i) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
leds.clear();
|
||||
colors.clear();
|
||||
|
||||
for(unsigned int zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
for(unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
new_led.name = zones[zone_idx].name + " LED " + std::to_string(led_idx+1);
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_CorsairCommanderCore::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
if((size_t) zone >= zones.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max))
|
||||
{
|
||||
zones[zone].leds_count = new_size;
|
||||
if(zone == 0 && controller->GetPidInt() == CORSAIR_COMMANDER_CORE_XT_PID)
|
||||
{
|
||||
if(new_size > 0)
|
||||
{
|
||||
controller->SetFanMode(true);
|
||||
controller->SetLedAmount(new_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
controller->SetFanMode(false);
|
||||
}
|
||||
}
|
||||
SetupZones();
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_CorsairCommanderCore::DeviceUpdateLEDs()
|
||||
{
|
||||
DeviceUpdateMode();
|
||||
}
|
||||
|
||||
void RGBController_CorsairCommanderCore::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_CorsairCommanderCore::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_CorsairCommanderCore::DeviceUpdateMode()
|
||||
{
|
||||
switch(modes[active_mode].value)
|
||||
{
|
||||
case CORSAIR_COMMANDER_CORE_MODE_DIRECT:
|
||||
controller->SetDirectColor(colors, zones);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_CorsairCCommanderCore.h |
|
||||
| |
|
||||
| RGBController for Corsair Commander Core |
|
||||
| |
|
||||
| Jeff P. |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "CorsairCommanderCoreController.h"
|
||||
|
||||
class RGBController_CorsairCommanderCore : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_CorsairCommanderCore(CorsairCommanderCoreController* controller_ptr);
|
||||
~RGBController_CorsairCommanderCore();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
CorsairCommanderCoreController* controller;
|
||||
std::vector<int> fanleds{0};
|
||||
};
|
||||
Reference in New Issue
Block a user