mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-04-27 09:23:57 -04:00
Add Razer Kraken controller based on OpenRazer
This commit is contained in:
207
Controllers/RazerController/RGBController_RazerKraken.cpp
Normal file
207
Controllers/RazerController/RGBController_RazerKraken.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
#include "RGBController_RazerKraken.h"
|
||||
#include "RazerDevices.h"
|
||||
|
||||
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);
|
||||
|
||||
// Breathing disabled, not yet implemented
|
||||
//mode Breathing;
|
||||
//Breathing.name = "Breathing";
|
||||
//Breathing.value = RAZER_KRAKEN_MODE_BREATHING;
|
||||
//Breathing.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
|
||||
//Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
|
||||
//Breathing.colors_min = 1;
|
||||
//Breathing.colors_max = 2;
|
||||
//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));
|
||||
}
|
||||
|
||||
if(device_list[device_index]->keymap != NULL)
|
||||
{
|
||||
for(unsigned int i = 0; i < device_list[device_index]->keymap_size; i++)
|
||||
{
|
||||
if(zone_id == device_list[device_index]->keymap[i].zone &&
|
||||
row_id == device_list[device_index]->keymap[i].row &&
|
||||
col_id == device_list[device_index]->keymap[i].col)
|
||||
{
|
||||
new_led->name = device_list[device_index]->keymap[i].name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
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].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:
|
||||
break;
|
||||
|
||||
case RAZER_KRAKEN_MODE_SPECTRUM_CYCLE:
|
||||
controller->SetModeSpectrumCycle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
42
Controllers/RazerController/RGBController_RazerKraken.h
Normal file
42
Controllers/RazerController/RGBController_RazerKraken.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*-----------------------------------------*\
|
||||
| RGBController_RazerKraken.h |
|
||||
| |
|
||||
| Generic RGB Interface for Razer Kraken |
|
||||
| devices |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/28/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#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 SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
RazerKrakenController* controller;
|
||||
};
|
||||
@@ -1,9 +1,11 @@
|
||||
#include "Detector.h"
|
||||
#include "RazerController.h"
|
||||
#include "RazerKrakenController.h"
|
||||
#include "RazerDevices.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_Razer.h"
|
||||
#include "RGBController_RazerKraken.h"
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
static bool openrazer_checked = false;
|
||||
@@ -75,6 +77,14 @@ void DetectRazerControllers(hid_device_info* info, const std::string& name)
|
||||
}
|
||||
} /* DetectRazerControllers() */
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRazerARGBControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Razer ARGB controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRazerARGBControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
@@ -118,6 +128,72 @@ void DetectRazerARGBControllers(hid_device_info* info, const std::string& name)
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectRazerKrakenController *
|
||||
* *
|
||||
* Tests the USB address to see if a Razer Kraken controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectRazerKrakenControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| If the OpenRazer/OpenRazer-Win32 controller is |
|
||||
| enabled, don't use this controller. |
|
||||
\*-------------------------------------------------*/
|
||||
if(!openrazer_checked)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Open device disable list and read in disabled |
|
||||
| device strings |
|
||||
\*-------------------------------------------------*/
|
||||
json detector_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Detectors");
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Check for OpenRazer and OpenRazer-Win32 enable |
|
||||
\*-------------------------------------------------*/
|
||||
if(detector_settings.contains("detectors"))
|
||||
{
|
||||
if(detector_settings["detectors"].contains("OpenRazer"))
|
||||
{
|
||||
if(detector_settings["detectors"]["OpenRazer"] == true)
|
||||
{
|
||||
openrazer_enabled = true;
|
||||
}
|
||||
}
|
||||
if(detector_settings["detectors"].contains("OpenRazer-Win32"))
|
||||
{
|
||||
if(detector_settings["detectors"]["OpenRazer-Win32"] == true)
|
||||
{
|
||||
openrazer_enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set OpenRazer checked flag to prevent having to do|
|
||||
| the settings lookup multiple times |
|
||||
\*-------------------------------------------------*/
|
||||
openrazer_checked = true;
|
||||
}
|
||||
|
||||
if(openrazer_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(dev)
|
||||
{
|
||||
RazerKrakenController* controller = new RazerKrakenController(dev, info->path, info->product_id, name);
|
||||
|
||||
RGBController_RazerKraken* rgb_controller = new RGBController_RazerKraken(controller);
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
} /* DetectRazerKrakenControllers() */
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Keyboards |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
@@ -187,3 +263,8 @@ REGISTER_HID_DETECTOR_PU("Razer Kraken Kitty Edition", Dete
|
||||
REGISTER_HID_DETECTOR_PU("Razer Mouse Bungee V3 Chroma", DetectRazerControllers, RAZER_VID, RAZER_MOUSE_BUNGEE_V3_CHROMA_PID, 1, 2);
|
||||
REGISTER_HID_DETECTOR_PU("Razer Nommo Chroma", DetectRazerControllers, RAZER_VID, RAZER_NOMMO_CHROMA_PID, 1, 3);
|
||||
REGISTER_HID_DETECTOR_PU("Razer Nommo Pro", DetectRazerControllers, RAZER_VID, RAZER_NOMMO_PRO_PID, 1, 3);
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Accessories |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
REGISTER_HID_DETECTOR_PU("Razer Kraken 7.1 V2", DetectRazerKrakenControllers, RAZER_VID, RAZER_KRAKEN_V2_PID, 0x0C, 1);
|
||||
|
||||
289
Controllers/RazerController/RazerKrakenController.cpp
Normal file
289
Controllers/RazerController/RazerKrakenController.cpp
Normal file
@@ -0,0 +1,289 @@
|
||||
/*-----------------------------------------*\
|
||||
| RazerKrakenController.cpp |
|
||||
| |
|
||||
| Driver for Razer Kraken devices |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/28/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RazerKrakenController.h"
|
||||
#include "RazerDevices.h"
|
||||
|
||||
#include <string.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_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::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;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| 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';
|
||||
}
|
||||
|
||||
std::string ret_string = serial_string;
|
||||
return ret_string;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*\
|
||||
| Set functions (send information to device) |
|
||||
\*---------------------------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
|
||||
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_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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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_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));
|
||||
}
|
||||
130
Controllers/RazerController/RazerKrakenController.h
Normal file
130
Controllers/RazerController/RazerKrakenController.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/*-----------------------------------------*\
|
||||
| RazerKrakenController.h |
|
||||
| |
|
||||
| Definitions and types for Razer Kraken |
|
||||
| devices |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 2/28/2021 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| 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(typedef 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(typedef 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 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;
|
||||
device_type type;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| 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;
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| HID report index for request and response |
|
||||
\*---------------------------------------------------------*/
|
||||
unsigned char report_index;
|
||||
unsigned char response_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_request_report razer_create_mode_spectrum_cycle_kraken_report(unsigned char variable_storage, unsigned char led_id);
|
||||
|
||||
std::string razer_get_firmware();
|
||||
std::string razer_get_serial();
|
||||
|
||||
void razer_set_mode_breathing();
|
||||
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);
|
||||
|
||||
|
||||
};
|
||||
@@ -279,8 +279,10 @@ HEADERS +=
|
||||
Controllers/PhilipsWizController/PhilipsWizController.h \
|
||||
Controllers/PhilipsWizController/RGBController_PhilipsWiz.h \
|
||||
Controllers/RazerController/RazerController.h \
|
||||
Controllers/RazerController/RazerKrakenController.h \
|
||||
Controllers/RazerController/RazerDevices.h \
|
||||
Controllers/RazerController/RGBController_Razer.h \
|
||||
Controllers/RazerController/RGBController_RazerKraken.h \
|
||||
Controllers/RedragonController/RedragonK556Controller.h \
|
||||
Controllers/RedragonController/RedragonM711Controller.h \
|
||||
Controllers/RedragonController/RGBController_RedragonK556.h \
|
||||
@@ -531,8 +533,10 @@ SOURCES +=
|
||||
Controllers/PhilipsWizController/PhilipsWizControllerDetect.cpp \
|
||||
Controllers/PhilipsWizController/RGBController_PhilipsWiz.cpp \
|
||||
Controllers/RazerController/RazerController.cpp \
|
||||
Controllers/RazerController/RazerKrakenController.cpp \
|
||||
Controllers/RazerController/RazerControllerDetect.cpp \
|
||||
Controllers/RazerController/RGBController_Razer.cpp \
|
||||
Controllers/RazerController/RGBController_RazerKraken.cpp \
|
||||
Controllers/RedragonController/RedragonK556Controller.cpp \
|
||||
Controllers/RedragonController/RedragonM711Controller.cpp \
|
||||
Controllers/RedragonController/RedragonControllerDetect.cpp \
|
||||
|
||||
Reference in New Issue
Block a user