Add NZXT Kraken driver
Driver should work for NZXT Kraken X42/X52/X62/X72. Most of the color modes and settings are already working. However, there are currently some limitations in settings different ring and logo modes.
This commit is contained in:
parent
6fd6c7f176
commit
facfa05062
7 changed files with 672 additions and 0 deletions
166
Controllers/NZXTKrakenController/NZXTKrakenController.cpp
Normal file
166
Controllers/NZXTKrakenController/NZXTKrakenController.cpp
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Driver for NZXT Kraken |
|
||||
| |
|
||||
| Martin Hartl (inlart), 04/04/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "NZXTKrakenController.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
const int NZXT_KRAKEN_READ_ENDPOINT = 0x81;
|
||||
const int NZXT_KRAKEN_WRITE_ENDPOINT = 0x01;
|
||||
|
||||
static void SetColor(const std::vector<RGBColor>& colors, unsigned char* color_data)
|
||||
{
|
||||
for (std::size_t idx = 0; idx < colors.size(); idx++)
|
||||
{
|
||||
int pixel_idx = idx * 3;
|
||||
RGBColor color = colors[idx];
|
||||
color_data[pixel_idx + 0x00] = RGBGetRValue(color);
|
||||
color_data[pixel_idx + 0x01] = RGBGetGValue(color);
|
||||
color_data[pixel_idx + 0x02] = RGBGetBValue(color);
|
||||
}
|
||||
}
|
||||
|
||||
static RGBColor ToLogoColor(RGBColor rgb)
|
||||
{
|
||||
return ToRGBColor(RGBGetGValue(rgb), RGBGetRValue(rgb), RGBGetBValue(rgb));
|
||||
}
|
||||
|
||||
NZXTKrakenController::NZXTKrakenController(libusb_device_handle* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Get the firmware version |
|
||||
\*-----------------------------------------------------*/
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
NZXTKrakenController::~NZXTKrakenController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string NZXTKrakenController::GetFirmwareVersion()
|
||||
{
|
||||
return firmware_version;
|
||||
}
|
||||
|
||||
void NZXTKrakenController::UpdateStatus()
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[64];
|
||||
memset(usb_buf, 0, sizeof(usb_buf));
|
||||
|
||||
libusb_interrupt_transfer(dev, NZXT_KRAKEN_READ_ENDPOINT, usb_buf, sizeof(usb_buf), &actual, 0);
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Extract cooler information |
|
||||
\*-----------------------------------------------------*/
|
||||
liquid_temperature = usb_buf[0x1] + (usb_buf[0x2] * 0.1);
|
||||
fan_speed = usb_buf[0x3] << 8 | usb_buf[0x4];
|
||||
pump_speed = usb_buf[0x5] << 8 | usb_buf[0x6];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Extract firmware version |
|
||||
\*-----------------------------------------------------*/
|
||||
int major = usb_buf[0xb];
|
||||
int minor = usb_buf[0xc] << 8 | usb_buf[0xd];
|
||||
int patch = usb_buf[0xe];
|
||||
std::stringstream ss;
|
||||
ss << major << '.' << minor << '.' << patch;
|
||||
firmware_version = ss.str();
|
||||
}
|
||||
|
||||
void NZXTKrakenController::UpdateEffect
|
||||
(
|
||||
NZXTKrakenChannel_t channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char speed,
|
||||
int seq,
|
||||
std::vector<RGBColor> colors
|
||||
)
|
||||
{
|
||||
unsigned char color_data[9 * 3];
|
||||
memset(color_data, 0, sizeof(color_data));
|
||||
|
||||
if(!colors.empty() && channel != NZXT_KRAKEN_CHANNEL_RING)
|
||||
{
|
||||
colors[0] = ToLogoColor(colors[0]);
|
||||
}
|
||||
|
||||
SetColor(colors, color_data);
|
||||
SendEffect(channel, mode, direction, color_data, speed, false, seq);
|
||||
}
|
||||
|
||||
void NZXTKrakenController::SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char* color_data,
|
||||
unsigned char speed /* = 0x02 */,
|
||||
bool movement /* = false */,
|
||||
int cis /* = 0 */,
|
||||
int size /* = 0 */
|
||||
)
|
||||
{
|
||||
int actual;
|
||||
unsigned char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set effect mode |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x02;
|
||||
usb_buf[0x01] = 0x4c;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set effect channel, movement and direction |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x02] = channel;
|
||||
usb_buf[0x02] |= movement ? ( 1 << 3 ) : 0;
|
||||
usb_buf[0x02] |= direction ? ( 1 << 4 ) : 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x03] = mode;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set effect speed, size and color in set |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x04] = speed;
|
||||
usb_buf[0x04] |= size << 3;
|
||||
usb_buf[0x04] |= cis << 5;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy color data bytes |
|
||||
\*-----------------------------------------------------*/
|
||||
if(color_data)
|
||||
{
|
||||
memcpy(usb_buf + 0x05, color_data, 9 * 3);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send effect |
|
||||
\*-----------------------------------------------------*/
|
||||
libusb_interrupt_transfer
|
||||
(
|
||||
dev,
|
||||
NZXT_KRAKEN_WRITE_ENDPOINT,
|
||||
usb_buf,
|
||||
sizeof(usb_buf),
|
||||
&actual,
|
||||
0
|
||||
);
|
||||
}
|
||||
86
Controllers/NZXTKrakenController/NZXTKrakenController.h
Normal file
86
Controllers/NZXTKrakenController/NZXTKrakenController.h
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*---------------------------------------------------------*\
|
||||
| Definitions for NZXT Kraken |
|
||||
| |
|
||||
| Martin Hartl (inlart), 04/04/2020 |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
enum NZXTKrakenChannel_t
|
||||
{
|
||||
NZXT_KRAKEN_CHANNEL_SYNC = 0x00, /* Sync Channel */
|
||||
NZXT_KRAKEN_CHANNEL_LOGO = 0x01, /* Logo Channel */
|
||||
NZXT_KRAKEN_CHANNEL_RING = 0x02, /* Ring Channel */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NZXT_KRAKEN_MODE_FIXED = 0x00, /* Fixed colors mode */
|
||||
NZXT_KRAKEN_MODE_FADING = 0x01, /* Fading mode */
|
||||
NZXT_KRAKEN_MODE_SPECTRUM = 0x02, /* Spectrum cycle mode */
|
||||
NZXT_KRAKEN_MODE_MARQUEE = 0x03, /* Marquee mode */
|
||||
NZXT_KRAKEN_MODE_COVER_MARQUEE = 0x04, /* Cover marquee mode */
|
||||
NZXT_KRAKEN_MODE_ALTERNATING = 0x05, /* Alternating mode */
|
||||
NZXT_KRAKEN_MODE_BREATHING = 0x06, /* Breathing mode */
|
||||
NZXT_KRAKEN_MODE_PULSE = 0x07, /* Pulse mode */
|
||||
NZXT_KRAKEN_MODE_TAI_CHI = 0x08, /* Tai Chi mode */
|
||||
NZXT_KRAKEN_MODE_WATER_COOLER = 0x09, /* Water color mode */
|
||||
NZXT_KRAKEN_MODE_LOADING = 0x0a, /* Loading mode */
|
||||
NZXT_KRAKEN_MODE_WINGS = 0x0c, /* Wings mode */
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
NZXT_KRAKEN_SPEED_SLOWEST = 0x00, /* Slowest speed */
|
||||
NZXT_KRAKEN_SPEED_SLOW = 0x01, /* Slow speed */
|
||||
NZXT_KRAKEN_SPEED_NORMAL = 0x02, /* Normal speed */
|
||||
NZXT_KRAKEN_SPEED_FAST = 0x03, /* Fast speed */
|
||||
NZXT_KRAKEN_SPEED_FASTEST = 0x04, /* Fastest speed */
|
||||
};
|
||||
|
||||
class NZXTKrakenController
|
||||
{
|
||||
public:
|
||||
NZXTKrakenController(libusb_device_handle* dev_handle);
|
||||
~NZXTKrakenController();
|
||||
|
||||
std::string GetFirmwareVersion();
|
||||
|
||||
void UpdateEffect
|
||||
(
|
||||
NZXTKrakenChannel_t channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char speed,
|
||||
int seq,
|
||||
std::vector<RGBColor> colors
|
||||
);
|
||||
|
||||
private:
|
||||
void UpdateStatus();
|
||||
|
||||
void SendEffect
|
||||
(
|
||||
unsigned char channel,
|
||||
unsigned char mode,
|
||||
bool direction,
|
||||
unsigned char* color_data,
|
||||
unsigned char speed = 0x02,
|
||||
bool movement = false,
|
||||
int cis = 0 ,
|
||||
int size = 0
|
||||
);
|
||||
|
||||
libusb_device_handle* dev;
|
||||
|
||||
// -- status
|
||||
std::string firmware_version;
|
||||
double liquid_temperature;
|
||||
unsigned int fan_speed;
|
||||
unsigned int pump_speed;
|
||||
};
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#include "NZXTKrakenController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_NZXTKraken.h"
|
||||
#include <vector>
|
||||
#include <libusb-1.0/libusb.h>
|
||||
|
||||
#define NZXT_KRAKEN_VID 0x1E71
|
||||
#define NZXT_KRAKEN_PID 0x170E
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectNZXTKrakenControllers *
|
||||
* *
|
||||
* Detect devices supported by the NZXTKraken driver *
|
||||
* * *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectNZXTKrakenControllers(std::vector<RGBController*> &rgb_controllers)
|
||||
{
|
||||
libusb_context * ctx;
|
||||
libusb_init(&ctx);
|
||||
|
||||
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, NZXT_KRAKEN_VID, NZXT_KRAKEN_PID);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
libusb_detach_kernel_driver(dev, 0);
|
||||
libusb_claim_interface(dev, 0);
|
||||
|
||||
NZXTKrakenController* controller = new NZXTKrakenController(dev);
|
||||
|
||||
RGBController_NZXTKraken* rgb_controller = new RGBController_NZXTKraken(controller);
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue