Publish LumaOps source
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_RazerKraken.cpp |
|
||||
| |
|
||||
| RGBController for Razer Kraken |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 28 Feb 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_RazerKraken.h"
|
||||
#include "RazerDevices.h"
|
||||
|
||||
/**------------------------------------------------------------------*\
|
||||
@name Razer Kraken
|
||||
@category Headset
|
||||
@type USB
|
||||
@save :robot:
|
||||
@direct :white_check_mark:
|
||||
@effects :white_check_mark:
|
||||
@detectors DetectRazerKrakenControllers
|
||||
@comment
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
RGBController_RazerKraken::RGBController_RazerKraken(RazerKrakenController* controller_ptr)
|
||||
{
|
||||
controller = controller_ptr;
|
||||
|
||||
name = controller->GetName();
|
||||
vendor = "Razer";
|
||||
type = controller->GetDeviceType();
|
||||
description = "Razer Kraken Device";
|
||||
location = controller->GetDeviceLocation();
|
||||
version = controller->GetFirmwareString();
|
||||
serial = controller->GetSerialString();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = RAZER_KRAKEN_MODE_DIRECT;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
mode Off;
|
||||
Off.name = "Off";
|
||||
Off.value = RAZER_KRAKEN_MODE_OFF;
|
||||
Off.flags = 0;
|
||||
Off.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(Off);
|
||||
|
||||
mode Static;
|
||||
Static.name = "Static";
|
||||
Static.value = RAZER_KRAKEN_MODE_STATIC;
|
||||
Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Static.colors_min = 1;
|
||||
Static.colors_max = 1;
|
||||
Static.colors.resize(1);
|
||||
modes.push_back(Static);
|
||||
|
||||
mode Breathing;
|
||||
Breathing.name = "Breathing";
|
||||
Breathing.value = RAZER_KRAKEN_MODE_BREATHING;
|
||||
Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
|
||||
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
Breathing.colors_min = 1;
|
||||
/*---------------------------------------------------------*\
|
||||
| Razer Kraken 7.1 Chroma only does single color breathing |
|
||||
\*---------------------------------------------------------*/
|
||||
if(device_list[controller->GetDeviceIndex()]->pid == RAZER_KRAKEN_PID)
|
||||
{
|
||||
Breathing.colors_max = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Breathing.colors_max = 3;
|
||||
}
|
||||
Breathing.colors.resize(1);
|
||||
modes.push_back(Breathing);
|
||||
|
||||
mode SpectrumCycle;
|
||||
SpectrumCycle.name = "Spectrum Cycle";
|
||||
SpectrumCycle.value = RAZER_KRAKEN_MODE_SPECTRUM_CYCLE;
|
||||
SpectrumCycle.flags = 0;
|
||||
SpectrumCycle.color_mode = MODE_COLORS_NONE;
|
||||
modes.push_back(SpectrumCycle);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_RazerKraken::~RGBController_RazerKraken()
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
|
||||
void RGBController_RazerKraken::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_RazerKraken::ResizeZone(int /*zone*/, int /*new_size*/)
|
||||
{
|
||||
/*---------------------------------------------------------*\
|
||||
| This device does not support resizing zones |
|
||||
\*---------------------------------------------------------*/
|
||||
}
|
||||
|
||||
void RGBController_RazerKraken::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char red = RGBGetRValue(colors[0]);
|
||||
unsigned char grn = RGBGetGValue(colors[0]);
|
||||
unsigned char blu = RGBGetBValue(colors[0]);
|
||||
|
||||
controller->SetModeCustom(red, grn, blu);
|
||||
}
|
||||
|
||||
void RGBController_RazerKraken::UpdateZoneLEDs(int /*zone*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RazerKraken::UpdateSingleLED(int /*led*/)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_RazerKraken::DeviceUpdateMode()
|
||||
{
|
||||
switch(modes[active_mode].value)
|
||||
{
|
||||
case RAZER_KRAKEN_MODE_OFF:
|
||||
controller->SetModeOff();
|
||||
break;
|
||||
|
||||
case RAZER_KRAKEN_MODE_STATIC:
|
||||
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
|
||||
{
|
||||
if(modes[active_mode].colors.size() == 1)
|
||||
{
|
||||
unsigned char red = RGBGetRValue(modes[active_mode].colors[0]);
|
||||
unsigned char grn = RGBGetGValue(modes[active_mode].colors[0]);
|
||||
unsigned char blu = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
|
||||
controller->SetModeStatic(red, grn, blu);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RAZER_KRAKEN_MODE_BREATHING:
|
||||
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
|
||||
{
|
||||
if(modes[active_mode].colors.size() == 1)
|
||||
{
|
||||
unsigned char red = RGBGetRValue(modes[active_mode].colors[0]);
|
||||
unsigned char grn = RGBGetGValue(modes[active_mode].colors[0]);
|
||||
unsigned char blu = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
|
||||
controller->SetModeBreathingOneColor(red, grn, blu);
|
||||
}
|
||||
else if(modes[active_mode].colors.size() == 2)
|
||||
{
|
||||
unsigned char red1 = RGBGetRValue(modes[active_mode].colors[0]);
|
||||
unsigned char grn1 = RGBGetGValue(modes[active_mode].colors[0]);
|
||||
unsigned char blu1 = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
unsigned char red2 = RGBGetRValue(modes[active_mode].colors[1]);
|
||||
unsigned char grn2 = RGBGetGValue(modes[active_mode].colors[1]);
|
||||
unsigned char blu2 = RGBGetBValue(modes[active_mode].colors[1]);
|
||||
|
||||
controller->SetModeBreathingTwoColors(red1, grn1, blu1, red2, grn2, blu2);
|
||||
}
|
||||
else if(modes[active_mode].colors.size() == 3)
|
||||
{
|
||||
unsigned char red1 = RGBGetRValue(modes[active_mode].colors[0]);
|
||||
unsigned char grn1 = RGBGetGValue(modes[active_mode].colors[0]);
|
||||
unsigned char blu1 = RGBGetBValue(modes[active_mode].colors[0]);
|
||||
unsigned char red2 = RGBGetRValue(modes[active_mode].colors[1]);
|
||||
unsigned char grn2 = RGBGetGValue(modes[active_mode].colors[1]);
|
||||
unsigned char blu2 = RGBGetBValue(modes[active_mode].colors[1]);
|
||||
unsigned char red3 = RGBGetRValue(modes[active_mode].colors[2]);
|
||||
unsigned char grn3 = RGBGetGValue(modes[active_mode].colors[2]);
|
||||
unsigned char blu3 = RGBGetBValue(modes[active_mode].colors[2]);
|
||||
|
||||
controller->SetModeBreathingThreeColors(red1, grn1, blu1, red2, grn2, blu2, red3, grn3, blu3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RAZER_KRAKEN_MODE_SPECTRUM_CYCLE:
|
||||
controller->SetModeSpectrumCycle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RGBController_RazerKraken.h |
|
||||
| |
|
||||
| RGBController for Razer Kraken |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 28 Feb 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include "RazerKrakenController.h"
|
||||
|
||||
enum
|
||||
{
|
||||
RAZER_KRAKEN_MODE_DIRECT,
|
||||
RAZER_KRAKEN_MODE_OFF,
|
||||
RAZER_KRAKEN_MODE_STATIC,
|
||||
RAZER_KRAKEN_MODE_BREATHING,
|
||||
RAZER_KRAKEN_MODE_SPECTRUM_CYCLE,
|
||||
};
|
||||
|
||||
class RGBController_RazerKraken : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_RazerKraken(RazerKrakenController* controller_ptr);
|
||||
~RGBController_RazerKraken();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
RazerKrakenController* controller;
|
||||
};
|
||||
@@ -0,0 +1,401 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RazerKrakenController.cpp |
|
||||
| |
|
||||
| Driver for Razer Kraken |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 28 Feb 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include <string.h>
|
||||
#include "RazerKrakenController.h"
|
||||
#include "RazerDevices.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
RazerKrakenController::RazerKrakenController(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;
|
||||
device_index = 0;
|
||||
|
||||
/*-----------------------------------------------------------------*\
|
||||
| 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 addresses for device |
|
||||
\*-----------------------------------------------------------------*/
|
||||
switch(dev_pid)
|
||||
{
|
||||
case RAZER_KRAKEN_V2_PID:
|
||||
case RAZER_KRAKEN_KITTY_BLACK_EDITION_V2_PID:
|
||||
case RAZER_KRAKEN_ULTIMATE_PID:
|
||||
led_mode_address = 0x172D;
|
||||
custom_address = 0x1189;
|
||||
breathing_address[0] = 0x1741;
|
||||
breathing_address[1] = 0x1745;
|
||||
breathing_address[2] = 0x174D;
|
||||
break;
|
||||
case RAZER_KRAKEN_CLASSIC_PID:
|
||||
case RAZER_KRAKEN_CLASSIC_ALT_PID:
|
||||
case RAZER_KRAKEN_PID:
|
||||
led_mode_address = 0x1008;
|
||||
custom_address = 0x1189;
|
||||
breathing_address[0] = 0x15DE;
|
||||
breathing_address[1] = 0x15DE;
|
||||
breathing_address[2] = 0x15DE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
RazerKrakenController::~RazerKrakenController()
|
||||
{
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
std::string RazerKrakenController::GetName()
|
||||
{
|
||||
return(name);
|
||||
}
|
||||
|
||||
unsigned int RazerKrakenController::GetDeviceIndex()
|
||||
{
|
||||
return(device_index);
|
||||
}
|
||||
|
||||
device_type RazerKrakenController::GetDeviceType()
|
||||
{
|
||||
return(device_list[device_index]->type);
|
||||
}
|
||||
|
||||
std::string RazerKrakenController::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string RazerKrakenController::GetFirmwareString()
|
||||
{
|
||||
return(razer_get_firmware());
|
||||
}
|
||||
|
||||
std::string RazerKrakenController::GetSerialString()
|
||||
{
|
||||
return(razer_get_serial());
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeBreathingOneColor(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
razer_set_mode_breathing_one_color(red, grn, blu);
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeBreathingTwoColors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2)
|
||||
{
|
||||
razer_set_mode_breathing_two_colors(r1, g1, b1, r2, g2, b2);
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeBreathingThreeColors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2, unsigned char r3, unsigned char g3, unsigned char b3)
|
||||
{
|
||||
razer_set_mode_breathing_three_colors(r1, g1, b1, r2, g2, b2, r3, g3, b3);
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeCustom(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
razer_set_mode_custom(red, grn, blu);
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeOff()
|
||||
{
|
||||
razer_set_mode_none();
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeSpectrumCycle()
|
||||
{
|
||||
razer_set_mode_spectrum_cycle();
|
||||
}
|
||||
|
||||
void RazerKrakenController::SetModeStatic(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
razer_set_mode_static(red, grn, blu);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| Basic report and response creation functions |
|
||||
\*---------------------------------------------------------------------------------*/
|
||||
|
||||
razer_kraken_request_report RazerKrakenController::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;
|
||||
}
|
||||
|
||||
razer_kraken_effect_byte RazerKrakenController::razer_kraken_create_effect_byte()
|
||||
{
|
||||
razer_kraken_effect_byte effect_byte;
|
||||
|
||||
memset(&effect_byte, 0, sizeof(razer_kraken_effect_byte));
|
||||
|
||||
return effect_byte;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| Get functions (request information from device) |
|
||||
\*---------------------------------------------------------------------------------*/
|
||||
|
||||
std::string RazerKrakenController::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 RazerKrakenController::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;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| Set functions (send information to device) |
|
||||
\*---------------------------------------------------------------------------------*/
|
||||
|
||||
void RazerKrakenController::razer_set_mode_breathing_one_color(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
razer_kraken_request_report rgb_report = razer_kraken_create_report(0x04, 0x40, 0x03, breathing_address[0]);
|
||||
razer_kraken_request_report effect_report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
rgb_report.arguments[0] = red;
|
||||
rgb_report.arguments[1] = grn;
|
||||
rgb_report.arguments[2] = blu;
|
||||
|
||||
effect_byte.bits.on_off_static = 1;
|
||||
effect_byte.bits.single_colour_breathing = 1;
|
||||
effect_byte.bits.sync = 1;
|
||||
effect_report.arguments[0] = effect_byte.value;
|
||||
|
||||
razer_usb_send(&rgb_report);
|
||||
razer_usb_send(&effect_report);
|
||||
}
|
||||
|
||||
void RazerKrakenController::razer_set_mode_breathing_two_colors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2)
|
||||
{
|
||||
razer_kraken_request_report rgb_report_1 = razer_kraken_create_report(0x04, 0x40, 0x03, breathing_address[1]);
|
||||
razer_kraken_request_report rgb_report_2 = razer_kraken_create_report(0x04, 0x40, 0x03, breathing_address[1] + 4);
|
||||
razer_kraken_request_report effect_report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
rgb_report_1.arguments[0] = r1;
|
||||
rgb_report_1.arguments[1] = g1;
|
||||
rgb_report_1.arguments[2] = b1;
|
||||
|
||||
rgb_report_2.arguments[0] = r2;
|
||||
rgb_report_2.arguments[1] = g2;
|
||||
rgb_report_2.arguments[2] = b2;
|
||||
|
||||
effect_byte.bits.on_off_static = 1;
|
||||
effect_byte.bits.two_colour_breathing = 1;
|
||||
effect_byte.bits.sync = 1;
|
||||
effect_report.arguments[0] = effect_byte.value;
|
||||
|
||||
razer_usb_send(&rgb_report_1);
|
||||
razer_usb_send(&rgb_report_2);
|
||||
razer_usb_send(&effect_report);
|
||||
}
|
||||
|
||||
void RazerKrakenController::razer_set_mode_breathing_three_colors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2, unsigned char r3, unsigned char g3, unsigned char b3)
|
||||
{
|
||||
razer_kraken_request_report rgb_report_1 = razer_kraken_create_report(0x04, 0x40, 0x03, breathing_address[1]);
|
||||
razer_kraken_request_report rgb_report_2 = razer_kraken_create_report(0x04, 0x40, 0x03, breathing_address[1] + 4);
|
||||
razer_kraken_request_report rgb_report_3 = razer_kraken_create_report(0x04, 0x40, 0x03, breathing_address[1] + 8);
|
||||
razer_kraken_request_report effect_report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
rgb_report_1.arguments[0] = r1;
|
||||
rgb_report_1.arguments[1] = g1;
|
||||
rgb_report_1.arguments[2] = b1;
|
||||
|
||||
rgb_report_2.arguments[0] = r2;
|
||||
rgb_report_2.arguments[1] = g2;
|
||||
rgb_report_2.arguments[2] = b2;
|
||||
|
||||
rgb_report_3.arguments[0] = r3;
|
||||
rgb_report_3.arguments[1] = g3;
|
||||
rgb_report_3.arguments[2] = b3;
|
||||
|
||||
effect_byte.bits.on_off_static = 1;
|
||||
effect_byte.bits.three_colour_breathing = 1;
|
||||
effect_byte.bits.sync = 1;
|
||||
effect_report.arguments[0] = effect_byte.value;
|
||||
|
||||
razer_usb_send(&rgb_report_1);
|
||||
razer_usb_send(&rgb_report_2);
|
||||
razer_usb_send(&rgb_report_3);
|
||||
razer_usb_send(&effect_report);
|
||||
}
|
||||
|
||||
void RazerKrakenController::razer_set_mode_custom(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
razer_kraken_request_report rgb_report = razer_kraken_create_report(0x04, 0x40, 3, custom_address);
|
||||
razer_kraken_request_report effect_report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
effect_byte.value = 0;
|
||||
|
||||
effect_byte.bits.on_off_static = 1;
|
||||
effect_byte.bits.spectrum_cycling = 0;
|
||||
|
||||
rgb_report.arguments[0] = red;
|
||||
rgb_report.arguments[1] = grn;
|
||||
rgb_report.arguments[2] = blu;
|
||||
effect_report.arguments[0] = effect_byte.value;
|
||||
|
||||
switch(dev_pid)
|
||||
{
|
||||
case RAZER_KRAKEN_PID:
|
||||
case RAZER_KRAKEN_V2_PID:
|
||||
case RAZER_KRAKEN_KITTY_BLACK_EDITION_V2_PID:
|
||||
case RAZER_KRAKEN_ULTIMATE_PID:
|
||||
razer_usb_send(&rgb_report);
|
||||
break;
|
||||
}
|
||||
|
||||
razer_usb_send(&effect_report);
|
||||
}
|
||||
|
||||
void RazerKrakenController::razer_set_mode_none()
|
||||
{
|
||||
razer_kraken_request_report report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
effect_byte.value = 0;
|
||||
|
||||
effect_byte.bits.on_off_static = 0;
|
||||
effect_byte.bits.spectrum_cycling = 0;
|
||||
|
||||
report.arguments[0] = effect_byte.value;
|
||||
|
||||
razer_usb_send(&report);
|
||||
}
|
||||
|
||||
void RazerKrakenController::razer_set_mode_spectrum_cycle()
|
||||
{
|
||||
razer_kraken_request_report report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
effect_byte.value = 0;
|
||||
|
||||
effect_byte.bits.on_off_static = 1;
|
||||
effect_byte.bits.spectrum_cycling = 1;
|
||||
|
||||
report.arguments[0] = effect_byte.value;
|
||||
|
||||
razer_usb_send(&report);
|
||||
}
|
||||
|
||||
void RazerKrakenController::razer_set_mode_static(unsigned char red, unsigned char grn, unsigned char blu)
|
||||
{
|
||||
razer_kraken_request_report rgb_report = razer_kraken_create_report(0x04, 0x40, 3, breathing_address[0]);
|
||||
razer_kraken_request_report effect_report = razer_kraken_create_report(0x04, 0x40, 0x01, led_mode_address);
|
||||
razer_kraken_effect_byte effect_byte = razer_kraken_create_effect_byte();
|
||||
|
||||
effect_byte.value = 0;
|
||||
|
||||
effect_byte.bits.on_off_static = 1;
|
||||
effect_byte.bits.spectrum_cycling = 0;
|
||||
|
||||
rgb_report.arguments[0] = red;
|
||||
rgb_report.arguments[1] = grn;
|
||||
rgb_report.arguments[2] = blu;
|
||||
effect_report.arguments[0] = effect_byte.value;
|
||||
|
||||
switch(dev_pid)
|
||||
{
|
||||
case RAZER_KRAKEN_PID:
|
||||
case RAZER_KRAKEN_V2_PID:
|
||||
case RAZER_KRAKEN_KITTY_BLACK_EDITION_V2_PID:
|
||||
case RAZER_KRAKEN_ULTIMATE_PID:
|
||||
razer_usb_send(&rgb_report);
|
||||
break;
|
||||
}
|
||||
|
||||
razer_usb_send(&effect_report);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| USB transfer functions |
|
||||
\*---------------------------------------------------------------------------------*/
|
||||
|
||||
int RazerKrakenController::razer_usb_receive(razer_kraken_response_report* report)
|
||||
{
|
||||
return hid_read(dev, (unsigned char*)report, sizeof(*report));
|
||||
}
|
||||
|
||||
int RazerKrakenController::razer_usb_send(razer_kraken_request_report* report)
|
||||
{
|
||||
return hid_write(dev, (unsigned char*)report, sizeof(*report));
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*---------------------------------------------------------*\
|
||||
| RazerKrakenController.h |
|
||||
| |
|
||||
| Driver for Razer Kraken |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 28 Feb 2021 |
|
||||
| |
|
||||
| This file is part of the OpenRGB project |
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <hidapi.h>
|
||||
#include "RGBController.h"
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Struct packing macro for GCC and MSVC |
|
||||
\*---------------------------------------------------------*/
|
||||
#ifdef __GNUC__
|
||||
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop))
|
||||
#endif
|
||||
|
||||
union razer_kraken_effect_byte
|
||||
{
|
||||
unsigned char value;
|
||||
|
||||
struct razer_kraken_effect_byte_bits
|
||||
{
|
||||
unsigned char on_off_static :1;
|
||||
unsigned char single_colour_breathing :1;
|
||||
unsigned char spectrum_cycling :1;
|
||||
unsigned char sync :1;
|
||||
unsigned char two_colour_breathing :1;
|
||||
unsigned char three_colour_breathing :1;
|
||||
} bits;
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Razer Kraken Report Types (taken from OpenRazer) |
|
||||
\*---------------------------------------------------------*/
|
||||
PACK(struct razer_kraken_request_report
|
||||
{
|
||||
unsigned char report_id;
|
||||
unsigned char destination;
|
||||
unsigned char length;
|
||||
unsigned char addr_h;
|
||||
unsigned char addr_l;
|
||||
unsigned char arguments[32];
|
||||
});
|
||||
|
||||
PACK(struct razer_kraken_response_report
|
||||
{
|
||||
unsigned char report_id;
|
||||
unsigned char arguments[36];
|
||||
});
|
||||
|
||||
class RazerKrakenController
|
||||
{
|
||||
public:
|
||||
RazerKrakenController(hid_device* dev_handle, const char* path, unsigned short pid, std::string dev_name);
|
||||
~RazerKrakenController();
|
||||
|
||||
unsigned int GetDeviceIndex();
|
||||
device_type GetDeviceType();
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetFirmwareString();
|
||||
std::string GetName();
|
||||
std::string GetSerialString();
|
||||
|
||||
void SetModeBreathingOneColor(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
void SetModeBreathingTwoColors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2);
|
||||
void SetModeBreathingThreeColors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2, unsigned char r3, unsigned char g3, unsigned char b3);
|
||||
void SetModeCustom(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
void SetModeOff();
|
||||
void SetModeSpectrumCycle();
|
||||
void SetModeStatic(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
unsigned short dev_pid;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Device information strings |
|
||||
\*---------------------------------------------------------*/
|
||||
std::string firmware_version;
|
||||
std::string location;
|
||||
std::string name;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Kraken LED/Mode Addresses |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned short breathing_address[3];
|
||||
unsigned short custom_address;
|
||||
unsigned short led_mode_address;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Index of device in Razer device list |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned int device_index;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Private functions based on OpenRazer |
|
||||
\*---------------------------------------------------------*/
|
||||
razer_kraken_request_report razer_kraken_create_report(unsigned char report_id, unsigned char destination, unsigned char length, unsigned short address);
|
||||
razer_kraken_effect_byte razer_kraken_create_effect_byte();
|
||||
|
||||
std::string razer_get_firmware();
|
||||
std::string razer_get_serial();
|
||||
|
||||
void razer_set_mode_breathing_one_color(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
void razer_set_mode_breathing_two_colors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2);
|
||||
void razer_set_mode_breathing_three_colors(unsigned char r1, unsigned char g1, unsigned char b1, unsigned char r2, unsigned char g2, unsigned char b2, unsigned char r3, unsigned char g3, unsigned char b3);
|
||||
void razer_set_mode_custom(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
void razer_set_mode_none();
|
||||
void razer_set_mode_spectrum_cycle();
|
||||
void razer_set_mode_static(unsigned char red, unsigned char grn, unsigned char blu);
|
||||
|
||||
int razer_usb_receive(razer_kraken_response_report* report);
|
||||
int razer_usb_send(razer_kraken_request_report* report);
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user