Add initial driver for Thermaltake Riing controller. Fixed configuration has 9 LEDs for channels 1, 2, and 3 but will make this configurable in the future. Only direct mode supported so far

This commit is contained in:
Adam Honse 2020-02-09 14:33:22 -06:00
parent ea1f21106c
commit 2f00fb9186
7 changed files with 407 additions and 2 deletions

View file

@ -0,0 +1,111 @@
/*-----------------------------------------*\
| ThermaltakeRiingController.cpp |
| |
| Definitions and types for Thermaltake |
| Riing Plus lighting controller |
| |
| Adam Honse (CalcProgrammer1) 2/7/2020 |
\*-----------------------------------------*/
#include "ThermaltakeRiingController.h"
#include <cstring>
ThermaltakeRiingController::ThermaltakeRiingController(libusb_device_handle* dev_handle)
{
dev = dev_handle;
SendInit();
channel_leds[0] = 9;
channel_leds[1] = 9;
channel_leds[2] = 9;
channel_leds[4] = 0;
channel_leds[4] = 0;
}
ThermaltakeRiingController::~ThermaltakeRiingController()
{
}
void ThermaltakeRiingController::SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors)
{
unsigned char* color_data = new unsigned char[colors.size()];
for(int color = 0; color < colors.size(); color++)
{
int color_idx = color * 3;
color_data[color_idx + 0] = RGBGetGValue(colors[color]);
color_data[color_idx + 1] = RGBGetRValue(colors[color]);
color_data[color_idx + 2] = RGBGetBValue(colors[color]);
}
SendRGB(channel, THERMALTAKE_MODE_PER_LED, THERMALTAKE_SPEED_FAST, colors.size(), color_data);
delete[] color_data;
}
/*-------------------------------------------------------------------------------------------------*\
| Private packet sending functions. |
\*-------------------------------------------------------------------------------------------------*/
void ThermaltakeRiingController::SendInit()
{
unsigned char usb_buf[64];
int actual;
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up Init packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0xFE;
usb_buf[0x01] = 0x33;
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x81, usb_buf, 64, &actual, 0);
}
void ThermaltakeRiingController::SendRGB
(
unsigned char port,
unsigned char mode,
unsigned char speed,
unsigned char num_colors,
unsigned char* color_data
)
{
unsigned char usb_buf[64];
int actual;
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
| Set up RGB packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x32;
usb_buf[0x01] = 0x52;
usb_buf[0x02] = port;
usb_buf[0x03] = mode + speed;
/*-----------------------------------------------------*\
| Copy in GRB color data |
\*-----------------------------------------------------*/
memcpy(&usb_buf[0x04], color_data, (num_colors * 3));
/*-----------------------------------------------------*\
| Send packet |
\*-----------------------------------------------------*/
libusb_interrupt_transfer(dev, 0x01, usb_buf, 64, &actual, 0);
libusb_interrupt_transfer(dev, 0x81, usb_buf, 64, &actual, 0);
}

View file

@ -0,0 +1,71 @@
/*-----------------------------------------*\
| ThermaltakeRiingController.h |
| |
| Definitions and types for Thermaltake |
| Riing Plus lighting controller |
| |
| Adam Honse (CalcProgrammer1) 2/7/2020 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <vector>
#include <libusb-1.0/libusb.h>
#pragma once
enum
{
THERMALTAKE_PORT_1 = 0x01,
THERMALTAKE_PORT_2 = 0x02,
THERMALTAKE_PORT_3 = 0x03,
THERMALTAKE_PORT_4 = 0x04,
THERMALTAKE_PORT_5 = 0x05
};
enum
{
THERMALTAKE_MODE_FLOW = 0x00,
THERMALTAKE_MODE_SPECTRUM = 0x04,
THERMALTAKE_MODE_RIPPLE = 0x08,
THERMALTAKE_MODE_BLINK = 0x0C,
THERMALTAKE_MODE_PULSE = 0x10,
THERMALTAKE_MODE_WAVE = 0x14,
THERMALTAKE_MODE_PER_LED = 0x18,
THERMALTAKE_MODE_FULL = 0x19
};
enum
{
THERMALTAKE_SPEED_SLOW = 0x03,
THERMALTAKE_SPEED_NORMAL = 0x02,
THERMALTAKE_SPEED_FAST = 0x01,
THERMALTAKE_SPEED_EXTREME = 0x00
};
class ThermaltakeRiingController
{
public:
ThermaltakeRiingController(libusb_device_handle* dev_handle);
~ThermaltakeRiingController();
void SetChannelLEDs(unsigned char channel, std::vector<RGBColor> colors);
unsigned int channel_leds[5];
private:
libusb_device_handle* dev;
void SendInit();
void ThermaltakeRiingController::SendRGB
(
unsigned char port,
unsigned char mode,
unsigned char speed,
unsigned char num_colors,
unsigned char* color_data
);
void SendFan();
void SendSave();
};

View file

@ -0,0 +1,41 @@
#include "ThermaltakeRiingController.h"
#include "RGBController.h"
#include "RGBController_ThermaltakeRiing.h"
#include <vector>
#include <libusb-1.0/libusb.h>
#define THERMALTAKE_RIING_VID 0x264A
#define THERMALTAKE_RIING_PID_BEGIN 0x1FA5
#define THERMALTAKE_RIING_PID_END 0x1FB5
/******************************************************************************************\
* *
* DetectThermaltakeRiingControllers *
* *
* Tests the USB address to see if an AMD Wraith Prism controller exists there. *
* *
\******************************************************************************************/
void DetectThermaltakeRiingControllers(std::vector<RGBController*>& rgb_controllers)
{
libusb_context * ctx;
libusb_init(&ctx);
for(int pid = THERMALTAKE_RIING_PID_BEGIN; pid <= THERMALTAKE_RIING_PID_END; pid++)
{
//Look for Thermaltake Riing device
libusb_device_handle * dev = libusb_open_device_with_vid_pid(ctx, THERMALTAKE_RIING_VID, pid);
if( dev )
{
libusb_detach_kernel_driver(dev, 0);
libusb_claim_interface(dev, 0);
ThermaltakeRiingController* controller = new ThermaltakeRiingController(dev);
RGBController_ThermaltakeRiing* rgb_controller = new RGBController_ThermaltakeRiing(controller);
rgb_controllers.push_back(rgb_controller);
}
}
}