Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -0,0 +1,189 @@
/*---------------------------------------------------------*\
| RGBController_RazerKrakenV3.cpp |
| |
| RGBController for Razer devices with 13-byte reports |
| |
| Greg Sandstrom (superstrom) 1 Nov 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <vector>
#include "RazerDevices.h"
#include "RGBController_RazerKrakenV3.h"
RGBController_RazerKrakenV3::RGBController_RazerKrakenV3(RazerKrakenV3Controller* controller_ptr)
{
controller = controller_ptr;
name = controller->GetName();
vendor = "Razer";
type = controller->GetDeviceType();
description = "Razer Device";
location = controller->GetDeviceLocation();
version = controller->GetFirmwareString();
serial = controller->GetSerialString();
uint8_t max_brightness = controller->GetMaxBrightness();
// By default, the device starts as Wave/Spectrum Cycle.
// Set Wave as first mode, so switching to Direct calls DeviceUpdateMode()
mode Wave;
Wave.name = "Wave";
Wave.value = RAZER_KRAKEN_V3_MODE_WAVE;
Wave.flags = MODE_FLAG_HAS_BRIGHTNESS;
Wave.direction = MODE_DIRECTION_RIGHT;
Wave.color_mode = MODE_COLORS_NONE;
Wave.brightness_min = 0;
Wave.brightness_max = max_brightness;
Wave.brightness = max_brightness;
modes.push_back(Wave);
mode Direct;
Direct.name = "Direct";
Direct.value = RAZER_KRAKEN_V3_MODE_DIRECT;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
Direct.color_mode = MODE_COLORS_PER_LED;
Direct.brightness_min = 0;
Direct.brightness_max = max_brightness;
Direct.brightness = max_brightness;
modes.push_back(Direct);
// V3 X does not support this mode.
if(device_list[controller->GetDeviceIndex()]->pid == RAZER_KRAKEN_V3_HYPERSENSE_PID)
{
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = RAZER_KRAKEN_V3_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors_min = 1;
Breathing.colors_max = 2;
Breathing.colors.resize(1);
modes.push_back(Breathing);
}
SetupZones();
}
RGBController_RazerKrakenV3::~RGBController_RazerKrakenV3()
{
delete controller;
}
void RGBController_RazerKrakenV3::SetupZones()
{
unsigned int device_index = controller->GetDeviceIndex();
/*---------------------------------------------------------*\
| Fill in zone information based on device table |
\*---------------------------------------------------------*/
for(unsigned int zone_id = 0; zone_id < RAZER_MAX_ZONES; zone_id++)
{
if(device_list[device_index]->zones[zone_id] != NULL)
{
zone new_zone;
new_zone.name = device_list[device_index]->zones[zone_id]->name;
new_zone.type = device_list[device_index]->zones[zone_id]->type;
new_zone.leds_count = device_list[device_index]->zones[zone_id]->rows * device_list[device_index]->zones[zone_id]->cols;
new_zone.leds_min = new_zone.leds_count;
new_zone.leds_max = new_zone.leds_count;
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 = device_list[device_index]->zones[zone_id]->rows;
new_map->width = device_list[device_index]->zones[zone_id]->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;
}
}
}
else
{
new_zone.matrix_map = NULL;
}
zones.push_back(new_zone);
}
}
for(unsigned int zone_id = 0; zone_id < zones.size(); zone_id++)
{
for (unsigned int row_id = 0; row_id < device_list[device_index]->zones[zone_id]->rows; row_id++)
{
for (unsigned int col_id = 0; col_id < device_list[device_index]->zones[zone_id]->cols; col_id++)
{
led* new_led = new led();
new_led->name = device_list[device_index]->zones[zone_id]->name;
if(zones[zone_id].leds_count > 1)
{
new_led->name.append(" LED ");
new_led->name.append(std::to_string(col_id + 1));
}
leds.push_back(*new_led);
}
}
}
SetupColors();
}
void RGBController_RazerKrakenV3::ResizeZone(int /*zone*/, int /*new_size*/)
{
}
void RGBController_RazerKrakenV3::DeviceUpdateLEDs()
{
if(modes[active_mode].value == RAZER_KRAKEN_V3_MODE_DIRECT)
{
controller->SetDirect(&colors[0]);
}
}
void RGBController_RazerKrakenV3::UpdateZoneLEDs(int /*zone*/)
{
DeviceUpdateLEDs();
}
void RGBController_RazerKrakenV3::UpdateSingleLED(int /*led*/)
{
DeviceUpdateLEDs();
}
void RGBController_RazerKrakenV3::DeviceUpdateMode()
{
switch(modes[active_mode].value)
{
case RAZER_KRAKEN_V3_MODE_DIRECT:
controller->SetModeDirect();
controller->SetBrightness(modes[active_mode].brightness);
break;
case RAZER_KRAKEN_V3_MODE_WAVE:
controller->SetModeWave();
controller->SetBrightness(modes[active_mode].brightness);
break;
case RAZER_KRAKEN_V3_MODE_BREATHING:
controller->SetModeBreathing(modes[active_mode].colors);
controller->SetBrightness(modes[active_mode].brightness);
break;
}
}
@@ -0,0 +1,42 @@
/*---------------------------------------------------------*\
| RGBController_RazerKrakenV3.h |
| |
| RGBController for Razer devices with 13-byte reports |
| |
| Greg Sandstrom (superstrom) 1 Nov 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include "RGBController.h"
#include "RazerKrakenV3Controller.h"
enum
{
RAZER_KRAKEN_V3_MODE_DIRECT,
RAZER_KRAKEN_V3_MODE_WAVE,
RAZER_KRAKEN_V3_MODE_BREATHING,
};
class RGBController_RazerKrakenV3 : public RGBController
{
public:
RGBController_RazerKrakenV3(RazerKrakenV3Controller* controller_ptr);
~RGBController_RazerKrakenV3();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
RazerKrakenV3Controller* controller;
};
@@ -0,0 +1,280 @@
/*---------------------------------------------------------*\
| RazerKrakenV3Controller.cpp |
| |
| Driver for Razer devices with 13-byte reports |
| |
| Greg Sandstrom (superstrom) 1 Nov 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <cstring>
#include "RazerKrakenController.h"
#include "RazerKrakenV3Controller.h"
#include "RazerDevices.h"
using namespace std::chrono_literals;
RazerKrakenV3Controller::RazerKrakenV3Controller(hid_device* dev_handle, const char* path, unsigned short pid, std::string dev_name)
{
dev = dev_handle;
dev_pid = pid;
location = path;
name = dev_name;
/*-----------------------------------------------------------------*\
| Loop through all known devices to look for a name match |
\*-----------------------------------------------------------------*/
for(unsigned int i = 0; i < RAZER_NUM_DEVICES; i++)
{
if(device_list[i]->pid == dev_pid)
{
/*---------------------------------------------------------*\
| Set device ID |
\*---------------------------------------------------------*/
device_index = i;
}
}
/*-----------------------------------------------------------------*\
| Determine matrix type for device |
\*-----------------------------------------------------------------*/
matrix_type = device_list[device_index]->matrix_type;
}
RazerKrakenV3Controller::~RazerKrakenV3Controller()
{
hid_close(dev);
}
std::string RazerKrakenV3Controller::GetName()
{
return(name);
}
unsigned int RazerKrakenV3Controller::GetDeviceIndex()
{
return(device_index);
}
device_type RazerKrakenV3Controller::GetDeviceType()
{
return(device_list[device_index]->type);
}
std::string RazerKrakenV3Controller::GetDeviceLocation()
{
return("HID: " + location);
}
std::string RazerKrakenV3Controller::GetFirmwareString()
{
return(razer_get_firmware());
}
std::string RazerKrakenV3Controller::GetSerialString()
{
return(razer_get_serial());
}
unsigned char RazerKrakenV3Controller::GetMaxBrightness()
{
/*-----------------------------------------------------*\
| Max brightness for most devices is 0xFF (255) |
| Add PIDs only for devices that use 0x64 (100) |
| or any another arbitrary value |
\*-----------------------------------------------------*/
unsigned char max_brightness = 255;
return(max_brightness);
}
void RazerKrakenV3Controller::SetModeDirect()
{
razer_kraken_v3_request_report report = razer_kraken_create_v3_report();
// 0 1 2 3 4 5 6 7 8
// 4001000f0800000000
// 40010000080000000000000000
report.report_id = RAZER_KRAKEN_V3_REPORT_ID;
report.command_id = RAZER_KRAKEN_V3_CMD_LIGHTING_SET_MODE;
report.arguments[1] = 0x0F;
report.arguments[2] = RAZER_KRAKEN_V3_MODE_ID_DIRECT;
hid_write(dev, (unsigned char*)&report, sizeof(report));
}
void RazerKrakenV3Controller::SetDirect(RGBColor* colors)
{
razer_kraken_v3_request_report report = razer_kraken_create_v3_report();
// how to get the number of leds?
unsigned int led_count = device_list[device_index]->cols;
// 0 1 2 3 4 5 6 7 8
// 400300ffffff000000
// 400300ffffff00000000000000
report.report_id = RAZER_KRAKEN_V3_REPORT_ID;
report.command_id = RAZER_KRAKEN_V3_CMD_LIGHTING_SET_COLOR;
for(unsigned int led_idx = 0; led_idx < led_count; led_idx++)
{
report.arguments[1 + (led_idx * 3)] = RGBGetRValue(colors[led_idx]);
report.arguments[2 + (led_idx * 3)] = RGBGetGValue(colors[led_idx]);
report.arguments[3 + (led_idx * 3)] = RGBGetBValue(colors[led_idx]);
}
hid_write(dev, (unsigned char*)&report, sizeof(report));
}
void RazerKrakenV3Controller::SetBrightness(unsigned char brightness)
{
razer_kraken_v3_request_report report = razer_kraken_create_v3_report();
// 0 1 2 3 4 5 6 7 8
// 40020000ff00000000
report.report_id = RAZER_KRAKEN_V3_REPORT_ID;
report.command_id = RAZER_KRAKEN_V3_CMD_LIGHTING_SET_BRIGHTNESS;
report.arguments[2] = brightness;
hid_write(dev, (unsigned char*)&report, sizeof(report));
}
void RazerKrakenV3Controller::SetModeWave()
{
razer_kraken_v3_request_report report = razer_kraken_create_v3_report();
// 0 1 2 3 4 5 6 7 8
// 4001000f0300000000
// 40010100030000000000000000
report.report_id = RAZER_KRAKEN_V3_REPORT_ID;
report.command_id = RAZER_KRAKEN_V3_CMD_LIGHTING_SET_MODE;
report.arguments[1] = 0x0F;
report.arguments[2] = RAZER_KRAKEN_V3_MODE_ID_WAVE;
hid_write(dev, (unsigned char*)&report, sizeof(report));
}
void RazerKrakenV3Controller::SetModeBreathing(std::vector<RGBColor> colors)
{
razer_kraken_v3_request_report report = razer_kraken_create_v3_report();
unsigned char led_count = (unsigned char)colors.size();
// 0 1 2 3 4 5 6 7 8 9 0 1 2
// 400101000101ff000000000000
// 40010100010100ffff00000000
// 40010100020200ff00ff000000
report.report_id = RAZER_KRAKEN_V3_REPORT_ID;
report.command_id = RAZER_KRAKEN_V3_CMD_LIGHTING_SET_MODE;
report.arguments[0] = 0x01;
report.arguments[2] = led_count; // normally this is where the MODE_ID goes....
report.arguments[3] = led_count;
for(unsigned int led_idx = 0; led_idx < led_count; led_idx++)
{
report.arguments[4 + (led_idx * 3)] = RGBGetRValue(colors[led_idx]);
report.arguments[5 + (led_idx * 3)] = RGBGetGValue(colors[led_idx]);
report.arguments[6 + (led_idx * 3)] = RGBGetBValue(colors[led_idx]);
}
hid_write(dev, (unsigned char*)&report, sizeof(report));
}
razer_kraken_v3_request_report RazerKrakenV3Controller::razer_kraken_create_v3_report()
{
razer_kraken_v3_request_report new_report;
/*---------------------------------------------------------*\
| Zero out the new report |
\*---------------------------------------------------------*/
memset(&new_report, 0, sizeof(razer_kraken_v3_request_report));
new_report.report_id = RAZER_KRAKEN_V3_REPORT_ID;
return new_report;
}
razer_kraken_request_report RazerKrakenV3Controller::razer_kraken_create_report(unsigned char report_id, unsigned char destination, unsigned char length, unsigned short address)
{
razer_kraken_request_report new_report;
/*---------------------------------------------------------*\
| Zero out the new report |
\*---------------------------------------------------------*/
memset(&new_report, 0, sizeof(razer_kraken_request_report));
/*---------------------------------------------------------*\
| Fill in the new report with the given parameters |
\*---------------------------------------------------------*/
new_report.report_id = report_id;
new_report.destination = destination;
new_report.length = length;
new_report.addr_h = (address >> 8);
new_report.addr_l = (address & 0xFF);
return new_report;
}
std::string RazerKrakenV3Controller::razer_get_firmware()
{
std::string firmware_string = "";
struct razer_kraken_request_report report = razer_kraken_create_report(0x04, 0x20, 0x02, 0x0030);
struct razer_kraken_response_report response_report;
std::this_thread::sleep_for(1ms);
razer_usb_send(&report);
std::this_thread::sleep_for(1ms);
razer_usb_receive(&response_report);
if(response_report.report_id == 0x05)
{
firmware_string = "v" + std::to_string(response_report.arguments[1]) + "." + std::to_string(response_report.arguments[2]);
}
return firmware_string;
}
std::string RazerKrakenV3Controller::razer_get_serial()
{
char serial_string[64] = "";
struct razer_kraken_request_report report = razer_kraken_create_report(0x04, 0x20, 0x16, 0x7f00);
struct razer_kraken_response_report response_report;
std::this_thread::sleep_for(1ms);
razer_usb_send(&report);
std::this_thread::sleep_for(1ms);
razer_usb_receive(&response_report);
if(response_report.report_id == 0x05)
{
strncpy(&serial_string[0], (const char*)&response_report.arguments[0], 22);
serial_string[22] = '\0';
}
for(size_t i = 0; i < 22; i++)
{
if(serial_string[i] < 30 || serial_string[i] > 126)
{
serial_string[i] = ' ';
}
}
std::string ret_string = serial_string;
return ret_string;
}
/*---------------------------------------------------------------------------------*\
| USB transfer functions |
\*---------------------------------------------------------------------------------*/
int RazerKrakenV3Controller::razer_usb_receive(razer_kraken_response_report* report)
{
return hid_read(dev, (unsigned char*)report, sizeof(*report));
}
int RazerKrakenV3Controller::razer_usb_send(razer_kraken_request_report* report)
{
return hid_write(dev, (unsigned char*)report, sizeof(*report));
}
@@ -0,0 +1,106 @@
/*---------------------------------------------------------*\
| RazerKrakenV3Controller.h |
| |
| Driver for Razer devices with 13-byte reports |
| |
| Greg Sandstrom (superstrom) 1 Nov 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <hidapi.h>
#include "RGBController.h"
#include "DeviceGuardManager.h"
#include "RazerKrakenController.h"
#define RAZER_KRAKEN_V3_REPORT_ID 0x40
enum
{
RAZER_KRAKEN_V3_CMD_LIGHTING_SET_MODE = 0x01,
RAZER_KRAKEN_V3_CMD_LIGHTING_SET_BRIGHTNESS = 0x02,
RAZER_KRAKEN_V3_CMD_LIGHTING_SET_COLOR = 0x03,
};
enum
{
RAZER_KRAKEN_V3_MODE_ID_DIRECT = 0x08,
RAZER_KRAKEN_V3_MODE_ID_WAVE = 0x03,
};
PACK(struct razer_kraken_v3_request_report
{
unsigned char report_id; // usb_buf[0]
unsigned char command_id; // usb_buf[1]
unsigned char arguments[13]; // usb_buf[2...]
});
class RazerKrakenV3Controller
{
public:
RazerKrakenV3Controller(hid_device* dev_handle, const char* path, unsigned short pid, std::string dev_name);
~RazerKrakenV3Controller();
unsigned int GetDeviceIndex();
device_type GetDeviceType();
std::string GetDeviceLocation();
std::string GetFirmwareString();
std::string GetName();
std::string GetSerialString();
unsigned char GetMaxBrightness();
void SetDirect(RGBColor* colors);
void SetBrightness(unsigned char brightness);
void SetModeDirect();
void SetModeWave();
void SetModeBreathing(std::vector<RGBColor> colors);
private:
hid_device* dev;
unsigned short dev_pid;
/*---------------------------------------------------------*\
| Device-specific protocol settings |
\*---------------------------------------------------------*/
unsigned char dev_transaction_id;
unsigned char dev_led_id;
/*---------------------------------------------------------*\
| Device information strings |
\*---------------------------------------------------------*/
std::string firmware_version;
std::string location;
std::string name;
/*---------------------------------------------------------*\
| Index of device in Razer device list |
\*---------------------------------------------------------*/
unsigned int device_index;
/*---------------------------------------------------------*\
| HID report index for request and response |
\*---------------------------------------------------------*/
unsigned char report_index;
unsigned char response_index;
/*---------------------------------------------------------*\
| Matrix type |
\*---------------------------------------------------------*/
unsigned char matrix_type;
/*---------------------------------------------------------*\
| Private functions based on OpenRazer |
\*---------------------------------------------------------*/
std::string razer_get_firmware();
std::string razer_get_serial();
razer_kraken_v3_request_report razer_kraken_create_v3_report();
razer_kraken_request_report razer_kraken_create_report(unsigned char report_id, unsigned char destination, unsigned char length, unsigned short address);
int razer_usb_receive(razer_kraken_response_report* report);
int razer_usb_send(razer_kraken_request_report* report);
};