Initial commit for the Riing Quad Fan Controller Hub
* Only looks like a direct mode controller * Implemented just that mode * Likely needs an Effect Engine (EE) to drive it Commits squashed and amended to more closely match existing Thermaltake Riing controller by Adam Honse <calcprogrammer1@gmail.com>merge-requests/371/merge
parent
c401413cb1
commit
9767f97719
@ -0,0 +1,152 @@
|
||||
/*-------------------------------------------------------------------*\
|
||||
| RGBController_ThermaltakeRiingQuad.cpp |
|
||||
| |
|
||||
| Driver for Thermaltake Riing Quad Controller |
|
||||
| |
|
||||
| Chris M (Dr_No) 15th Feb 2021 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "RGBController_ThermaltakeRiingQuad.h"
|
||||
|
||||
RGBController_ThermaltakeRiingQuad::RGBController_ThermaltakeRiingQuad(ThermaltakeRiingQuadController* quad_ptr)
|
||||
{
|
||||
quad = quad_ptr;
|
||||
|
||||
name = quad->GetDeviceName();
|
||||
vendor = "Thermaltake";
|
||||
type = DEVICE_TYPE_COOLER;
|
||||
description = "Thermaltake Riing Quad Device";
|
||||
location = quad->GetDeviceLocation();
|
||||
serial = quad->GetSerial();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
Direct.value = THERMALTAKE_QUAD_MODE_DIRECT;
|
||||
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Direct.speed_min = 0;
|
||||
Direct.speed_max = 0;
|
||||
Direct.speed = 0;
|
||||
Direct.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Direct);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_ThermaltakeRiingQuad::~RGBController_ThermaltakeRiingQuad()
|
||||
{
|
||||
delete quad;
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::SetupZones()
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Only set LED count on the first run |
|
||||
\*-------------------------------------------------*/
|
||||
bool first_run = false;
|
||||
|
||||
if(zones.size() == 0)
|
||||
{
|
||||
first_run = true;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Clear any existing color/LED configuration |
|
||||
\*-------------------------------------------------*/
|
||||
leds.clear();
|
||||
colors.clear();
|
||||
zones.resize(THERMALTAKE_QUAD_NUM_CHANNELS);
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| Set zones and leds |
|
||||
\*-------------------------------------------------*/
|
||||
for (unsigned int channel_idx = 0; channel_idx < THERMALTAKE_QUAD_NUM_CHANNELS; channel_idx++)
|
||||
{
|
||||
char ch_idx_string[2];
|
||||
sprintf(ch_idx_string, "%d", channel_idx + 1);
|
||||
|
||||
zones[channel_idx].name = "Riing Channel ";
|
||||
zones[channel_idx].name.append(ch_idx_string);
|
||||
zones[channel_idx].type = ZONE_TYPE_LINEAR;
|
||||
|
||||
/*-------------------------------------------------*\
|
||||
| The maximum number of colors that would fit in the|
|
||||
| Riing Quad protocol is 54 |
|
||||
\*-------------------------------------------------*/
|
||||
zones[channel_idx].leds_min = 0;
|
||||
zones[channel_idx].leds_max = 54;
|
||||
|
||||
if(first_run)
|
||||
{
|
||||
zones[channel_idx].leds_count = 0;
|
||||
}
|
||||
|
||||
zones[channel_idx].matrix_map = NULL;
|
||||
|
||||
for (unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
|
||||
{
|
||||
char led_idx_string[3];
|
||||
sprintf(led_idx_string, "%d", led_ch_idx + 1);
|
||||
|
||||
led new_led;
|
||||
new_led.name = "Riing Channel ";
|
||||
new_led.name.append(ch_idx_string);
|
||||
new_led.name.append(", LED ");
|
||||
new_led.name.append(led_idx_string);
|
||||
|
||||
leds.push_back(new_led);
|
||||
leds_channel.push_back(channel_idx);
|
||||
}
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
if((size_t) zone >= zones.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(((unsigned int)new_size >= zones[zone].leds_min) && ((unsigned int)new_size <= zones[zone].leds_max))
|
||||
{
|
||||
zones[zone].leds_count = new_size;
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::DeviceUpdateLEDs()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
quad->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
|
||||
}
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
quad->SetChannelLEDs(zone, zones[zone].colors, zones[zone].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::UpdateSingleLED(int led)
|
||||
{
|
||||
unsigned int channel = leds_channel[led];
|
||||
|
||||
quad->SetChannelLEDs(channel, zones[channel].colors, zones[channel].leds_count);
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::SetCustomMode()
|
||||
{
|
||||
active_mode = 0;
|
||||
}
|
||||
|
||||
void RGBController_ThermaltakeRiingQuad::DeviceUpdateMode()
|
||||
{
|
||||
for(std::size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
|
||||
{
|
||||
quad->SetMode(modes[active_mode].value, modes[active_mode].speed);
|
||||
quad->SetChannelLEDs(zone_idx, zones[zone_idx].colors, zones[zone_idx].leds_count);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*-------------------------------------------------------------------*\
|
||||
| RGBController_ThermaltakeRiingQuad.cpp |
|
||||
| |
|
||||
| Driver for Thermaltake Riing Quad Controller |
|
||||
| |
|
||||
| Chris M (Dr_No) 15th Feb 2021 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "ThermaltakeRiingQuadController.h"
|
||||
|
||||
class RGBController_ThermaltakeRiingQuad : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_ThermaltakeRiingQuad(ThermaltakeRiingQuadController* quad_ptr);
|
||||
~RGBController_ThermaltakeRiingQuad();
|
||||
|
||||
void SetupZones();
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void DeviceUpdateMode();
|
||||
|
||||
private:
|
||||
ThermaltakeRiingQuadController* quad;
|
||||
std::vector<unsigned int> leds_channel;
|
||||
std::vector<unsigned int> zones_channel;
|
||||
};
|
@ -0,0 +1,157 @@
|
||||
/*-------------------------------------------------------------------*\
|
||||
| ThermaltakeRiingQuadController.cpp |
|
||||
| |
|
||||
| Driver for Thermaltake Riing Quad Controller |
|
||||
| |
|
||||
| Chris M (Dr_No) 15th Feb 2021 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "ThermaltakeRiingQuadController.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
ThermaltakeRiingQuadController::ThermaltakeRiingQuadController(hid_device* dev_handle, const char* path)
|
||||
{
|
||||
wchar_t tmpName[HID_MAX_STR];
|
||||
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
|
||||
hid_get_manufacturer_string(dev, tmpName, HID_MAX_STR);
|
||||
std::wstring wName = std::wstring(tmpName);
|
||||
device_name = std::string(wName.begin(), wName.end());
|
||||
|
||||
hid_get_product_string(dev, tmpName, HID_MAX_STR);
|
||||
wName = std::wstring(tmpName);
|
||||
device_name.append(" ").append(std::string(wName.begin(), wName.end()));
|
||||
|
||||
hid_get_serial_number_string(dev, tmpName, HID_MAX_STR);
|
||||
wName = std::wstring(tmpName);
|
||||
serial = std::string(wName.begin(), wName.end());
|
||||
|
||||
SendInit();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| The Riing Quad only seems to run in direct mode and |
|
||||
| requires a packet within seconds to remain in the |
|
||||
| set mode (similar to Corsair Node Pro). Start a thread|
|
||||
| to send a packet every TT_QUAD_KEEPALIVE seconds |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(tt_quad_buffer, 0x00, sizeof(tt_quad_buffer));
|
||||
unsigned char temp_buffer[3] = { 0x00, 0x32, 0x52 };
|
||||
|
||||
for(std::size_t zone_index = 0; zone_index < THERMALTAKE_QUAD_NUM_CHANNELS; zone_index++)
|
||||
{
|
||||
/*-------------------------------------------------*\
|
||||
| Add the constant bytes for the mode info buffer |
|
||||
\*-------------------------------------------------*/
|
||||
memcpy(&tt_quad_buffer[zone_index][0], temp_buffer, 3);
|
||||
}
|
||||
|
||||
keepalive_thread_run = 1;
|
||||
keepalive_thread = new std::thread(&ThermaltakeRiingQuadController::KeepaliveThread, this);
|
||||
}
|
||||
|
||||
ThermaltakeRiingQuadController::~ThermaltakeRiingQuadController()
|
||||
{
|
||||
keepalive_thread_run = 0;
|
||||
keepalive_thread->join();
|
||||
delete keepalive_thread;
|
||||
|
||||
hid_close(dev);
|
||||
}
|
||||
|
||||
void ThermaltakeRiingQuadController::KeepaliveThread()
|
||||
{
|
||||
while(keepalive_thread_run.load())
|
||||
{
|
||||
if((std::chrono::steady_clock::now() - last_commit_time) > std::chrono::seconds(THERMALTAKE_QUAD_KEEPALIVE))
|
||||
{
|
||||
SendBuffer();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
}
|
||||
|
||||
std::string ThermaltakeRiingQuadController::GetDeviceName()
|
||||
{
|
||||
return device_name;
|
||||
}
|
||||
|
||||
std::string ThermaltakeRiingQuadController::GetDeviceLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string ThermaltakeRiingQuadController::GetSerial()
|
||||
{
|
||||
return(serial);
|
||||
}
|
||||
|
||||
void ThermaltakeRiingQuadController::SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors)
|
||||
{
|
||||
unsigned char* color_data = new unsigned char[3 * num_colors];
|
||||
|
||||
for(std::size_t color = 0; color < num_colors; 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]);
|
||||
}
|
||||
|
||||
tt_quad_buffer[channel][THERMALTAKE_QUAD_ZONE_BYTE] = channel + 1;
|
||||
tt_quad_buffer[channel][THERMALTAKE_QUAD_MODE_BYTE] = current_mode + ( current_speed & 0x03 );
|
||||
memcpy(&tt_quad_buffer[channel][THERMALTAKE_QUAD_DATA_BYTE], color_data, (num_colors * 3));
|
||||
|
||||
hid_write(dev, tt_quad_buffer[channel], THERMALTAKE_QUAD_PACKET_SIZE);
|
||||
|
||||
delete[] color_data;
|
||||
}
|
||||
|
||||
void ThermaltakeRiingQuadController::SetMode(unsigned char mode, unsigned char speed)
|
||||
{
|
||||
current_mode = mode;
|
||||
current_speed = speed;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------------------------------*\
|
||||
| Private packet sending functions. |
|
||||
\*-------------------------------------------------------------------------------------------------*/
|
||||
|
||||
void ThermaltakeRiingQuadController::SendInit()
|
||||
{
|
||||
unsigned char usb_buf[THERMALTAKE_QUAD_PACKET_SIZE];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Init packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x00;
|
||||
usb_buf[0x01] = 0xFE;
|
||||
usb_buf[0x02] = 0x33;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, usb_buf, THERMALTAKE_QUAD_PACKET_SIZE);
|
||||
hid_read_timeout(dev, usb_buf, THERMALTAKE_QUAD_PACKET_SIZE, THERMALTAKE_QUAD_INTERRUPT_TIMEOUT);
|
||||
}
|
||||
|
||||
void ThermaltakeRiingQuadController::SendBuffer()
|
||||
{
|
||||
for(std::size_t channel_index = 0; channel_index < THERMALTAKE_QUAD_NUM_CHANNELS; channel_index++)
|
||||
{
|
||||
hid_write(dev, tt_quad_buffer[channel_index], THERMALTAKE_QUAD_PACKET_SIZE);
|
||||
}
|
||||
|
||||
/*-------------------------------------*\
|
||||
| Update the last commit time |
|
||||
\*-------------------------------------*/
|
||||
last_commit_time = std::chrono::steady_clock::now();
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*-------------------------------------------------------------------*\
|
||||
| ThermaltakeRiingQuadController.h |
|
||||
| |
|
||||
| Driver for Thermaltake Riing Quad Controller |
|
||||
| |
|
||||
| Chris M (Dr_No) 15th Feb 2021 |
|
||||
| |
|
||||
\*-------------------------------------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
#define THERMALTAKE_QUAD_PACKET_SIZE 193
|
||||
#define THERMALTAKE_QUAD_INTERRUPT_TIMEOUT 250
|
||||
#define THERMALTAKE_QUAD_KEEPALIVE 3
|
||||
#define HID_MAX_STR 255
|
||||
|
||||
enum
|
||||
{
|
||||
THERMALTAKE_QUAD_COMMAND_BYTE = 1,
|
||||
THERMALTAKE_QUAD_FUNCTION_BYTE = 2,
|
||||
THERMALTAKE_QUAD_ZONE_BYTE = 3,
|
||||
THERMALTAKE_QUAD_MODE_BYTE = 4,
|
||||
THERMALTAKE_QUAD_DATA_BYTE = 5,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
THERMALTAKE_QUAD_MODE_DIRECT = 0x24
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
THERMALTAKE_QUAD_SPEED_EXTREME = 0x00,
|
||||
THERMALTAKE_QUAD_SPEED_FAST = 0x01,
|
||||
THERMALTAKE_QUAD_SPEED_NORMAL = 0x02,
|
||||
THERMALTAKE_QUAD_SPEED_SLOW = 0x03,
|
||||
};
|
||||
|
||||
#define THERMALTAKE_QUAD_NUM_CHANNELS 5
|
||||
|
||||
class ThermaltakeRiingQuadController
|
||||
{
|
||||
public:
|
||||
ThermaltakeRiingQuadController(hid_device* dev_handle, const char* path);
|
||||
~ThermaltakeRiingQuadController();
|
||||
|
||||
std::string GetDeviceName();
|
||||
std::string GetDeviceLocation();
|
||||
std::string GetSerial();
|
||||
|
||||
void SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors);
|
||||
void SetMode(unsigned char mode, unsigned char speed);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
|
||||
unsigned char current_mode;
|
||||
unsigned char current_speed;
|
||||
std::string device_name;
|
||||
std::string serial;
|
||||
std::string location;
|
||||
|
||||
uint8_t tt_quad_buffer[THERMALTAKE_QUAD_NUM_CHANNELS][THERMALTAKE_QUAD_PACKET_SIZE];
|
||||
std::thread* keepalive_thread;
|
||||
std::atomic<bool> keepalive_thread_run;
|
||||
std::chrono::time_point<std::chrono::steady_clock> last_commit_time;
|
||||
|
||||
void SendBuffer();
|
||||
void KeepaliveThread();
|
||||
|
||||
void SendInit();
|
||||
|
||||
void SendFan();
|
||||
void SendSave();
|
||||
};
|
Loading…
Reference in New Issue