Initial commit for the Corsair MM700 to resolve #1718

+ Adding CorsairPeripheralV2Controller base class
+ Adding CorsairPeripheralV2Devices.h metadata file
+ Renaming CorsairK55RGBPROController to CorsairPeripheralV2SWController
+ Adjusting CorsairPeripheralV2SWController to accomodate base class changes
+ Renaming RGBController_CorsairK55RGBPRO to RGBController_CorsairV2SW
+ Adjusting RGBController_CorsairV2SW to handle device set up from meta data
+ Adding PID `0x1B9B` and registering detector in CorsairPeripheralV2ControllerDetect.cpp
This commit is contained in:
Chris 2022-08-11 20:58:09 +10:00
parent 9caf7802ed
commit 3a71b76075
14 changed files with 970 additions and 350 deletions

View file

@ -1,106 +0,0 @@
#include "CorsairK55RGBPROController.h"
/*-----------------------------------------*\
| CorsairK55RGBPROController.cpp |
| |
| Driver for Corsair K55 RGB PRO Keyboard |
\*-----------------------------------------*/
#include "LogManager.h"
CorsairK55RGBPROController::CorsairK55RGBPROController(hid_device* dev_handle, const char* path)
{
dev = dev_handle;
location = path;
LightingControl();
}
CorsairK55RGBPROController::~CorsairK55RGBPROController()
{
hid_close(dev);
}
std::string CorsairK55RGBPROController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string CorsairK55RGBPROController::GetFirmwareString()
{
return "";
}
std::string CorsairK55RGBPROController::GetName()
{
return name;
}
void CorsairK55RGBPROController::SetName(std::string device_name)
{
name = device_name;
}
std::string CorsairK55RGBPROController::GetSerialString()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
std::wstring return_wstring = serial_string;
std::string return_string(return_wstring.begin(), return_wstring.end());
return(return_string);
}
void CorsairK55RGBPROController::LightingControl()
{
unsigned char usb_buf[65];
memset(usb_buf, 0x00, sizeof(usb_buf));
//This is requered
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x01;
usb_buf[0x03] = 0x03;
usb_buf[0x05] = 0x02;
hid_write(dev, (unsigned char *)usb_buf, 65);
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x02;
usb_buf[0x03] = 0x5F;
hid_write(dev, (unsigned char *)usb_buf, 65);
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x0D;
usb_buf[0x04] = 0x01;
hid_write(dev, (unsigned char *)usb_buf, 65);
}
void CorsairK55RGBPROController::SetLEDs(std::vector<RGBColor>colors)
{
unsigned char usb_buf[65];
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x06;
usb_buf[0x04] = 0x12;
for(std::size_t color_idx = 0; color_idx < colors.size(); color_idx++)
{
RGBColor color = colors[color_idx];
usb_buf[9 + color_idx] = RGBGetRValue(color);
usb_buf[15 + color_idx] = RGBGetGValue(color);
usb_buf[21 + color_idx] = RGBGetBValue(color);
}
hid_write(dev, (unsigned char *)usb_buf, 65);
}

View file

@ -1,35 +0,0 @@
#ifndef CORSAIRK55RGBPROCONTROLLER_H
#define CORSAIRK55RGBPROCONTROLLER_H
#include "RGBController.h"
#include <string>
#include <hidapi/hidapi.h>
class CorsairK55RGBPROController
{
public:
CorsairK55RGBPROController(hid_device* dev_handle, const char* path);
~CorsairK55RGBPROController();
std::string GetDeviceLocation();
std::string GetFirmwareString();
std::string GetName();
std::string GetSerialString();
void SetLEDs(std::vector<RGBColor> colors);
void SetLEDsKeyboardLimited(std::vector<RGBColor> colors);
void SetName(std::string device_name);
private:
hid_device* dev;
std::string firmware_version;
std::string location;
std::string name;
device_type type;
void LightingControl();
void SetLEDsKeyboardFull(std::vector<RGBColor> colors);
};
#endif // CORSAIRK55RGBPROCONTROLLER_H

View file

@ -1,15 +1,18 @@
/*-----------------------------------------------------*\
| OpenRGB includes |
\*-----------------------------------------------------*/
#include <hidapi/hidapi.h>
#include "Detector.h"
#include "CorsairPeripheralController.h"
#include "CorsairK100Controller.h"
#include "CorsairK55RGBPROController.h"
#include "LogManager.h"
#include "RGBController.h"
/*-----------------------------------------------------*\
| Corsair Peripheral specific includes |
\*-----------------------------------------------------*/
#include "RGBController_CorsairPeripheral.h"
#include "RGBController_CorsairK100.h"
#include "RGBController_CorsairK55RGBPRO.h"
#include "RGBController_CorsairK65Mini.h"
#include "RGBController_CorsairK95PlatinumXT.h"
#include <hidapi/hidapi.h>
#define CORSAIR_PERIPHERAL_CONTROLLER_NAME "Corsair peripheral"
@ -81,12 +84,6 @@
\*-----------------------------------------------------*/
#define CORSAIR_K100_PID 0x1B7C
/*-----------------------------------------------------*\
| Corsair K55 RGB PRO Keyboard product ID |
| This keyboard uses a separate driver |
\*-----------------------------------------------------*/
#define CORSAIR_K55_RGB_PRO_PID 0x1BA4
/*-----------------------------------------------------*\
| Corsair K65 Mini Keyboard product ID |
| This keyboard uses a separate driver |
@ -120,19 +117,6 @@ void DetectCorsairK100Controllers(hid_device_info* info, const std::string& name
}
} /* DetectCorsairPeripheralControllers() */
void DetectCorsairK55RGBPROControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
CorsairK55RGBPROController* controller = new CorsairK55RGBPROController(dev, info->path);
controller->SetName(name);
RGBController_CorsairK55RGBPRO* rgb_controller = new RGBController_CorsairK55RGBPRO(controller);
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
} /* DetectCorsairK55RGBPROControllers() */
void DetectCorsairK65MiniControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
@ -252,16 +236,12 @@ REGISTER_HID_DETECTOR_I("Corsair ST100 RGB", DetectCorsairPeriphe
\*-----------------------------------------------------------------------------------------------------*/
REGISTER_HID_DETECTOR_IP("Corsair K100", DetectCorsairK100Controllers, CORSAIR_VID, CORSAIR_K100_PID, 1, 0xFF42);
/*-----------------------------------------------------------------------------------------------------*\
| Corsair K55 RGB PRO Keyboard |
\*-----------------------------------------------------------------------------------------------------*/
REGISTER_HID_DETECTOR_IP("Corsair K55 RGB PRO", DetectCorsairK55RGBPROControllers, CORSAIR_VID, CORSAIR_K55_RGB_PRO_PID, 1, 0xFF42);
/*-----------------------------------------------------------------------------------------------------*\
| Corsair K65 Mini Keyboard |
\*-----------------------------------------------------------------------------------------------------*/
REGISTER_HID_DETECTOR_I("Corsair K65 Mini", DetectCorsairK65MiniControllers, CORSAIR_VID, CORSAIR_K65_MINI_PID, 1);
REGISTER_HID_DETECTOR_I("Corsair K65 Mini", DetectCorsairK65MiniControllers, CORSAIR_VID, CORSAIR_K65_MINI_PID, 1);
/*-----------------------------------------------------------------------------------------------------*\
| Corsair K95 Platinum XT Keyboard |
\*-----------------------------------------------------------------------------------------------------*/
REGISTER_HID_DETECTOR_IP("Corsair K95 RGB PLATINUM XT", DetectCorsairK95PlatinumXTControllers, CORSAIR_VID, CORSAIR_K95_PLATINUM_XT_PID, 1, 0xFF42);
REGISTER_HID_DETECTOR_IP("Corsair K95 RGB PLATINUM XT", DetectCorsairK95PlatinumXTControllers, CORSAIR_VID, CORSAIR_K95_PLATINUM_XT_PID, 1, 0xFF42);

View file

@ -1,141 +0,0 @@
/*-----------------------------------------*\
| RGBController_CorsairK55RGBPRO.cpp |
| |
| Driver for Corsair K55 RGB PRO0 Keyboard |
\*-----------------------------------------*/
#include "LogManager.h"
#include "RGBController_CorsairK55RGBPRO.h"
using namespace std::chrono_literals;
/**------------------------------------------------------------------*\
@name Corsair K55 RGB Pro
@category Keyboard
@type USB
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectCorsairK55RGBPROControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_CorsairK55RGBPRO::RGBController_CorsairK55RGBPRO(CorsairK55RGBPROController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetName();
vendor = "Corsair";
description = "Corsair K55 RGB PRO Keyboard Device";
type = DEVICE_TYPE_KEYBOARD;
version = controller->GetFirmwareString();
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
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);
SetupZones();
/*-----------------------------------------------------*\
| The Corsair K55 RGB PRO requires a packet within |
| 1 minutes of sending the lighting change in order |
| to not revert back into rainbow mode. Start a thread |
| to continuously send a keepalive packet every 50 sec |
\*-----------------------------------------------------*/
keepalive_thread_run = true;
keepalive_thread = new std::thread(&RGBController_CorsairK55RGBPRO::KeepaliveThread, this);
}
RGBController_CorsairK55RGBPRO::~RGBController_CorsairK55RGBPRO()
{
/*-----------------------------------------------------*\
| Close keepalive thread |
\*-----------------------------------------------------*/
keepalive_thread_run = false;
keepalive_thread->join();
delete keepalive_thread;
/*---------------------------------------------------------*\
| Delete the matrix map |
\*---------------------------------------------------------*/
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
{
if(zones[zone_index].type == ZONE_TYPE_MATRIX)
{
delete zones[zone_index].matrix_map;
}
}
delete controller;
}
void RGBController_CorsairK55RGBPRO::SetupZones()
{
zone new_zone;
new_zone.name = "Keyboard";
new_zone.type = ZONE_TYPE_LINEAR;
new_zone.leds_min = 5;
new_zone.leds_max = 5;
new_zone.leds_count = 5;
new_zone.matrix_map = NULL;
for(unsigned int led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
{
led new_led;
new_led.name = "Zone " + std::to_string( led_idx );
leds.push_back(new_led);
}
zones.push_back(new_zone);
SetupColors();
}
void RGBController_CorsairK55RGBPRO::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_CorsairK55RGBPRO::DeviceUpdateLEDs()
{
last_update_time = std::chrono::steady_clock::now();
controller->SetLEDs(colors);
}
void RGBController_CorsairK55RGBPRO::UpdateZoneLEDs(int /*zone*/)
{
controller->SetLEDs(colors);
}
void RGBController_CorsairK55RGBPRO::UpdateSingleLED(int /*led*/)
{
controller->SetLEDs(colors);
}
void RGBController_CorsairK55RGBPRO::DeviceUpdateMode()
{
}
void RGBController_CorsairK55RGBPRO::KeepaliveThread()
{
while(keepalive_thread_run.load())
{
if(active_mode == 0)
{
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50000))
{
DeviceUpdateLEDs();
}
}
std::this_thread::sleep_for(3000ms);
}
}

View file

@ -1,33 +0,0 @@
#ifndef RGBCONTROLLER_CORSAIRK55RGBPRO_H
#define RGBCONTROLLER_CORSAIRK55RGBPRO_H
#include "RGBController.h"
#include "CorsairK55RGBPROController.h"
class RGBController_CorsairK55RGBPRO : public RGBController
{
public:
RGBController_CorsairK55RGBPRO(CorsairK55RGBPROController* controller_ptr);
~RGBController_CorsairK55RGBPRO();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
void KeepaliveThread();
private:
CorsairK55RGBPROController* controller;
std::thread* keepalive_thread;
std::atomic<bool> keepalive_thread_run;
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
};
#endif // RGBCONTROLLER_CORSAIRK55RGBPRO_H

View file

@ -0,0 +1,290 @@
/*---------------------------------------------------------------------*\
| CorsairPeripheralV2Controller.cpp |
| |
| Base class for the 08 based Corsair protocol |
| |
| Chris M (Dr_No) 07 Aug 2022 |
| |
\*---------------------------------------------------------------------*/
#include "CorsairPeripheralV2Controller.h"
CorsairPeripheralV2Controller::CorsairPeripheralV2Controller(hid_device* dev_handle, const char* path, std::string name, uint16_t pid)
{
const uint8_t sz = HID_MAX_STR;
wchar_t tmp[sz];
dev = dev_handle;
location = path;
hid_get_manufacturer_string(dev, tmp, sz);
std::wstring wName = std::wstring(tmp);
device_name = std::string(wName.begin(), wName.end());
hid_get_product_string(dev, tmp, sz);
wName = std::wstring(tmp);
device_name.append(" ").append(std::string(wName.begin(), wName.end()));
for(size_t i = 0; i < CORSAIR_DEVICE_COUNT; i++)
{
if(device_list[i]->pid == pid)
{
/*---------------------------------------------------------*\
| Set device ID |
\*---------------------------------------------------------*/
device_index = i;
write_cmd = CORSAIR_V2_WRITE_ID + device_list[device_index]->wireless;
}
}
/*---------------------------------------------------------*\
| Possibly is Wireless connected? |
\*---------------------------------------------------------*/
GetAddress(0x11);
}
CorsairPeripheralV2Controller::~CorsairPeripheralV2Controller()
{
hid_close(dev);
}
const corsair_device* CorsairPeripheralV2Controller::GetDeviceData()
{
return device_list[device_index];
}
std::string CorsairPeripheralV2Controller::GetDeviceLocation()
{
return("HID: " + location);
}
std::string CorsairPeripheralV2Controller::GetFirmwareString()
{
return "";
}
std::string CorsairPeripheralV2Controller::GetName()
{
return device_name;
}
std::string CorsairPeripheralV2Controller::GetSerialString()
{
const uint8_t sz = HID_MAX_STR;
wchar_t tmp[sz];
int ret = hid_get_serial_number_string(dev, tmp, sz);
if(ret != 0)
{
LOG_DEBUG("[%s] Get HID Serial string failed", device_name.c_str());
return("");
}
std::wstring w_tmp = std::wstring(tmp);
std::string serial = std::string(w_tmp.begin(), w_tmp.end());
return serial;
}
void CorsairPeripheralV2Controller::SetRenderMode(corsair_v2_device_mode mode)
{
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
/*---------------------------------------------------------*\
| Set Mode |
\*---------------------------------------------------------*/
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_SET;
buffer[3] = CORSAIR_V2_VALUE_MODE;
buffer[5] = mode;
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
}
void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1, uint8_t opt2)
{
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
/*---------------------------------------------------------*\
| The Corsair command is the same for each initialisation |
| packet and the registers and options differ for |
| each peripheral supported by the protocol |
\*---------------------------------------------------------*/
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_GET;
buffer[3] = opt1;
buffer[5] = 0x00;
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
/*---------------------------------------------------------*\
| Open a RGB lighting handle |
\*---------------------------------------------------------*/
buffer[2] = 0x0D;
buffer[3] = 0x00;
buffer[4] = 0x01;
buffer[5] = opt2;
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
}
void CorsairPeripheralV2Controller::GetAddress(uint8_t address)
{
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
uint8_t read[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
memset(read, 0, CORSAIR_V2_WRITE_SIZE);
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_GET;
buffer[3] = address;
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
hid_read(dev, read, CORSAIR_V2_WRITE_SIZE);
LOG_DEBUG("[%s] GetAddress %02X - %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X", device_name.c_str(),
address, read[0], read[1], read[2], read[3], read[4], read[5], read[6], read[7], read[8], read[9]);
}
void CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1)
{
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_START_TX;
buffer[3] = opt1;
buffer[4] = 0x01;
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
}
void CorsairPeripheralV2Controller::StopTransaction(uint8_t opt1)
{
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_STOP_TX;
buffer[3] = 0x01;
buffer[4] = opt1;
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
}
void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size)
{
const uint8_t offset1 = 8;
const uint8_t offset2 = 4;
uint16_t remaining = data_size;
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
StartTransaction(0);
/*---------------------------------------------------------*\
| Set the data header in packet 1 with the data length |
| signaling how many packets to expect to the device |
\*---------------------------------------------------------*/
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_BLK_W1;
buffer[4] = data_size & 0xFF;
buffer[5] = data_size >> 8;
/*---------------------------------------------------------*\
| Check if the data needs more than 1 packet |
\*---------------------------------------------------------*/
uint8_t copy_bytes = CORSAIR_V2_WRITE_SIZE - offset1;
if(remaining < copy_bytes)
{
copy_bytes = remaining;
}
memcpy(&buffer[offset1], &data[0], copy_bytes);
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
remaining -= copy_bytes;
buffer[2] = CORSAIR_V2_CMD_BLK_WN;
copy_bytes = CORSAIR_V2_WRITE_SIZE - offset2;
/*---------------------------------------------------------*\
| Send the remaining packets |
\*---------------------------------------------------------*/
while(remaining)
{
uint8_t index = data_size - remaining;
if(remaining < copy_bytes)
{
memset(&buffer[offset2], 0, copy_bytes);
copy_bytes = remaining;
}
memcpy(&buffer[offset2], &data[index], copy_bytes);
hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE);
remaining -= copy_bytes;
}
StopTransaction(0);
}
void CorsairPeripheralV2Controller::UpdateHWMode(uint16_t mode, corsair_v2_color color_mode, uint8_t speed,
uint8_t direction, uint8_t brightness, std::vector<RGBColor> colors)
{
/*---------------------------------------------------------*\
| If we are switching to `Direct` mode |
| set device in software mode |
\*---------------------------------------------------------*/
if(mode == CORSAIR_V2_MODE_DIRECT)
{
SetRenderMode(CORSAIR_V2_MODE_SW);
return;
}
/*
SetRenderMode(CORSAIR_V2_MODE_HW);
uint8_t buffer[CORSAIR_V2_WRITE_SIZE];
memset(buffer, 0, CORSAIR_V2_WRITE_SIZE);
*/
/*---------------------------------------------------------*\
| Set the data header in packet 1 with the data length |
| signaling how many packets to expect to the device |
\*---------------------------------------------------------*/
/*
buffer[1] = write_cmd;
buffer[2] = CORSAIR_V2_CMD_BLK_W1;
buffer[3] = CORSAIR_V2_MODE_HW;
buffer[4] = 0x30;
buffer[8] = mode & 0xFF;
buffer[9] = mode >> 8;
buffer[10] = CORSAIR_V2_COLOR_SPECIFIC;
buffer[11] = speed;
buffer[14] = colors.size();
for(size_t i = 0; i < colors.size(); ++i)
{
uint8_t offset = 15 + (i * 4);
buffer[offset] = brightness;
buffer[offset + 1] = RGBGetBValue(colors[i]);
buffer[offset + 2] = RGBGetGValue(colors[i]);
buffer[offset + 3] = RGBGetRValue(colors[i]);
}
*/
}

View file

@ -0,0 +1,95 @@
/*---------------------------------------------------------------------*\
| CorsairPeripheralV2Controller.h |
| |
| Base class for the 08 based Corsair protocol |
| |
| Chris M (Dr_No) 07 Aug 2022 |
| |
\*---------------------------------------------------------------------*/
#pragma once
#include <string>
#include <vector>
#include <hidapi/hidapi.h>
#include "LogManager.h"
#include "RGBController.h"
#include "CorsairPeripheralV2Devices.h"
#define NA 0xFFFFFFFF
#define HID_MAX_STR 255
#define CORSAIR_V2_WRITE_ID 8
#define CORSAIR_V2_VALUE_MODE 3
#define CORSAIR_V2_WRITE_SIZE 65
#define CORSAIR_V2_BRIGHTNESS_MIN 0
#define CORSAIR_V2_BRIGHTNESS_MAX 0xFF
enum corsair_v2_cmd
{
CORSAIR_V2_CMD_SET = 0x01, /* Command for setting values */
CORSAIR_V2_CMD_GET = 0x02, /* Command for getting values */
CORSAIR_V2_CMD_STOP_TX = 0x05, /* Finish Transaction */
CORSAIR_V2_CMD_BLK_W1 = 0x06, /* Block write packet 1 */
CORSAIR_V2_CMD_BLK_WN = 0x07, /* Block write remaining packets */
CORSAIR_V2_CMD_START_TX = 0x0D, /* Start Transaction */
};
enum corsair_v2_mode
{
CORSAIR_V2_MODE_DIRECT = 0x0000,
CORSAIR_V2_MODE_STATIC = 0x207E,
CORSAIR_V2_MODE_FLASHING = 0xAD4F,
CORSAIR_V2_MODE_BREATHING = 0xA5FA,
CORSAIR_V2_MODE_SPECTRUM = 0x7BFF,
CORSAIR_V2_MODE_RAINBOW = 0xB94C,
CORSAIR_V2_MODE_RAIN = 0xA07E,
CORSAIR_V2_MODE_SPIRAL = 0xAB87,
CORSAIR_V2_MODE_WATERCOLOR = 0x0022,
CORSAIR_V2_MODE_REACTIVE = 0xB1F9,
CORSAIR_V2_MODE_RIPPLE = 0x09A2,
CORSAIR_V2_MODE_VISOR = 0x90C0
};
enum corsair_v2_color
{
CORSAIR_V2_COLOR_NONE = 0x00,
CORSAIR_V2_COLOR_SPECIFIC = 0x01,
CORSAIR_V2_COLOR_RANDOM = 0x02,
CORSAIR_V2_COLOR_UNKNOWN = 0x03
};
class CorsairPeripheralV2Controller
{
public:
CorsairPeripheralV2Controller(hid_device* dev_handle, const char* path, std::string name, uint16_t pid);
~CorsairPeripheralV2Controller();
std::string GetDeviceLocation();
std::string GetFirmwareString();
std::string GetName();
std::string GetSerialString();
const corsair_device* GetDeviceData();
void SetRenderMode(corsair_v2_device_mode mode);
void LightingControl(uint8_t opt1, uint8_t opt2);
void SetLEDs(uint8_t *data, uint16_t data_size);
void UpdateHWMode(uint16_t mode, corsair_v2_color color_mode, uint8_t speed,
uint8_t direction, uint8_t brightness, std::vector<RGBColor> colors);
virtual void SetLedsDirect(std::vector<RGBColor> colors) = 0;
private:
void GetAddress(uint8_t address);
void StartTransaction(uint8_t opt1);
void StopTransaction(uint8_t opt1);
hid_device* dev;
uint8_t write_cmd;
uint16_t device_index;
std::string firmware_version;
std::string location;
std::string device_name;
};

View file

@ -0,0 +1,44 @@
/*-----------------------------------------------------*\
| OpenRGB includes |
\*-----------------------------------------------------*/
#include <hidapi/hidapi.h>
#include "Detector.h"
#include "LogManager.h"
#include "RGBController.h"
/*-----------------------------------------------------*\
| Corsair Peripheral specific includes |
\*-----------------------------------------------------*/
#include "CorsairPeripheralV2Devices.h"
#include "RGBController_CorsairV2Software.h"
#define CORSAIR_PERIPHERAL_CONTROLLER_NAME "Corsair V2 Peripheral"
/*-----------------------------------------------------*\
| Corsair vendor ID |
\*-----------------------------------------------------*/
#define CORSAIR_VID 0x1B1C
void DetectCorsairV2SoftwareControllers(hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
if(dev)
{
CorsairPeripheralV2SWController* controller = new CorsairPeripheralV2SWController(dev, info->path, name, info->product_id);
RGBController_CorsairV2SW* rgb_controller = new RGBController_CorsairV2SW(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
} /* DetectCorsairV2SoftwareControllers() */
/*-----------------------------------------------------------------------------------------------------*\
| Keyboards |
\*-----------------------------------------------------------------------------------------------------*/
REGISTER_HID_DETECTOR_IP("Corsair K55 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K55_RGB_PRO_PID, 1, 0xFF42);
/*-----------------------------------------------------------------------------------------------------*\
| Mousemat |
\*-----------------------------------------------------------------------------------------------------*/
REGISTER_HID_DETECTOR_IP("Corsair MM700", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_MM700_PID, 1, 0xFF42);

View file

@ -0,0 +1,159 @@
#pragma once
#include <string>
#include "RGBController.h"
#include "RGBControllerKeyNames.h"
#define CORSAIR_ZONES_MAX 5
enum corsair_v2_device_mode
{
CORSAIR_V2_MODE_HW = 0x01, /* Hardware RGB mode */
CORSAIR_V2_MODE_SW = 0x02, /* Software RGB mode */
};
typedef struct
{
std::string name;
zone_type type;
uint8_t rows;
uint8_t cols;
} corsair_zone;
typedef struct
{
uint8_t zone;
uint8_t row;
uint8_t col;
const char* name;
} corsair_led;
typedef struct
{
uint16_t pid;
bool wireless;
device_type type;
uint8_t supports;
uint8_t rows;
uint8_t cols;
const corsair_zone* zones[CORSAIR_ZONES_MAX];
const corsair_led* layout;
uint16_t layout_size;
} corsair_device;
/*-----------------------------------------------------*\
| Corsair V2 Protocol Keyboards |
\*-----------------------------------------------------*/
#define CORSAIR_K55_RGB_PRO_PID 0x1BA4
/*-----------------------------------------------------*\
| Corsair V2 Protocol Mousemats |
\*-----------------------------------------------------*/
#define CORSAIR_MM700_PID 0x1B9B
/*-------------------------------------------------------------*\
| Corsair K55 RGB Pro 1B1C:1BA4 |
| |
| Zone "Keyboard" |
| Linear |
| 1 Row, 6 Columns |
\*-------------------------------------------------------------*/
static const corsair_zone k55_rgb_pro_zone =
{
ZONE_EN_KEYBOARD,
ZONE_TYPE_LINEAR,
1,
6
};
static const corsair_device k55_rgb_pro_device =
{
CORSAIR_K55_RGB_PRO_PID,
false,
DEVICE_TYPE_KEYBOARD,
CORSAIR_V2_MODE_SW,
1,
6,
{
&k55_rgb_pro_zone,
nullptr,
nullptr,
nullptr,
nullptr
},
nullptr,
0
};
/*-------------------------------------------------------------*\
| Corsair MM700 1B1C:1B9B |
| |
| Zone "Logo" |
| Single |
| |
| Zone "Edge" |
| Linear |
| 1 Row, 2 Columns |
\*-------------------------------------------------------------*/
static const corsair_zone mm700_right_zone =
{
"Right",
ZONE_TYPE_SINGLE,
1,
1
};
static const corsair_zone mm700_logo_zone =
{
"Logo",
ZONE_TYPE_SINGLE,
1,
1
};
static const corsair_zone mm700_left_zone =
{
"Left",
ZONE_TYPE_SINGLE,
1,
1
};
static const corsair_device mm700_device =
{
CORSAIR_MM700_PID,
false,
DEVICE_TYPE_MOUSEMAT,
CORSAIR_V2_MODE_SW,
1,
3,
{
&mm700_left_zone,
&mm700_right_zone,
&mm700_logo_zone,
nullptr,
nullptr
},
nullptr,
0
};
/*-------------------------------------------------------------------------*\
| DEVICE MASTER LIST |
\*-------------------------------------------------------------------------*/
#define CORSAIR_DEVICE_COUNT (sizeof(device_list) / sizeof(device_list[ 0 ]))
static const corsair_device* device_list[] =
{
/*-----------------------------------------------------------------*\
| KEYBOARDS |
\*-----------------------------------------------------------------*/
&k55_rgb_pro_device,
/*-----------------------------------------------------------------*\
| MOUSEMATS |
\*-----------------------------------------------------------------*/
&mm700_device,
};

View file

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------*\
| CorsairPeripheralV2SoftwareController.cpp |
| |
| Common driver for the newer Corsair peripherals that use |
| the `08` based USB protocol |
| |
| Chris M (Dr_No) 11 Aug 2022 |
\*---------------------------------------------------------------------*/
#pragma once
#include "LogManager.h"
#include "CorsairPeripheralV2SoftwareController.h"
CorsairPeripheralV2SWController::CorsairPeripheralV2SWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid) : CorsairPeripheralV2Controller(dev_handle, path, name, pid)
{
SetRenderMode(CORSAIR_V2_MODE_SW);
LightingControl(0x5F, 0x00);
}
CorsairPeripheralV2SWController::~CorsairPeripheralV2SWController()
{
}
void CorsairPeripheralV2SWController::SetLedsDirect(std::vector<RGBColor>colors)
{
uint16_t count = colors.size();
uint16_t green = count;
uint16_t blue = count * 2;
uint16_t length = count * 3;
uint8_t* buffer = new uint8_t[length];
memset(buffer, 0, length);
for(std::size_t i = 0; i < count; i++)
{
RGBColor color = colors[i];
buffer[i] = RGBGetRValue(color);
buffer[green + i] = RGBGetGValue(color);
buffer[blue + i] = RGBGetBValue(color);
}
SetLEDs(buffer, length);
delete[] buffer;
}

View file

@ -0,0 +1,27 @@
/*---------------------------------------------------------------------*\
| CorsairPeripheralV2SoftwareController.h |
| |
| Common driver for the newer Corsair peripherals that use |
| the `08` based USB protocol |
| |
| Chris M (Dr_No) 11 Aug 2022 |
\*---------------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CorsairPeripheralV2Controller.h"
#include <string>
#include <hidapi/hidapi.h>
class CorsairPeripheralV2SWController : public CorsairPeripheralV2Controller
{
public:
CorsairPeripheralV2SWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid);
~CorsairPeripheralV2SWController();
void SetLedsDirect(std::vector<RGBColor> colors);
private:
};

View file

@ -0,0 +1,251 @@
/*---------------------------------------------------------------------*\
| RGBController_CorsairV2SoftwareController.cpp |
| |
| Common driver for the newer Corsair peripherals that use |
| the `08` based USB protocol |
| |
| Chris M (Dr_No) 11 Aug 2022 |
\*---------------------------------------------------------------------*/
#include "LogManager.h"
#include "RGBController_CorsairV2Software.h"
using namespace std::chrono_literals;
/**------------------------------------------------------------------*\
@name Corsair K55 RGB Pro
@category Keyboard
@type USB
@save :x:
@direct :white_check_mark:
@effects :x:
@detectors DetectCorsairK55RGBPROControllers
@comment
\*-------------------------------------------------------------------*/
RGBController_CorsairV2SW::RGBController_CorsairV2SW(CorsairPeripheralV2Controller *controller_ptr)
{
controller = controller_ptr;
const corsair_device* corsair = controller->GetDeviceData();
vendor = "Corsair";
description = controller->GetName();
type = corsair->type;
version = controller->GetFirmwareString();
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
if(corsair->supports & CORSAIR_V2_MODE_SW)
{
mode Direct;
Direct.name = "Direct";
Direct.value = CORSAIR_V2_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
}
if(corsair->supports & CORSAIR_V2_MODE_HW)
{
mode Static;
Static.name = "Static";
Static.value = CORSAIR_V2_MODE_STATIC;
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Static.colors_min = 1;
Static.colors_max = 1;
Static.colors.resize(Static.colors_max);
Static.brightness_min = CORSAIR_V2_BRIGHTNESS_MIN;
Static.brightness_max = CORSAIR_V2_BRIGHTNESS_MAX;
Static.brightness = CORSAIR_V2_BRIGHTNESS_MAX;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
modes.push_back(Static);
}
SetupZones();
/*-----------------------------------------------------*\
| The Corsair K55 RGB PRO requires a packet within |
| 1 minutes of sending the lighting change in order |
| to not revert back into rainbow mode. Start a thread |
| to continuously send a keepalive packet every 50 sec |
\*-----------------------------------------------------*/
keepalive_thread_run = true;
keepalive_thread = new std::thread(&RGBController_CorsairV2SW::KeepaliveThread, this);
}
RGBController_CorsairV2SW::~RGBController_CorsairV2SW()
{
/*-----------------------------------------------------*\
| Close keepalive thread |
\*-----------------------------------------------------*/
keepalive_thread_run = false;
keepalive_thread->join();
delete keepalive_thread;
/*---------------------------------------------------------*\
| Delete the matrix map |
\*---------------------------------------------------------*/
for(unsigned int zone_index = 0; zone_index < zones.size(); zone_index++)
{
if(zones[zone_index].type == ZONE_TYPE_MATRIX)
{
delete zones[zone_index].matrix_map;
}
}
delete controller;
}
void RGBController_CorsairV2SW::SetupZones()
{
const corsair_device* corsair = controller->GetDeviceData();
/*---------------------------------------------------------*\
| Fill in zones from the device data |
\*---------------------------------------------------------*/
for(size_t i = 0; i < CORSAIR_ZONES_MAX; i++)
{
if(corsair->zones[i] == NULL)
{
break;
}
else
{
zone new_zone;
new_zone.name = corsair->zones[i]->name;
new_zone.type = corsair->zones[i]->type;
new_zone.leds_count = corsair->zones[i]->rows * corsair->zones[i]->cols;
if(new_zone.type == ZONE_TYPE_MATRIX)
{
matrix_map_type * new_map = new matrix_map_type;
new_zone.matrix_map = new_map;
new_map->height = corsair->zones[i]->rows;
new_map->width = corsair->zones[i]->cols;
new_map->map = new unsigned int[new_map->height * new_map->width];
for(unsigned int y = 0; y < new_map->height; y++)
{
for(unsigned int x = 0; x < new_map->width; x++)
{
new_map->map[(y * new_map->width) + x] = (y * new_map->width) + x;
}
}
/*---------------------------------------------------------*\
| Create LEDs for the Matrix zone |
\*---------------------------------------------------------*/
uint8_t blanks = 0;
for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
{
led new_led;
bool not_found = true;
for(size_t layout_index = 0; layout_index < corsair->layout_size; layout_index++)
{
uint8_t row = layout_index / new_map->width;
uint8_t col = layout_index % new_map->width;
if( i == corsair->layout[layout_index].zone &&
row == corsair->layout[layout_index].row &&
col == corsair->layout[layout_index].col )
{
new_led.name = corsair->layout[layout_index].name;
not_found = false;
break;
}
}
/*-----------------------------------------------------------------*\
| If this is the "Keyboard" zone and key was not found in the map |
| then change the value of the key to hide it from view |
\*-----------------------------------------------------------------*/
if(not_found && new_zone.name == ZONE_EN_KEYBOARD)
{
new_zone.matrix_map->map[led_idx] = NA;
blanks++;
}
else
{
leds.push_back(new_led);
}
}
new_zone.leds_count -= blanks;
}
else
{
new_zone.matrix_map = NULL;
/*---------------------------------------------------------*\
| Create LEDs for the Linear / Single zone |
\*---------------------------------------------------------*/
for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
{
led new_led;
new_led.name = new_zone.name + " ";
new_led.name.append(std::to_string( led_idx ));
new_led.value = leds.size();
leds.push_back(new_led);
}
}
LOG_DEBUG("[%s] Creating a %s zone: %s with %d LEDs", name.c_str(),
((new_zone.type == ZONE_TYPE_MATRIX) ? "matrix": "linear"),
new_zone.name, new_zone.leds_count);
new_zone.leds_min = new_zone.leds_count;
new_zone.leds_max = new_zone.leds_count;
zones.push_back(new_zone);
}
}
SetupColors();
}
void RGBController_CorsairV2SW::ResizeZone(int /*zone*/, int /*new_size*/)
{
/*---------------------------------------------------------*\
| This device does not support resizing zones |
\*---------------------------------------------------------*/
}
void RGBController_CorsairV2SW::DeviceUpdateLEDs()
{
last_update_time = std::chrono::steady_clock::now();
controller->SetLedsDirect(colors);
}
void RGBController_CorsairV2SW::UpdateZoneLEDs(int /*zone*/)
{
controller->SetLedsDirect(colors);
}
void RGBController_CorsairV2SW::UpdateSingleLED(int /*led*/)
{
controller->SetLedsDirect(colors);
}
void RGBController_CorsairV2SW::DeviceUpdateMode()
{
}
void RGBController_CorsairV2SW::KeepaliveThread()
{
while(keepalive_thread_run.load())
{
if(active_mode == 0)
{
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50000))
{
DeviceUpdateLEDs();
}
}
std::this_thread::sleep_for(3000ms);
}
}

View file

@ -0,0 +1,39 @@
/*---------------------------------------------------------------------*\
| RGBController_CorsairV2SoftwareController.cpp |
| |
| Common driver for the newer Corsair peripherals that use |
| the `08` based USB protocol |
| |
| Chris M (Dr_No) 11 Aug 2022 |
\*---------------------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "CorsairPeripheralV2Controller.h"
#include "CorsairPeripheralV2SoftwareController.h"
class RGBController_CorsairV2SW : public RGBController
{
public:
RGBController_CorsairV2SW(CorsairPeripheralV2Controller* controller_ptr);
~RGBController_CorsairV2SW();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
void KeepaliveThread();
private:
CorsairPeripheralV2Controller* controller;
std::thread* keepalive_thread;
std::atomic<bool> keepalive_thread_run;
std::chrono::time_point
<std::chrono::steady_clock> last_update_time;
};

View file

@ -318,14 +318,16 @@ HEADERS +=
Controllers/CorsairLightingNodeController/RGBController_CorsairLightingNode.h \
Controllers/CorsairPeripheralController/CorsairPeripheralController.h \
Controllers/CorsairPeripheralController/CorsairK100Controller.h \
Controllers/CorsairPeripheralController/CorsairK55RGBPROController.h \
Controllers/CorsairPeripheralController/CorsairK65MiniController.h \
Controllers/CorsairPeripheralController/CorsairK95PlatinumXTController.h \
Controllers/CorsairPeripheralController/RGBController_CorsairPeripheral.h \
Controllers/CorsairPeripheralController/RGBController_CorsairK100.h \
Controllers/CorsairPeripheralController/RGBController_CorsairK55RGBPRO.h \
Controllers/CorsairPeripheralController/RGBController_CorsairK65Mini.h \
Controllers/CorsairPeripheralController/RGBController_CorsairK95PlatinumXT.h \
Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h \
Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h \
Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.h \
Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.h \
Controllers/CorsairVengeanceController/CorsairVengeanceController.h \
Controllers/CorsairVengeanceController/RGBController_CorsairVengeance.h \
Controllers/CorsairVengeanceProController/CorsairVengeanceProController.h \
@ -805,14 +807,16 @@ SOURCES +=
Controllers/CorsairPeripheralController/CorsairPeripheralController.cpp \
Controllers/CorsairPeripheralController/CorsairPeripheralControllerDetect.cpp \
Controllers/CorsairPeripheralController/CorsairK100Controller.cpp \
Controllers/CorsairPeripheralController/CorsairK55RGBPROController.cpp \
Controllers/CorsairPeripheralController/CorsairK65MiniController.cpp \
Controllers/CorsairPeripheralController/CorsairK95PlatinumXTController.cpp \
Controllers/CorsairPeripheralController/RGBController_CorsairPeripheral.cpp \
Controllers/CorsairPeripheralController/RGBController_CorsairK100.cpp \
Controllers/CorsairPeripheralController/RGBController_CorsairK55RGBPRO.cpp \
Controllers/CorsairPeripheralController/RGBController_CorsairK65Mini.cpp \
Controllers/CorsairPeripheralController/RGBController_CorsairK95PlatinumXT.cpp \
Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp \
Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2ControllerDetect.cpp \
Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.cpp \
Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp \
Controllers/CorsairVengeanceController/CorsairVengeanceController.cpp \
Controllers/CorsairVengeanceController/CorsairVengeanceControllerDetect.cpp \
Controllers/CorsairVengeanceController/RGBController_CorsairVengeance.cpp \