Initial commit for the Corsair M55 mouse
* Added config to CorsairPeripheralV2Devices * Adding device config to CorsairPeripheralV2Devices.cpp * Extending the base CorsairPeripheralV2Controller to CorsairPeripheralV2HWController to account for HW modes * Minor adjustments to the CorsairPeripheralV2SWController to accommodate * Resolves #1951master
parent
549a631541
commit
baf5d30b27
@ -0,0 +1,89 @@
|
||||
/*---------------------------------------------------------------------*\
|
||||
| CorsairPeripheralV2HardwareController.cpp |
|
||||
| |
|
||||
| Driver for the newer Corsair peripherals that use the '08' |
|
||||
| based USB protocol and support hardware lighting modes. |
|
||||
| |
|
||||
| Chris M (Dr_No) 07 Dec 2022 |
|
||||
\*---------------------------------------------------------------------*/
|
||||
|
||||
#include "LogManager.h"
|
||||
#include "CorsairPeripheralV2HardwareController.h"
|
||||
|
||||
CorsairPeripheralV2HWController::CorsairPeripheralV2HWController(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);
|
||||
}
|
||||
|
||||
CorsairPeripheralV2HWController::~CorsairPeripheralV2HWController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CorsairPeripheralV2HWController::SetLedsDirect(std::vector<RGBColor *>colors)
|
||||
{
|
||||
switch(corsair_v2_device_list[device_index]->protocol)
|
||||
{
|
||||
case CORSAIR_V2_TYPE_HW_TRIPLETS:
|
||||
SetLedsDirectTriplets(colors);
|
||||
break;
|
||||
case CORSAIR_V2_TYPE_HW_COLOUR_BLOCK:
|
||||
SetLedsDirectColourBlocks(colors);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("[%s] Error setting Direct mode: Device supportes returned %i", device_name.c_str(),
|
||||
corsair_v2_device_list[device_index]->protocol);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CorsairPeripheralV2HWController::SetLedsDirectColourBlocks(std::vector<RGBColor *>colors)
|
||||
{
|
||||
uint16_t count = colors.size();
|
||||
uint16_t green = count + CORSAIR_V2HW_DATA_OFFSET;
|
||||
uint16_t blue = (count * 2) + CORSAIR_V2HW_DATA_OFFSET;
|
||||
uint16_t length = (count * 3) + CORSAIR_V2HW_DATA_OFFSET;
|
||||
uint8_t* buffer = new uint8_t[length];
|
||||
|
||||
memset(buffer, 0, length);
|
||||
|
||||
buffer[0] = CORSAIR_V2_MODE_DIRECT & 0xFF;
|
||||
buffer[1] = CORSAIR_V2_MODE_DIRECT >> 8;
|
||||
for(std::size_t i = 0; i < count; i++)
|
||||
{
|
||||
RGBColor color = *colors[i];
|
||||
std::size_t idx = i + CORSAIR_V2HW_DATA_OFFSET;
|
||||
|
||||
buffer[idx] = RGBGetRValue(color);
|
||||
buffer[idx + green] = RGBGetGValue(color);
|
||||
buffer[idx + blue] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
SetLEDs(buffer, length);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void CorsairPeripheralV2HWController::SetLedsDirectTriplets(std::vector<RGBColor *>colors)
|
||||
{
|
||||
uint16_t count = colors.size();
|
||||
uint16_t length = (count * 3) + CORSAIR_V2HW_DATA_OFFSET;
|
||||
uint8_t* buffer = new uint8_t[length];
|
||||
|
||||
memset(buffer, 0, length);
|
||||
|
||||
buffer[0] = CORSAIR_V2_MODE_DIRECT & 0xFF;
|
||||
buffer[1] = CORSAIR_V2_MODE_DIRECT >> 8;
|
||||
for(std::size_t i = 0; i < count; i++)
|
||||
{
|
||||
RGBColor color = *colors[i];
|
||||
std::size_t idx = (i * 3) + CORSAIR_V2HW_DATA_OFFSET;
|
||||
|
||||
buffer[idx] = RGBGetRValue(color);
|
||||
buffer[idx + 1] = RGBGetGValue(color);
|
||||
buffer[idx + 2] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
SetLEDs(buffer, length);
|
||||
delete[] buffer;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
/*---------------------------------------------------------------------*\
|
||||
| CorsairPeripheralV2HardwareController.h |
|
||||
| |
|
||||
| Driver for the newer Corsair peripherals that use the '08' |
|
||||
| based USB protocol and support hardware lighting modes. |
|
||||
| |
|
||||
| Chris M (Dr_No) 07 Dec 2022 |
|
||||
\*---------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "CorsairPeripheralV2Controller.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#undef CORSAIR_V2_WRITE_SIZE
|
||||
#define CORSAIR_V2_WRITE_SIZE 1025
|
||||
#define CORSAIR_V2HW_DATA_OFFSET 2
|
||||
|
||||
class CorsairPeripheralV2HWController : public CorsairPeripheralV2Controller
|
||||
{
|
||||
public:
|
||||
CorsairPeripheralV2HWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid);
|
||||
~CorsairPeripheralV2HWController();
|
||||
|
||||
void SetLedsDirect(std::vector<RGBColor *> colors);
|
||||
|
||||
private:
|
||||
void SetLedsDirectColourBlocks(std::vector<RGBColor *> colors);
|
||||
void SetLedsDirectTriplets(std::vector<RGBColor *> colors);
|
||||
};
|
||||
@ -0,0 +1,247 @@
|
||||
/*---------------------------------------------------------------------*\
|
||||
| RGBController_CorsairV2HardwareController.cpp |
|
||||
| |
|
||||
| Driver for the newer Corsair peripherals that use the '08' |
|
||||
| based USB protocol and support hardware lighting modes. |
|
||||
| |
|
||||
| Chris M (Dr_No) 10 Dec 2022 |
|
||||
\*---------------------------------------------------------------------*/
|
||||
#include "LogManager.h"
|
||||
#include "RGBController_CorsairV2Hardware.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Corsair Peripherals V2 Hardware
|
||||
@category Keyboard
|
||||
@type USB
|
||||
@save :robot:
|
||||
@direct :white_check_mark:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectCorsairV2HardwareControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_CorsairV2HW::RGBController_CorsairV2HW(CorsairPeripheralV2Controller *controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
const corsair_v2_device* corsair = controller->GetDeviceData();
|
||||
|
||||
vendor = "Corsair";
|
||||
description = controller->GetName();
|
||||
type = corsair->type;
|
||||
version = controller->GetFirmwareString();
|
||||
location = controller->GetDeviceLocation();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
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);
|
||||
|
||||
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_CorsairV2HW::KeepaliveThread, this);
|
||||
}
|
||||
|
||||
RGBController_CorsairV2HW::~RGBController_CorsairV2HW()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| 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_CorsairV2HW::SetupZones()
|
||||
{
|
||||
unsigned int max_led_value = 0;
|
||||
const corsair_v2_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;
|
||||
|
||||
if(new_zone.type == ZONE_TYPE_MATRIX)
|
||||
{
|
||||
new_zone.leds_count = corsair->layout_size;
|
||||
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];
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create an empty matrix |
|
||||
\*---------------------------------------------------------*/
|
||||
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] = NA;
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create LEDs for the Matrix zone |
|
||||
| Place keys in the layout to populate the matrix |
|
||||
\*---------------------------------------------------------*/
|
||||
for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
|
||||
new_led.name = corsair->layout[led_idx].name;
|
||||
new_led.value = corsair->layout[led_idx].index;
|
||||
max_led_value = std::max(max_led_value, new_led.value);
|
||||
leds.push_back(new_led);
|
||||
|
||||
uint8_t layout_index = (corsair->layout[led_idx].row * new_map->width)
|
||||
+ corsair->layout[led_idx].col;
|
||||
new_map->map[layout_index] = led_idx;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Add 1 the max_led_value to account for the 0th index |
|
||||
\*---------------------------------------------------------*/
|
||||
max_led_value++;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_zone.leds_count = corsair->zones[i]->rows * corsair->zones[i]->cols;
|
||||
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);
|
||||
}
|
||||
|
||||
max_led_value = std::max(max_led_value, (unsigned int)leds.size());
|
||||
}
|
||||
|
||||
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.c_str(), 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();
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Create a buffer map of pointers which contains the |
|
||||
| layout order of colors the device expects. |
|
||||
\*---------------------------------------------------------*/
|
||||
for(size_t led_idx = 0; led_idx < max_led_value; led_idx++)
|
||||
{
|
||||
buffer_map.push_back(&null_color);
|
||||
}
|
||||
|
||||
for(size_t led_idx = 0; led_idx < leds.size(); led_idx++)
|
||||
{
|
||||
buffer_map[leds[led_idx].value] = &colors[led_idx];
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_CorsairV2HW::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_CorsairV2HW::DeviceUpdateLEDs()
|
||||
{
|
||||
last_update_time = std::chrono::steady_clock::now();
|
||||
|
||||
controller->SetLedsDirect(buffer_map);
|
||||
}
|
||||
|
||||
void RGBController_CorsairV2HW::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
controller->SetLedsDirect(buffer_map);
|
||||
}
|
||||
|
||||
void RGBController_CorsairV2HW::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
controller->SetLedsDirect(buffer_map);
|
||||
}
|
||||
|
||||
void RGBController_CorsairV2HW::DeviceUpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_CorsairV2HW::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(30000ms);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------*\
|
||||
| RGBController_CorsairV2HardwareController.h |
|
||||
| |
|
||||
| Driver for the newer Corsair peripherals that use the '08' |
|
||||
| based USB protocol and support hardware lighting modes. |
|
||||
| |
|
||||
| Chris M (Dr_No) 10 Dec 2022 |
|
||||
\*---------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "CorsairPeripheralV2Controller.h"
|
||||
#include "CorsairPeripheralV2HardwareController.h"
|
||||
|
||||
class RGBController_CorsairV2HW : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_CorsairV2HW(CorsairPeripheralV2Controller* controller_ptr);
|
||||
~RGBController_CorsairV2HW();
|
||||
|
||||
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;
|
||||
|
||||
RGBColor null_color = 0;
|
||||
std::vector<RGBColor *> buffer_map;
|
||||
|
||||
std::thread* keepalive_thread;
|
||||
std::atomic<bool> keepalive_thread_run;
|
||||
std::chrono::time_point
|
||||
<std::chrono::steady_clock> last_update_time;
|
||||
|
||||
};
|
||||
Loading…
Reference in New Issue