Publish LumaOps source

This commit is contained in:
LumaOps release export
2026-09-03 01:18:36 +02:00
commit 7f1c0e5f71
2363 changed files with 501543 additions and 0 deletions
@@ -0,0 +1,789 @@
/*---------------------------------------------------------*\
| LianLiUniHub_AL10Controller.cpp |
| |
| Driver for Lian Li AL10 Uni Hub |
| |
| Oliver P 05 May 2022 |
| Credit to Luca Lovisa for original work |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <cstring>
#include "LianLiUniHub_AL10Controller.h"
using namespace std::chrono_literals;
/*----------------------------------------------------------------------------*\
| The Uni Hub is controlled by sending control transfers to various wIndex |
| addresses, allthough it announces some kind of hid interface. Hence it |
| requires libusb as hidapi provides no wIndex customization. |
\*----------------------------------------------------------------------------*/
LianLiUniHub_AL10Controller::LianLiUniHub_AL10Controller
(
libusb_device* device,
libusb_device_descriptor* descriptor
)
{
int ret;
/*--------------------------------------------------------------------*\
| Open the libusb device. |
\*--------------------------------------------------------------------*/
ret = libusb_open(device, &handle);
if(ret < 0)
{
return;
}
/*--------------------------------------------------------------------*\
| Fill in the location string from USB port numbers. |
\*--------------------------------------------------------------------*/
uint8_t ports[7];
ret = libusb_get_port_numbers(device, ports, sizeof(ports));
if(ret > 0)
{
location = "USB: ";
for (int i = 0; i < ret; i ++)
{
location += std::to_string(ports[i]);
location.push_back(':');
}
location.pop_back();
}
/*--------------------------------------------------------------------*\
| Fill in the serial string from the string descriptor |
\*--------------------------------------------------------------------*/
char serialStr[64];
ret = libusb_get_string_descriptor_ascii(handle, descriptor->iSerialNumber, reinterpret_cast<unsigned char*>(serialStr), sizeof(serialStr));
if(ret > 0)
{
serial = std::string(serialStr, ret);
}
/*--------------------------------------------------------------------*\
| Fill in the version string by reading version from device. |
\*--------------------------------------------------------------------*/
version = ReadVersion();
/*--------------------------------------------------------------------*\
| Create channels with their static configuration and "sane" defaults. |
\*--------------------------------------------------------------------*/
Channel channel1;
channel1.index = 0;
channel1.anyFanCountOffset = UNIHUB_AL10_ANY_C1_FAN_COUNT_OFFSET;
channel1.anyFanCount = UNIHUB_AL10_ANY_FAN_COUNT_001;
channel1.ledActionAddress = UNIHUB_AL10_LED_C1_ACTION_ADDRESS;
channel1.ledCommitAddress = UNIHUB_AL10_LED_C1_COMMIT_ADDRESS;
channel1.ledModeAddress = UNIHUB_AL10_LED_C1_MODE_ADDRESS;
channel1.ledSpeedAddress = UNIHUB_AL10_LED_C1_SPEED_ADDRESS;
channel1.ledDirectionAddress = UNIHUB_AL10_LED_C1_DIRECTION_ADDRESS;
channel1.ledBrightnessAddress = UNIHUB_AL10_LED_C1_BRIGHTNESS_ADDRESS;
channel1.ledMode = UNIHUB_AL10_LED_MODE_RAINBOW;
channel1.ledSpeed = UNIHUB_AL10_LED_SPEED_100;
channel1.ledDirection = UNIHUB_AL10_LED_DIRECTION_LTR;
channel1.ledBrightness = UNIHUB_AL10_LED_BRIGHTNESS_100;
channel1.fanHubActionAddress = UNIHUB_AL10_FAN_C1_HUB_ACTION_ADDRESS;
channel1.fanHubCommitAddress = UNIHUB_AL10_FAN_C1_HUB_COMMIT_ADDRESS;
channel1.fanPwmActionAddress = UNIHUB_AL10_FAN_C1_PWM_ACTION_ADDRESS;
channel1.fanPwmCommitAddress = UNIHUB_AL10_FAN_C1_PWM_COMMIT_ADDRESS;
channel1.fanRpmActionAddress = UNIHUB_AL10_FAN_C1_RPM_ACTION_ADDRESS;
channel1.fanSpeed = UNIHUB_AL10_FAN_SPEED_QUIET;
channels[0] = channel1;
Channel channel2;
channel2.index = 1;
channel2.anyFanCountOffset = UNIHUB_AL10_ANY_C2_FAN_COUNT_OFFSET;
channel2.anyFanCount = UNIHUB_AL10_ANY_FAN_COUNT_001;
channel2.ledActionAddress = UNIHUB_AL10_LED_C2_ACTION_ADDRESS;
channel2.ledCommitAddress = UNIHUB_AL10_LED_C2_COMMIT_ADDRESS;
channel2.ledModeAddress = UNIHUB_AL10_LED_C2_MODE_ADDRESS;
channel2.ledSpeedAddress = UNIHUB_AL10_LED_C2_SPEED_ADDRESS;
channel2.ledDirectionAddress = UNIHUB_AL10_LED_C2_DIRECTION_ADDRESS;
channel2.ledBrightnessAddress = UNIHUB_AL10_LED_C2_BRIGHTNESS_ADDRESS;
channel2.ledMode = UNIHUB_AL10_LED_MODE_RAINBOW;
channel2.ledSpeed = UNIHUB_AL10_LED_SPEED_100;
channel2.ledDirection = UNIHUB_AL10_LED_DIRECTION_LTR;
channel2.ledBrightness = UNIHUB_AL10_LED_BRIGHTNESS_100;
channel2.fanHubActionAddress = UNIHUB_AL10_FAN_C2_HUB_ACTION_ADDRESS;
channel2.fanHubCommitAddress = UNIHUB_AL10_FAN_C2_HUB_COMMIT_ADDRESS;
channel2.fanPwmActionAddress = UNIHUB_AL10_FAN_C2_PWM_ACTION_ADDRESS;
channel2.fanPwmCommitAddress = UNIHUB_AL10_FAN_C2_PWM_COMMIT_ADDRESS;
channel2.fanRpmActionAddress = UNIHUB_AL10_FAN_C2_RPM_ACTION_ADDRESS;
channel2.fanSpeed = UNIHUB_AL10_FAN_SPEED_QUIET;
channels[1] = channel2;
Channel channel3;
channel3.index = 2;
channel3.anyFanCountOffset = UNIHUB_AL10_ANY_C3_FAN_COUNT_OFFSET;
channel3.anyFanCount = UNIHUB_AL10_ANY_FAN_COUNT_001;
channel3.ledActionAddress = UNIHUB_AL10_LED_C3_ACTION_ADDRESS;
channel3.ledCommitAddress = UNIHUB_AL10_LED_C3_COMMIT_ADDRESS;
channel3.ledModeAddress = UNIHUB_AL10_LED_C3_MODE_ADDRESS;
channel3.ledSpeedAddress = UNIHUB_AL10_LED_C3_SPEED_ADDRESS;
channel3.ledDirectionAddress = UNIHUB_AL10_LED_C3_DIRECTION_ADDRESS;
channel3.ledBrightnessAddress = UNIHUB_AL10_LED_C3_BRIGHTNESS_ADDRESS;
channel3.ledMode = UNIHUB_AL10_LED_MODE_RAINBOW;
channel3.ledSpeed = UNIHUB_AL10_LED_SPEED_100;
channel3.ledDirection = UNIHUB_AL10_LED_DIRECTION_LTR;
channel3.ledBrightness = UNIHUB_AL10_LED_BRIGHTNESS_100;
channel3.fanHubActionAddress = UNIHUB_AL10_FAN_C3_HUB_ACTION_ADDRESS;
channel3.fanHubCommitAddress = UNIHUB_AL10_FAN_C3_HUB_COMMIT_ADDRESS;
channel3.fanPwmActionAddress = UNIHUB_AL10_FAN_C3_PWM_ACTION_ADDRESS;
channel3.fanPwmCommitAddress = UNIHUB_AL10_FAN_C3_PWM_COMMIT_ADDRESS;
channel3.fanRpmActionAddress = UNIHUB_AL10_FAN_C3_RPM_ACTION_ADDRESS;
channel3.fanSpeed = UNIHUB_AL10_FAN_SPEED_QUIET;
channels[2] = channel3;
Channel channel4;
channel4.index = 3;
channel4.anyFanCountOffset = UNIHUB_AL10_ANY_C4_FAN_COUNT_OFFSET;
channel4.anyFanCount = UNIHUB_AL10_ANY_FAN_COUNT_001;
channel4.ledActionAddress = UNIHUB_AL10_LED_C4_ACTION_ADDRESS;
channel4.ledCommitAddress = UNIHUB_AL10_LED_C4_COMMIT_ADDRESS;
channel4.ledModeAddress = UNIHUB_AL10_LED_C4_MODE_ADDRESS;
channel4.ledSpeedAddress = UNIHUB_AL10_LED_C4_SPEED_ADDRESS;
channel4.ledDirectionAddress = UNIHUB_AL10_LED_C4_DIRECTION_ADDRESS;
channel4.ledBrightnessAddress = UNIHUB_AL10_LED_C4_BRIGHTNESS_ADDRESS;
channel4.ledMode = UNIHUB_AL10_LED_MODE_RAINBOW;
channel4.ledSpeed = UNIHUB_AL10_LED_SPEED_100;
channel4.ledDirection = UNIHUB_AL10_LED_DIRECTION_LTR;
channel4.ledBrightness = UNIHUB_AL10_LED_BRIGHTNESS_100;
channel4.fanHubActionAddress = UNIHUB_AL10_FAN_C4_HUB_ACTION_ADDRESS;
channel4.fanHubCommitAddress = UNIHUB_AL10_FAN_C4_HUB_COMMIT_ADDRESS;
channel4.fanPwmActionAddress = UNIHUB_AL10_FAN_C4_PWM_ACTION_ADDRESS;
channel4.fanPwmCommitAddress = UNIHUB_AL10_FAN_C4_PWM_COMMIT_ADDRESS;
channel4.fanRpmActionAddress = UNIHUB_AL10_FAN_C4_RPM_ACTION_ADDRESS;
channel4.fanSpeed = UNIHUB_AL10_FAN_SPEED_QUIET;
channels[3] = channel4;
}
LianLiUniHub_AL10Controller::~LianLiUniHub_AL10Controller()
{
CloseLibusb();
}
std::string LianLiUniHub_AL10Controller::GetVersion()
{
return version;
}
std::string LianLiUniHub_AL10Controller::GetLocation()
{
return location;
}
std::string LianLiUniHub_AL10Controller::GetSerial()
{
return serial;
}
void LianLiUniHub_AL10Controller::SetAnyFanCount(size_t channel, uint8_t count)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
channels[channel].anyFanCount = count;
}
void LianLiUniHub_AL10Controller::SetLedColors(size_t channel, RGBColor* colors, size_t count)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
/*-------------------------------------*\
| Check for invalid count |
\*-------------------------------------*/
if(count > UNIHUB_AL10_CHANLED_COUNT)
{
count = UNIHUB_AL10_CHANLED_COUNT;
}
/*-------------------------------------*\
| Check for mode colors |
\*-------------------------------------*/
size_t i = 0;
switch(channels[channel].ledMode)
{
case UNIHUB_AL10_LED_MODE_RAINBOW:
channels[channel].colors[0].r = 0xFC;
channels[channel].colors[0].b = 0xFC;
channels[channel].colors[0].g = 0xFC;
i = 1;
break;
case UNIHUB_AL10_LED_MODE_BREATHING:
for(unsigned int color_idx = 0; color_idx < count; color_idx++)
{
for(unsigned int led_idx = 0; led_idx < 20; led_idx++)
{
channels[channel].colors[led_idx + (color_idx * 20)].r = RGBGetRValue(colors[color_idx]);
channels[channel].colors[led_idx + (color_idx * 20)].b = RGBGetBValue(colors[color_idx]);
channels[channel].colors[led_idx + (color_idx * 20)].g = RGBGetGValue(colors[color_idx]);
i++;
}
}
break;
case UNIHUB_AL10_LED_MODE_SCAN:
for(; i < 20; i++)
{
channels[channel].colors[i].r = 0x00;
channels[channel].colors[i].b = 0x00;
channels[channel].colors[i].g = 0x00;
}
channels[channel].colors[0x00].r = RGBGetRValue(colors[0]);
channels[channel].colors[0x00].b = RGBGetBValue(colors[0]);
channels[channel].colors[0x00].g = RGBGetGValue(colors[0]);
channels[channel].colors[0x08].r = RGBGetRValue(colors[1]);
channels[channel].colors[0x08].b = RGBGetBValue(colors[1]);
channels[channel].colors[0x08].g = RGBGetGValue(colors[1]);
break;
default:
for(; i < count; i++)
{
channels[channel].colors[i].r = (RGBGetRValue(colors[i]));
channels[channel].colors[i].b = (RGBGetBValue(colors[i]));
channels[channel].colors[i].g = (RGBGetGValue(colors[i]));
// Limiter to protect LEDs
if(UNIHUB_AL10_LED_LIMITER && (channels[channel].colors[i].r > 153) && (channels[channel].colors[i].r == channels[channel].colors[i].b) && (channels[channel].colors[i].r == channels[channel].colors[i].g))
{
channels[channel].colors[i].r = 153;
channels[channel].colors[i].b = 153;
channels[channel].colors[i].g = 153;
}
}
}
/* Set all remaining leds to black */
for(; i < UNIHUB_AL10_CHANLED_COUNT; i++)
{
channels[channel].colors[i].r = 0x00;
channels[channel].colors[i].b = 0x00;
channels[channel].colors[i].g = 0x00;
}
}
void LianLiUniHub_AL10Controller::SetLedMode(size_t channel, uint8_t mode)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
channels[channel].ledMode = mode;
}
void LianLiUniHub_AL10Controller::SetLedSpeed(size_t channel, uint8_t speed)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
channels[channel].ledSpeed = speed;
}
void LianLiUniHub_AL10Controller::SetLedDirection(size_t channel, uint8_t direction)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
channels[channel].ledDirection = direction;
}
void LianLiUniHub_AL10Controller::SetLedBrightness(size_t channel, uint8_t brightness)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
channels[channel].ledBrightness = brightness;
}
uint16_t LianLiUniHub_AL10Controller::GetFanSpeed(size_t channel)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return 0;
}
return channels[channel].fanSpeed;
}
void LianLiUniHub_AL10Controller::SetFanSpeed(size_t channel, uint16_t speed)
{
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel >= UNIHUB_AL10_CHANNEL_COUNT)
{
return;
}
channels[channel].fanSpeed = speed;
}
void LianLiUniHub_AL10Controller::EnableRgbhMode()
{
rgbhModeEnabled = true;
}
void LianLiUniHub_AL10Controller::DisableRgbhMode()
{
rgbhModeEnabled = false;
}
void LianLiUniHub_AL10Controller::EnableSyncMode()
{
syncModeEnabled = true;
}
void LianLiUniHub_AL10Controller::DisableSyncMode()
{
syncModeEnabled = false;
}
/*----------------------------------------------------------------------------*\
| The Uni Hub is a PWM and LED controller designed specifically for the Lian |
| Li Uni Fans. It can control them by itself using the built-in effect engine |
| can also be connected to the mainboard via 4-pin PWM and 3-pin RGB cables |
| and forward these signals. The protocol implementation below was build as |
| close a possible to the Lian Li L-Connect software. |
| |
| The commands to control the fan speeds and to switch between controller and |
| mainboard control is already included, but currently deactivated as OpenRGB |
| had no fan control module or controller specific configuration at the time |
| of writing. |
\*----------------------------------------------------------------------------*/
void LianLiUniHub_AL10Controller::Synchronize()
{
/*---------------------------------------------------------------------*\
| Configure common settings. |
\*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*\
| Still unsure about this. Probably some sort of configuration |
| initialization |
\*---------------------------------------------------------------------*/
uint8_t config_initialization[16];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(config_initialization, 0x00, sizeof(config_initialization));
config_initialization[0x0F] = 0x43; // Control data
config_initialization[0x0F] = 0x01; // Ending data
SendConfig(UNIHUB_AL10_ACTION_ADDRESS, config_initialization, sizeof(config_initialization));
for(const Channel& channel : channels)
{
/*-------------------------------------*\
| The Uni Hub doesn't know zero fans |
\*-------------------------------------*/
uint8_t anyFanCount = channel.anyFanCount;
if(anyFanCount == UNIHUB_AL10_ANY_FAN_COUNT_000)
{
anyFanCount = UNIHUB_AL10_ANY_FAN_COUNT_001;
}
/*-------------------------------------*\
| Configure the physical fan count |
\*-------------------------------------*/
uint8_t config_fan_count[16];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(config_fan_count, 0x00, sizeof(config_fan_count));
config_fan_count[0x01] = 0x40; // Control data
config_fan_count[0x02] = channel.index + 1; // Channel
config_fan_count[0x03] = anyFanCount + 1; // Number of fans
config_fan_count[0x0F] = 0x01; // Ending data
SendConfig(UNIHUB_AL10_ACTION_ADDRESS, config_fan_count, sizeof(config_fan_count));
//SendCommit(UNIHUB_AL10_COMMIT_ADDRESS);
}
/*--------------------------------------------------------------------*\
| Configure channels for sync effects |
\*--------------------------------------------------------------------*/
/*
if(syncModeEnabled)
{
uint8_t config_sync[6];
uint8_t config_sync_index = 0;
config_sync[config_sync_index++] = 0x33;
for(const Channel& channel : channels)
{
if(channel.anyFanCount != UNIHUB_AL10_ANY_FAN_COUNT_000)
{
config_sync[config_sync_index++] = channel.index;
}
}
config_sync[config_sync_index++] = 0x08;
SendConfig(UNIHUB_AL10_ACTION_ADDRESS, config_sync, config_sync_index);
SendCommit(UNIHUB_AL10_COMMIT_ADDRESS);
}
*/
/*--------------------------------------------------------------------*\
| Configure led settings. |
\*--------------------------------------------------------------------*/
for(const Channel& channel : channels)
{
if(channel.anyFanCount != UNIHUB_AL10_ANY_FAN_COUNT_000)
{
for(unsigned int fan_idx = 0; fan_idx <= UNIHUB_AL10_ANY_FAN_COUNT_004; fan_idx++)
{
/*-----------------------------*\
| Configure fan colors |
\*-----------------------------*/
uint8_t fan_config_colors[24];
memcpy(fan_config_colors, channel.colors + (fan_idx * 20), sizeof(fan_config_colors));
SendConfig(channel.ledActionAddress + (60 * fan_idx), fan_config_colors, sizeof(fan_config_colors));
}
/*-----------------------------*\
| Configure led mode |
\*-----------------------------*/
uint8_t led_config[16];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(led_config, 0x00, sizeof(led_config));
led_config[0x01] = channel.ledMode; // Effect
led_config[0x02] = channel.ledSpeed; // Speed
led_config[0x03] = channel.ledDirection; // Direction
led_config[0x09] = channel.ledBrightness; // Brightness?
led_config[0x0F] = 0x01; // Ending data
SendConfig(UNIHUB_AL10_ACTION_ADDRESS + (channel.index * 32 ), led_config, sizeof(led_config));
for(unsigned int fan_idx = 0; fan_idx <= UNIHUB_AL10_ANY_FAN_COUNT_004; fan_idx++)
{
/*-----------------------------*\
| Configure rim colors |
\*-----------------------------*/
uint8_t rim_config_colors[36];
memcpy(rim_config_colors, channel.colors + (fan_idx * 20) + 8, sizeof(rim_config_colors));
SendConfig(channel.ledActionAddress + 24 + (60 * fan_idx), rim_config_colors, sizeof(rim_config_colors));
}
SendConfig(UNIHUB_AL10_ACTION_ADDRESS + 16 + (channel.index * 32 ), led_config, sizeof(led_config));
}
/*-----------------------------------------------------------------*\
| The Uni Hub doesn't know zero fans so we set them to black |
\*-----------------------------------------------------------------*/
else
{
for(unsigned int fan_idx = 0; fan_idx <= UNIHUB_AL10_ANY_FAN_COUNT_004; fan_idx++)
{
/*-----------------------------*\
| Configure fan colors |
\*-----------------------------*/
uint8_t fan_config_colors[24];
memset(fan_config_colors, 0x00, sizeof(fan_config_colors));
SendConfig(channel.ledActionAddress + (60 * fan_idx), fan_config_colors, sizeof(fan_config_colors));
}
/*-----------------------------*\
| Configure led mode |
\*-----------------------------*/
uint8_t led_config[16];
/*-----------------------------------------------------*\
| Zero out buffer |
\*-----------------------------------------------------*/
memset(led_config, 0x00, sizeof(led_config));
led_config[0x01] = UNIHUB_AL10_LED_MODE_STATIC_COLOR; // Effect
led_config[0x02] = channel.ledSpeed; // Speed?
led_config[0x03] = channel.ledDirection; // direction
led_config[0x0F] = 0x01; // Ending data
SendConfig(UNIHUB_AL10_ACTION_ADDRESS + (channel.index * 32 ), led_config, sizeof(led_config));
for(unsigned int fan_idx = 0; fan_idx <= UNIHUB_AL10_ANY_FAN_COUNT_004; fan_idx++)
{
/*-----------------------------*\
| Configure rim colors |
\*-----------------------------*/
uint8_t rim_config_colors[36];
memset(rim_config_colors, 0x00, sizeof(rim_config_colors));
SendConfig(channel.ledActionAddress + 24 + (60 * fan_idx), rim_config_colors, sizeof(rim_config_colors));
}
SendConfig(UNIHUB_AL10_ACTION_ADDRESS + 16 + (channel.index * 32 ), led_config, sizeof(led_config));
}
}
/*--------------------------------------------------------------------*\
| Configure fan settings. Comment out until enabling fan control |
\*--------------------------------------------------------------------*/
// uint8_t control = 0;
/*-------------------------------------*\
| Configure fan settings |
\*-------------------------------------*/
// for(const Channel& channel : channels)
// {
// if(channel.fanSpeed == UNIHUB_AL10_FAN_SPEED_PWM)
// {
/*-----------------------------*\
| Configure the fan to pwm |
| control |
\*-----------------------------*/
// uint8_t config_pwm[1] = { 0x00 };
// control |= (0x01 << channel.index);
// SendConfig(channel.fanPwmActionAddress, config_pwm, sizeof(config_pwm));
// SendCommit(channel.fanPwmCommitAddress);
// }
// else
// {
/*-----------------------------*\
| Configure the fan to hub |
| control and set speed |
\*-----------------------------*/
// uint8_t config_hub[2] = { (uint8_t)(channel.fanSpeed >> 0x08), (uint8_t)(channel.fanSpeed & 0xFF) };
// SendConfig(channel.fanHubActionAddress, config_hub, sizeof(config_hub));
// SendCommit(channel.fanHubCommitAddress);
// }
// }
/*-------------------------------------*\
| Configure fan control modes |
\*-------------------------------------*/
// uint8_t config_fan_mode[2] = { 0x31, (uint8_t)(0xF0 | control) };
// SendConfig(UNIHUB_AL10_ACTION_ADDRESS, config_fan_mode, sizeof(config_fan_mode));
// SendCommit(UNIHUB_AL10_COMMIT_ADDRESS);
/*--------------------------------------------------------------------*\
| Configure led settings. |
\*--------------------------------------------------------------------*/
// if(rgbhModeEnabled)
// {
/*-------------------------------------*\
| Configure the leds to hdr control. |
\*-------------------------------------*/
// uint8_t config_hdr[2] = { 0x30, 0x01 };
// SendConfig(UNIHUB_AL10_ACTION_ADDRESS, config_hdr, sizeof(config_hdr));
// SendCommit(UNIHUB_AL10_COMMIT_ADDRESS);
// }
// else
// {
/*-------------------------------------*\
| Configure the leds to hub control |
\*-------------------------------------*/
// uint8_t config_hub[2] = { 0x30, 0x00 };
// SendConfig(UNIHUB_AL10_ACTION_ADDRESS, config_hub, sizeof(config_hub));
// SendCommit(UNIHUB_AL10_COMMIT_ADDRESS);
// }
}
uint16_t LianLiUniHub_AL10Controller::ReadFanSpeed(size_t channel)
{
/*-------------------------------------*\
| Check for invalid handle |
\*-------------------------------------*/
if(handle == nullptr)
{
return(0);
}
/*-------------------------------------*\
| Check for invalid channel |
\*-------------------------------------*/
if(channel > UNIHUB_AL10_CHANNEL_COUNT)
{
return(0);
}
uint8_t buffer[2];
uint8_t length = sizeof(buffer);
uint16_t wIndex = channels[channel].fanRpmActionAddress;
/*-------------------------------------*\
| Send packet |
\*-------------------------------------*/
size_t ret = libusb_control_transfer(handle, /* dev_handle */
0xC0, /* bmRequestType */
0x81, /* bRequest */
0x00, /* wValue */
wIndex, /* wIndex */
buffer, /* data */
length, /* wLength */
1000); /* timeout */
/*-------------------------------------*\
| Check for communication error |
\*-------------------------------------*/
if(ret != length)
{
return(0);
}
return(*(uint16_t*)buffer);
}
void LianLiUniHub_AL10Controller::CloseLibusb()
{
if (handle != nullptr)
{
libusb_close(handle);
handle = nullptr;
}
}
std::string LianLiUniHub_AL10Controller::ReadVersion()
{
/*-------------------------------------*\
| Check for invalid handle |
\*-------------------------------------*/
if(handle == nullptr)
{
return("");
}
uint8_t buffer[5];
uint8_t length = sizeof(buffer);
/*-------------------------------------*\
| Send packet |
\*-------------------------------------*/
size_t ret = libusb_control_transfer(handle, /* dev_handle */
0xC0, /* bmRequestType */
0x81, /* bRequest */
0x00, /* wValue */
0xB500, /* wIndex */
buffer, /* data */
length, /* wLength */
1000); /* timeout */
/*-------------------------------------*\
| Check for communication error |
\*-------------------------------------*/
if(ret != length)
{
return("");
}
/*-------------------------------------*\
| Format version string |
\*-------------------------------------*/
char version[15];
int vlength = std::snprintf(version, sizeof(version), "%x.%x.%x.%x.%x", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
return(std::string(version, vlength));
}
void LianLiUniHub_AL10Controller::SendConfig(uint16_t wIndex, uint8_t *config, size_t length)
{
/*-------------------------------------*\
| Check for invalid handle |
\*-------------------------------------*/
if(handle == nullptr)
{
return;
}
/*-------------------------------------*\
| Send packet |
\*-------------------------------------*/
size_t ret = libusb_control_transfer(handle, /* dev_handle */
0x40, /* bmRequestType */
0x80, /* bRequest */
0x00, /* wValue */
wIndex, /* wIndex */
config, /* data */
(uint16_t)length, /* wLength */
1000); /* timeout */
std::this_thread::sleep_for(5ms);
/*-------------------------------------*\
| Check for communication error |
\*-------------------------------------*/
if(ret != length)
{
return;
}
}
void LianLiUniHub_AL10Controller::SendCommit(uint16_t wIndex)
{
/*-------------------------------------*\
| Set up config packet |
\*-------------------------------------*/
uint8_t config[1] = { 0x01 };
/*-------------------------------------*\
| Send packet |
\*-------------------------------------*/
SendConfig(wIndex, config, sizeof(config));
std::this_thread::sleep_for(5ms);
}
@@ -0,0 +1,273 @@
/*---------------------------------------------------------*\
| LianLiUniHub_AL10Controller.h |
| |
| Driver for Lian Li AL10 Uni Hub |
| |
| Oliver P 05 May 2022 |
| Credit to Luca Lovisa for original work |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <cstdint>
#include <mutex>
#include <string>
#include <libusb.h>
#include "RGBController.h"
/*----------------------------------------------------------------------------*\
| Global definitions. |
\*----------------------------------------------------------------------------*/
enum
{
UNIHUB_AL10_CHANNEL_COUNT = 0x04, /* Channel count */
UNIHUB_AL10_CHANLED_COUNT = 0x50, /* Max-LED per channel count */
};
enum
{
UNIHUB_AL10_ACTION_ADDRESS = 0xE020, /* Global action address */
UNIHUB_AL10_COMMIT_ADDRESS = 0xE02F, /* Global commit address */
};
enum
{
UNIHUB_AL10_ANY_C1_FAN_COUNT_OFFSET = 0x00, /* Channel 1 fan count offset */
UNIHUB_AL10_ANY_C2_FAN_COUNT_OFFSET = 0x14, /* Channel 2 fan count offset */
UNIHUB_AL10_ANY_C3_FAN_COUNT_OFFSET = 0x28, /* Channel 3 fan count offset */
UNIHUB_AL10_ANY_C4_FAN_COUNT_OFFSET = 0x3C, /* Channel 4 fan count offset */
};
enum
{
UNIHUB_AL10_ANY_FAN_COUNT_000 = 0xFF, /* Fan count for 0 fans (dummy value) */
UNIHUB_AL10_ANY_FAN_COUNT_001 = 0x00, /* Fan count for 1 fan */
UNIHUB_AL10_ANY_FAN_COUNT_002 = 0x01, /* Fan count for 2 fans */
UNIHUB_AL10_ANY_FAN_COUNT_003 = 0x02, /* Fan count for 3 fans */
UNIHUB_AL10_ANY_FAN_COUNT_004 = 0x03, /* Fan count for 4 fans */
};
enum
{
UNIHUB_AL10_LED_LIMITER = 1, /* Limit the color white to 999999 as per manufacturer limits in v1.7 */
};
/*----------------------------------------------------------------------------*\
| Definitions related to led configuration. |
\*----------------------------------------------------------------------------*/
enum
{
UNIHUB_AL10_LED_C1_ACTION_ADDRESS = 0xE500, /* Channel 1 led action address */
UNIHUB_AL10_LED_C1_COMMIT_ADDRESS = 0xE02F, /* Channel 1 led commit address */
UNIHUB_AL10_LED_C1_MODE_ADDRESS = 0xE021, /* Channel 1 led mode address */
UNIHUB_AL10_LED_C1_SPEED_ADDRESS = 0xE022, /* Channel 1 led speed address */
UNIHUB_AL10_LED_C1_DIRECTION_ADDRESS = 0xE023, /* Channel 1 led direction address */
UNIHUB_AL10_LED_C1_BRIGHTNESS_ADDRESS = 0xE029, /* Channel 1 led brightness address */
UNIHUB_AL10_LED_C2_ACTION_ADDRESS = 0xE5F0, /* Channel 2 led action address */
UNIHUB_AL10_LED_C2_COMMIT_ADDRESS = 0xE03F, /* Channel 2 led commit address */
UNIHUB_AL10_LED_C2_MODE_ADDRESS = 0xE031, /* Channel 2 led mode address */
UNIHUB_AL10_LED_C2_SPEED_ADDRESS = 0xE032, /* Channel 2 led speed address */
UNIHUB_AL10_LED_C2_DIRECTION_ADDRESS = 0xE033, /* Channel 2 led direction address */
UNIHUB_AL10_LED_C2_BRIGHTNESS_ADDRESS = 0xE039, /* Channel 2 led brightness address */
UNIHUB_AL10_LED_C3_ACTION_ADDRESS = 0xE6E0, /* Channel 3 led action address */
UNIHUB_AL10_LED_C3_COMMIT_ADDRESS = 0xE04F, /* Channel 3 led commit address */
UNIHUB_AL10_LED_C3_MODE_ADDRESS = 0xE041, /* Channel 3 led mode address */
UNIHUB_AL10_LED_C3_SPEED_ADDRESS = 0xE042, /* Channel 3 led speed address */
UNIHUB_AL10_LED_C3_DIRECTION_ADDRESS = 0xE043, /* Channel 3 led direction address */
UNIHUB_AL10_LED_C3_BRIGHTNESS_ADDRESS = 0xE049, /* Channel 3 led brightness address */
UNIHUB_AL10_LED_C4_ACTION_ADDRESS = 0xE7D0, /* Channel 4 led action address */
UNIHUB_AL10_LED_C4_COMMIT_ADDRESS = 0xE05F, /* Channel 4 led commit address */
UNIHUB_AL10_LED_C4_MODE_ADDRESS = 0xE051, /* Channel 4 led mode address */
UNIHUB_AL10_LED_C4_SPEED_ADDRESS = 0xE052, /* Channel 4 led speed address */
UNIHUB_AL10_LED_C4_DIRECTION_ADDRESS = 0xE053, /* Channel 4 led direction address */
UNIHUB_AL10_LED_C4_BRIGHTNESS_ADDRESS = 0xE059, /* Channel 4 led brightness address */
};
enum
{
UNIHUB_AL10_LED_MODE_RAINBOW = 0x05, /* Rainbow mode */
UNIHUB_AL10_LED_MODE_RAINBOW_MORPH = 0xFF, /* Runway mode - Needs updated code */
UNIHUB_AL10_LED_MODE_STATIC_COLOR = 0x01, /* Static Color mode */
UNIHUB_AL10_LED_MODE_BREATHING = 0x02, /* Breathing mode */
UNIHUB_AL10_LED_MODE_TAICHI = 0x2C, /* Neon mode */
UNIHUB_AL10_LED_MODE_COLOR_CYCLE = 0x2B, /* Color Cycle mode */
UNIHUB_AL10_LED_MODE_RUNWAY = 0xFF, /* Runway mode - Needs updated code */
UNIHUB_AL10_LED_MODE_METEOR = 0xFF, /* Meteor mode - Needs updated code */
UNIHUB_AL10_LED_MODE_WARNING = 0x2D, /* Warning mode */
UNIHUB_AL10_LED_MODE_VOICE = 0x22, /* Voice mode */
UNIHUB_AL10_LED_MODE_SPINNING_TEACUP = 0x36, /* Spinning Teacup mode */
UNIHUB_AL10_LED_MODE_TORNADO = 0x34, /* Tornado mode */
UNIHUB_AL10_LED_MODE_MIXING = 0x23, /* Mixing mode */
UNIHUB_AL10_LED_MODE_STACK = 0xFF, /* Stack mode - Needs updated code */
UNIHUB_AL10_LED_MODE_STAGGGERED = 0x35, /* Stagggered mode */
UNIHUB_AL10_LED_MODE_TIDE = 0x25, /* Tide mode */
UNIHUB_AL10_LED_MODE_SCAN = 0x26, /* Scan mode */
UNIHUB_AL10_LED_MODE_CONTEST = 0x33, /* Contest mode */
};
enum
{
UNIHUB_AL10_LED_SPEED_000 = 0x02, /* Very slow speed */
UNIHUB_AL10_LED_SPEED_025 = 0x01, /* Rather slow speed */
UNIHUB_AL10_LED_SPEED_050 = 0x00, /* Medium speed */
UNIHUB_AL10_LED_SPEED_075 = 0xFF, /* Rather fast speed */
UNIHUB_AL10_LED_SPEED_100 = 0xFE, /* Very fast speed */
};
enum
{
UNIHUB_AL10_LED_DIRECTION_LTR = 0x00, /* Left-to-Right direction */
UNIHUB_AL10_LED_DIRECTION_RTL = 0x01, /* Right-to-Left direction */
};
enum
{
UNIHUB_AL10_LED_BRIGHTNESS_000 = 0x08, /* Very dark (off) */
UNIHUB_AL10_LED_BRIGHTNESS_025 = 0x03, /* Rather dark */
UNIHUB_AL10_LED_BRIGHTNESS_050 = 0x02, /* Medium bright */
UNIHUB_AL10_LED_BRIGHTNESS_075 = 0x01, /* Rather bright */
UNIHUB_AL10_LED_BRIGHTNESS_100 = 0x00, /* Very bright */
};
/*----------------------------------------------------------------------------*\
| Definitions related to fan configuration. |
\*----------------------------------------------------------------------------*/
enum
{
UNIHUB_AL10_FAN_C1_HUB_ACTION_ADDRESS = 0xE8A0, /* Channel 1 fan action address for hub control */
UNIHUB_AL10_FAN_C1_HUB_COMMIT_ADDRESS = 0xE890, /* Channel 1 fan commit address for hub control */
UNIHUB_AL10_FAN_C1_PWM_ACTION_ADDRESS = 0xE890, /* Channel 1 fan action address for pwm control */
UNIHUB_AL10_FAN_C1_PWM_COMMIT_ADDRESS = 0xE818, /* Channel 1 fan commit address for pwm control */
UNIHUB_AL10_FAN_C1_RPM_ACTION_ADDRESS = 0xE800, /* Channel 1 fan pwm read address */
UNIHUB_AL10_FAN_C2_HUB_ACTION_ADDRESS = 0xE8A2, /* Channel 2 fan action address for hub control */
UNIHUB_AL10_FAN_C2_HUB_COMMIT_ADDRESS = 0xE891, /* Channel 2 fan commit address for hub control */
UNIHUB_AL10_FAN_C2_PWM_ACTION_ADDRESS = 0xE891, /* Channel 2 fan action address for pwm control */
UNIHUB_AL10_FAN_C2_PWM_COMMIT_ADDRESS = 0xE81A, /* Channel 2 fan commit address for pwm control */
UNIHUB_AL10_FAN_C2_RPM_ACTION_ADDRESS = 0xE802, /* Channel 1 fan pwm read address */
UNIHUB_AL10_FAN_C3_HUB_ACTION_ADDRESS = 0xE8A4, /* Channel 3 fan action address for hub control */
UNIHUB_AL10_FAN_C3_HUB_COMMIT_ADDRESS = 0xE892, /* Channel 3 fan commit address for hub control */
UNIHUB_AL10_FAN_C3_PWM_ACTION_ADDRESS = 0xE892, /* Channel 3 fan action address for pwm control */
UNIHUB_AL10_FAN_C3_PWM_COMMIT_ADDRESS = 0xE81C, /* Channel 3 fan commit address for pwm control */
UNIHUB_AL10_FAN_C3_RPM_ACTION_ADDRESS = 0xE804, /* Channel 1 fan pwm read address */
UNIHUB_AL10_FAN_C4_HUB_ACTION_ADDRESS = 0xE8A6, /* Channel 4 fan action address for hub control */
UNIHUB_AL10_FAN_C4_HUB_COMMIT_ADDRESS = 0xE893, /* Channel 4 fan commit address for hub control */
UNIHUB_AL10_FAN_C4_PWM_ACTION_ADDRESS = 0xE893, /* Channel 4 fan action address for pwm control */
UNIHUB_AL10_FAN_C4_PWM_COMMIT_ADDRESS = 0xE81E, /* Channel 4 fan commit address for pwm control */
UNIHUB_AL10_FAN_C4_RPM_ACTION_ADDRESS = 0xE806, /* Channel 1 fan pwm read address */
};
enum
{
UNIHUB_AL10_FAN_SPEED_QUIET = 0x2003, /* Rather slow */
UNIHUB_AL10_FAN_SPEED_HIGH_SPEED = 0x2206, /* Rather fast */
UNIHUB_AL10_FAN_SPEED_FULL_SPEED = 0x6C07, /* BRRRRRRRRRR */
UNIHUB_AL10_FAN_SPEED_PWM = 0xFFFF, /* PWM Control */
};
/*----------------------------------------------------------------------------*\
| Uni Hub controller. |
\*----------------------------------------------------------------------------*/
class LianLiUniHub_AL10Controller
{
private:
/* The Uni Hub requires colors in RBG order */
struct Color
{
uint8_t r;
uint8_t b;
uint8_t g;
};
/* The values correspond to the definitions above */
struct Channel
{
uint8_t index;
uint8_t anyFanCountOffset;
uint8_t anyFanCount;
uint16_t ledActionAddress;
uint16_t ledCommitAddress;
uint16_t ledModeAddress;
uint16_t ledSpeedAddress;
uint16_t ledDirectionAddress;
uint16_t ledBrightnessAddress;
Color colors[UNIHUB_AL10_CHANLED_COUNT];
uint8_t ledMode;
uint8_t ledSpeed;
uint8_t ledDirection;
uint8_t ledBrightness;
uint16_t fanHubActionAddress;
uint16_t fanHubCommitAddress;
uint16_t fanPwmActionAddress;
uint16_t fanPwmCommitAddress;
uint16_t fanRpmActionAddress;
uint16_t fanSpeed;
};
public:
LianLiUniHub_AL10Controller
(
libusb_device* device,
libusb_device_descriptor* descriptor
);
~LianLiUniHub_AL10Controller();
std::string GetVersion();
std::string GetLocation();
std::string GetSerial();
void SetAnyFanCount(size_t channel, uint8_t count);
void SetLedColors(size_t channel, RGBColor* colors, size_t count);
void SetLedMode(size_t channel, uint8_t mode);
void SetLedSpeed(size_t channel, uint8_t speed);
void SetLedDirection(size_t channel, uint8_t direction);
void SetLedBrightness(size_t channel, uint8_t brightness);
uint16_t GetFanSpeed(size_t channel);
void SetFanSpeed(size_t channel, uint16_t speed);
void EnableRgbhMode();
void DisableRgbhMode();
void EnableSyncMode();
void DisableSyncMode();
uint16_t ReadFanSpeed(size_t channel);
/*-----------------------------------------------------*\
| Synchronize the current configuration to the Uni Hub. |
\*-----------------------------------------------------*/
void Synchronize();
private:
libusb_device_handle* handle = nullptr;
std::string version;
std::string location;
std::string serial;
bool rgbhModeEnabled = false;
bool syncModeEnabled = false;
Channel channels[UNIHUB_AL10_CHANNEL_COUNT];
void CloseLibusb();
std::string ReadVersion();
void SendConfig(uint16_t wIndex, uint8_t *config, size_t length);
void SendCommit(uint16_t wIndex);
};
@@ -0,0 +1,661 @@
/*---------------------------------------------------------*\
| RGBController_LianLiUniHub_AL10.cpp |
| |
| RGBController for Lian Li AL10 Uni Hub |
| |
| Oliver P 05 May 2022 |
| Credit to Luca Lovisa for original work |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include <string>
#include "RGBController_LianLiUniHub_AL10.h"
/**------------------------------------------------------------------*\
@name Lian Li Uni Hub
@type USB
@save :x:
@direct :rotating_light:
@effects :white_check_mark:
@detectors DetectLianLiUniHub
@comment
\*-------------------------------------------------------------------*/
RGBController_LianLiUniHub_AL10::RGBController_LianLiUniHub_AL10(LianLiUniHub_AL10Controller* controller_ptr)
{
controller = controller_ptr;
name = "Lian Li Uni Hub - AL";
vendor = "Lian Li";
version = controller->GetVersion();
type = DEVICE_TYPE_COOLER;
description = "Lian Li Uni Hub - AL v1.0";
location = controller->GetLocation();
serial = controller->GetSerial();
initializedMode = false;
mode Custom;
Custom.name = "Custom";
Custom.value = UNIHUB_AL10_LED_MODE_STATIC_COLOR;
Custom.flags = MODE_FLAG_HAS_PER_LED_COLOR;
Custom.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Custom);
mode RainbowWave;
RainbowWave.name = "Rainbow Wave";
RainbowWave.value = UNIHUB_AL10_LED_MODE_RAINBOW;
RainbowWave.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_DIRECTION_LR;
RainbowWave.speed_min = 0;
RainbowWave.speed_max = 4;
RainbowWave.brightness_min = 0;
RainbowWave.brightness_max = 4;
RainbowWave.speed = 3;
RainbowWave.brightness = 3;
RainbowWave.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
RainbowWave.color_mode = MODE_COLORS_NONE;
//RainbowWave.colors[0] = ToRGBColor(253,253,253);
modes.push_back(RainbowWave);
/* Needs updated code
mode RainbowMorph;
RainbowMorph.name = "Rainbow Morph";
RainbowMorph.value = UNIHUB_AL10_LED_MODE_RAINBOW_MORPH;
RainbowMorph.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS;
RainbowMorph.speed_min = 0;
RainbowMorph.speed_max = 4;
RainbowMorph.brightness_min = 0;
RainbowMorph.brightness_max = 4;
RainbowMorph.speed = 3;
RainbowMorph.brightness = 3;
RainbowMorph.color_mode = MODE_COLORS_NONE;
modes.push_back(RainbowMorph);
*/
mode StaticColor;
StaticColor.name = "Static Color";
StaticColor.value = UNIHUB_AL10_LED_MODE_STATIC_COLOR;
StaticColor.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS;
StaticColor.brightness_min = 0;
StaticColor.brightness_max = 4;
StaticColor.colors_min = 0;
StaticColor.colors_max = 4;
StaticColor.brightness = 3;
StaticColor.color_mode = MODE_COLORS_MODE_SPECIFIC;
StaticColor.colors.resize(4);
modes.push_back(StaticColor);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = UNIHUB_AL10_LED_MODE_BREATHING;
Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Breathing.speed_min = 0;
Breathing.speed_max = 4;
Breathing.brightness_min = 0;
Breathing.brightness_max = 4;
Breathing.colors_min = 0;
Breathing.colors_max = 4;
Breathing.speed = 3;
Breathing.brightness = 3;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors.resize(4);
modes.push_back(Breathing);
mode Taichi;
Taichi.name = "Taichi";
Taichi.value = UNIHUB_AL10_LED_MODE_TAICHI;
Taichi.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Taichi.speed_min = 0;
Taichi.speed_max = 4;
Taichi.brightness_min = 0;
Taichi.brightness_max = 4;
Taichi.colors_min = 0;
Taichi.colors_max = 2;
Taichi.speed = 3;
Taichi.brightness = 3;
Taichi.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
Taichi.color_mode = MODE_COLORS_MODE_SPECIFIC;
Taichi.colors.resize(2);
modes.push_back(Taichi);
mode ColorCycle;
ColorCycle.name = "ColorCycle";
ColorCycle.value = UNIHUB_AL10_LED_MODE_COLOR_CYCLE;
ColorCycle.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
ColorCycle.speed_min = 0;
ColorCycle.speed_max = 4;
ColorCycle.brightness_min = 0;
ColorCycle.brightness_max = 4;
ColorCycle.colors_min = 0;
ColorCycle.colors_max = 4;
ColorCycle.speed = 3;
ColorCycle.brightness = 3;
ColorCycle.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
ColorCycle.color_mode = MODE_COLORS_MODE_SPECIFIC;
ColorCycle.colors.resize(4);
modes.push_back(ColorCycle);
/* Needs updated code
mode Runway;
Runway.name = "Runway";
Runway.value = UNIHUB_AL10_LED_MODE_RUNWAY;
Runway.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Runway.speed_min = 0;
Runway.speed_max = 4;
Runway.brightness_min = 0;
Runway.brightness_max = 4;
Runway.colors_min = 0;
Runway.colors_max = 2;
Runway.speed = 3;
Runway.brightness = 3;
Runway.color_mode = MODE_COLORS_MODE_SPECIFIC;
Runway.colors.resize(2);
modes.push_back(Runway);
*/
/* Needs updated code
mode Meteor;
Meteor.name = "Meteor";
Meteor.value = UNIHUB_AL10_LED_MODE_METEOR;
Meteor.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Meteor.speed_min = 0;
Meteor.speed_max = 4;
Meteor.brightness_min = 0;
Meteor.brightness_max = 4;
Meteor.colors_min = 0;
Meteor.colors_max = 4;
Meteor.speed = 3;
Meteor.brightness = 3;
Meteor.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
Meteor.color_mode = MODE_COLORS_MODE_SPECIFIC;
Meteor.colors.resize(4);
modes.push_back(Meteor);
*/
mode Warning;
Warning.name = "Warning";
Warning.value = UNIHUB_AL10_LED_MODE_WARNING;
Warning.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Warning.speed_min = 0;
Warning.speed_max = 4;
Warning.brightness_min = 0;
Warning.brightness_max = 4;
Warning.colors_min = 0;
Warning.colors_max = 4;
Warning.speed = 3;
Warning.brightness = 3;
Warning.color_mode = MODE_COLORS_MODE_SPECIFIC;
Warning.colors.resize(4);
modes.push_back(Warning);
mode Voice;
Voice.name = "Voice";
Voice.value = UNIHUB_AL10_LED_MODE_VOICE;
Voice.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Voice.speed_min = 0;
Voice.speed_max = 4;
Voice.brightness_min = 0;
Voice.brightness_max = 4;
Voice.colors_min = 0;
Voice.colors_max = 4;
Voice.speed = 3;
Voice.brightness = 3;
Voice.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
Voice.color_mode = MODE_COLORS_MODE_SPECIFIC;
Voice.colors.resize(4);
modes.push_back(Voice);
mode SpinningTeacup;
SpinningTeacup.name = "SpinningTeacup";
SpinningTeacup.value = UNIHUB_AL10_LED_MODE_SPINNING_TEACUP;
SpinningTeacup.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
SpinningTeacup.speed_min = 0;
SpinningTeacup.speed_max = 4;
SpinningTeacup.brightness_min = 0;
SpinningTeacup.brightness_max = 4;
SpinningTeacup.colors_min = 0;
SpinningTeacup.colors_max = 4;
SpinningTeacup.speed = 3;
SpinningTeacup.brightness = 3;
SpinningTeacup.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
SpinningTeacup.color_mode = MODE_COLORS_MODE_SPECIFIC;
SpinningTeacup.colors.resize(4);
modes.push_back(SpinningTeacup);
mode Tornado;
Tornado.name = "Tornado";
Tornado.value = UNIHUB_AL10_LED_MODE_TORNADO;
Tornado.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Tornado.speed_min = 0;
Tornado.speed_max = 4;
Tornado.brightness_min = 0;
Tornado.brightness_max = 4;
Tornado.colors_min = 0;
Tornado.colors_max = 4;
Tornado.speed = 3;
Tornado.brightness = 3;
Tornado.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
Tornado.color_mode = MODE_COLORS_MODE_SPECIFIC;
Tornado.colors.resize(4);
modes.push_back(Tornado);
mode Mixing;
Mixing.name = "Mixing";
Mixing.value = UNIHUB_AL10_LED_MODE_MIXING;
Mixing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Mixing.speed_min = 0;
Mixing.speed_max = 4;
Mixing.brightness_min = 0;
Mixing.brightness_max = 4;
Mixing.colors_min = 0;
Mixing.colors_max = 2;
Mixing.speed = 3;
Mixing.brightness = 3;
Mixing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Mixing.colors.resize(2);
modes.push_back(Mixing);
/* Needs updated code
mode Stack;
Stack.name = "Stack";
Stack.value = UNIHUB_AL10_LED_MODE_STACK;
Stack.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Stack.speed_min = 0;
Stack.speed_max = 4;
Stack.brightness_min = 0;
Stack.brightness_max = 4;
Stack.colors_min = 0;
Stack.colors_max = 2;
Stack.speed = 3;
Stack.brightness = 3;
Stack.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
Stack.color_mode = MODE_COLORS_MODE_SPECIFIC;
Stack.colors.resize(2);
modes.push_back(Stack);
*/
mode Staggered;
Staggered.name = "Staggered";
Staggered.value = UNIHUB_AL10_LED_MODE_STAGGGERED;
Staggered.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Staggered.speed_min = 0;
Staggered.speed_max = 4;
Staggered.brightness_min = 0;
Staggered.brightness_max = 4;
Staggered.colors_min = 0;
Staggered.colors_max = 4;
Staggered.speed = 3;
Staggered.brightness = 3;
Staggered.color_mode = MODE_COLORS_MODE_SPECIFIC;
Staggered.colors.resize(4);
modes.push_back(Staggered);
mode Tide;
Tide.name = "Tide";
Tide.value = UNIHUB_AL10_LED_MODE_TIDE;
Tide.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Tide.speed_min = 0;
Tide.speed_max = 4;
Tide.brightness_min = 0;
Tide.brightness_max = 4;
Tide.colors_min = 0;
Tide.colors_max = 4;
Tide.speed = 3;
Tide.brightness = 3;
Tide.color_mode = MODE_COLORS_MODE_SPECIFIC;
Tide.colors.resize(4);
modes.push_back(Tide);
mode Scan;
Scan.name = "Scan";
Scan.value = UNIHUB_AL10_LED_MODE_SCAN;
Scan.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Scan.speed_min = 0;
Scan.speed_max = 4;
Scan.brightness_min = 0;
Scan.brightness_max = 4;
Scan.colors_min = 0;
Scan.colors_max = 2;
Scan.speed = 3;
Scan.brightness = 3;
Scan.color_mode = MODE_COLORS_MODE_SPECIFIC;
Scan.colors.resize(2);
modes.push_back(Scan);
mode Contest;
Contest.name = "Contest";
Contest.value = UNIHUB_AL10_LED_MODE_CONTEST;
Contest.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_DIRECTION_LR;
Contest.speed_min = 0;
Contest.speed_max = 4;
Contest.brightness_min = 0;
Contest.brightness_max = 4;
Contest.colors_min = 0;
Contest.colors_max = 2;
Contest.speed = 3;
Contest.brightness = 3;
Contest.direction = UNIHUB_AL10_LED_DIRECTION_LTR;
Contest.color_mode = MODE_COLORS_MODE_SPECIFIC;
Contest.colors.resize(3);
modes.push_back(Contest);
/* Motherboard header mode? Not implemented yet
mode Rgbh = makeModeAL();
Rgbh.name = "RGB Header";
Rgbh.value = UNIHUB_AL10_LED_MODE_STATIC_COLOR | 0x0200;
Rgbh.flags = 0;
Rgbh.color_mode = MODE_COLORS_NONE;
modes.push_back(Rgbh);
*/
RGBController_LianLiUniHub_AL10::SetupZones();
}
void RGBController_LianLiUniHub_AL10::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(UNIHUB_AL10_CHANNEL_COUNT);
/*-------------------------------------------------*\
| Set zones and leds |
\*-------------------------------------------------*/
int addressableCounter = 1;
for(unsigned int channel_idx = 0; channel_idx < zones.size(); channel_idx++)
{
zones[channel_idx].name = "Channel ";
zones[channel_idx].name.append(std::to_string(addressableCounter));
addressableCounter++;
zones[channel_idx].type = ZONE_TYPE_LINEAR;
zones[channel_idx].leds_min = 0;
zones[channel_idx].leds_max = UNIHUB_AL10_CHANLED_COUNT;
if(first_run)
{
zones[channel_idx].leds_count = zones[channel_idx].leds_min;
}
for(unsigned int led_ch_idx = 0; led_ch_idx < zones[channel_idx].leds_count; led_ch_idx++)
{
led new_led;
new_led.name = zones[channel_idx].name;
new_led.name.append(", LED ");
new_led.name.append(std::to_string(led_ch_idx + 1));
new_led.value = channel_idx;
leds.push_back(new_led);
}
zones[channel_idx].matrix_map = NULL;
}
SetupColors();
}
void RGBController_LianLiUniHub_AL10::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_LianLiUniHub_AL10::DeviceUpdateLEDs()
{
if(!initializedMode)
{
DeviceUpdateMode();
}
for(size_t channel = 0; channel < zones.size(); channel++)
{
uint8_t fanCount = convertLedCountToFanCount(zones[channel].leds_count);
controller->SetAnyFanCount(channel, convertAnyFanCount(fanCount));
controller->SetLedColors(channel, zones[channel].colors, zones[channel].leds_count);
}
controller->Synchronize();
}
void RGBController_LianLiUniHub_AL10::UpdateZoneLEDs(int zone)
{
if(!initializedMode)
{
DeviceUpdateMode();
}
unsigned int channel = zone;
uint8_t fanCount = convertLedCountToFanCount(zones[channel].leds_count);
controller->SetAnyFanCount(channel, convertAnyFanCount(fanCount));
controller->SetLedColors(channel, zones[channel].colors, zones[channel].leds_count);
controller->Synchronize();
}
void RGBController_LianLiUniHub_AL10::UpdateSingleLED(int led)
{
if(!initializedMode)
{
DeviceUpdateMode();
}
unsigned int channel = leds[led].value;
uint8_t fanCount = convertLedCountToFanCount(zones[channel].leds_count);
controller->SetAnyFanCount(channel, convertAnyFanCount(fanCount));
controller->SetLedColors(channel, zones[channel].colors, zones[channel].leds_count);
controller->Synchronize();
}
void RGBController_LianLiUniHub_AL10::DeviceUpdateMode()
{
initializedMode = true;
for (size_t channel = 0; channel < zones.size(); channel++)
{
uint8_t fanCount = convertLedCountToFanCount(zones[channel].leds_count);
controller->SetAnyFanCount(channel, convertAnyFanCount(fanCount));
switch (modes[active_mode].color_mode)
{
case MODE_COLORS_PER_LED:
controller->SetLedColors(channel, zones[channel].colors, zones[channel].leds_count);
break;
case MODE_COLORS_MODE_SPECIFIC:
controller->SetLedColors(channel, modes[active_mode].colors.data(), modes[active_mode].colors.size());
break;
default:
controller->SetLedColors(channel, nullptr, 0);
break;
}
controller->SetLedMode(channel, modes[active_mode].value);
if(modes[active_mode].flags & MODE_FLAG_HAS_SPEED)
{
controller->SetLedSpeed(channel, convertLedSpeed(modes[active_mode].speed));
}
else
{
controller->SetLedSpeed(channel, UNIHUB_AL10_LED_SPEED_075);
}
if(modes[active_mode].flags & MODE_FLAG_HAS_DIRECTION_LR)
{
controller->SetLedDirection(channel, convertLedDirection(modes[active_mode].direction));
}
else
{
controller->SetLedDirection(channel, UNIHUB_AL10_LED_DIRECTION_LTR);
}
if(modes[active_mode].flags & MODE_FLAG_HAS_BRIGHTNESS)
{
controller->SetLedBrightness(channel, convertLedBrightness(modes[active_mode].brightness));
}
else
{
controller->SetLedBrightness(channel, UNIHUB_AL10_LED_BRIGHTNESS_100);
}
}
if(modes[active_mode].value & 0x0200)
{
controller->EnableRgbhMode();
controller->DisableSyncMode();
}
else if (modes[active_mode].value & 0x0100)
{
controller->DisableRgbhMode();
controller->EnableSyncMode();
}
else
{
controller->DisableRgbhMode();
controller->DisableSyncMode();
}
controller->Synchronize();
}
uint8_t RGBController_LianLiUniHub_AL10::convertAnyFanCount(uint8_t count)
{
switch (count)
{
case 0:
return UNIHUB_AL10_ANY_FAN_COUNT_000;
case 1:
return UNIHUB_AL10_ANY_FAN_COUNT_001;
case 2:
return UNIHUB_AL10_ANY_FAN_COUNT_002;
case 3:
return UNIHUB_AL10_ANY_FAN_COUNT_003;
case 4:
return UNIHUB_AL10_ANY_FAN_COUNT_004;
default:
return UNIHUB_AL10_ANY_FAN_COUNT_001;
}
}
uint8_t RGBController_LianLiUniHub_AL10::convertLedSpeed(uint8_t speed)
{
switch (speed)
{
case 0:
return UNIHUB_AL10_LED_SPEED_000;
case 1:
return UNIHUB_AL10_LED_SPEED_025;
case 2:
return UNIHUB_AL10_LED_SPEED_050;
case 3:
return UNIHUB_AL10_LED_SPEED_075;
case 4:
return UNIHUB_AL10_LED_SPEED_100;
default:
return UNIHUB_AL10_LED_SPEED_050;
}
}
uint8_t RGBController_LianLiUniHub_AL10::convertLedDirection(uint8_t direction)
{
switch (direction)
{
case 0:
return UNIHUB_AL10_LED_DIRECTION_LTR;
case 1:
return UNIHUB_AL10_LED_DIRECTION_RTL;
default:
return UNIHUB_AL10_LED_DIRECTION_LTR;
}
}
uint8_t RGBController_LianLiUniHub_AL10::convertLedBrightness(uint8_t brightness)
{
switch (brightness)
{
case 0:
return UNIHUB_AL10_LED_BRIGHTNESS_000;
case 1:
return UNIHUB_AL10_LED_BRIGHTNESS_025;
case 2:
return UNIHUB_AL10_LED_BRIGHTNESS_050;
case 3:
return UNIHUB_AL10_LED_BRIGHTNESS_075;
case 4:
return UNIHUB_AL10_LED_BRIGHTNESS_100;
default:
return UNIHUB_AL10_LED_BRIGHTNESS_100;
}
}
uint8_t RGBController_LianLiUniHub_AL10::convertLedCountToFanCount(uint8_t count)
{
/*-------------------------------------------------*\
| Converts <20 to 0, 20-39 to 1, 40-59 to 2, 60=79 |
| to 3 and 80+ to 4 |
\*-------------------------------------------------*/
// Sets lower and upper limits
if (count == 0x00)
{
return 0x00;
}
if (count >= 0x50)
{
count = 0x50;
}
/*---------------------------------------------------------*\
| Returns regular count if it's not in multiples of 20s |
| (AL120 has 20 LEDs per fan, LED strip scenario) |
\*---------------------------------------------------------*/
if (count % 20)
{
return(count);
}
else
{
return(count / 20);
}
}
@@ -0,0 +1,46 @@
/*---------------------------------------------------------*\
| RGBController_LianLiUniHub_AL10.h |
| |
| RGBController for Lian Li AL Uni Hub |
| |
| Oliver P 05 May 2022 |
| Credit to Luca Lovisa for original work |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <cstdint>
#include <vector>
#include "LianLiUniHub_AL10Controller.h"
#include "RGBController.h"
class RGBController_LianLiUniHub_AL10 : public RGBController
{
public:
RGBController_LianLiUniHub_AL10(LianLiUniHub_AL10Controller* controller_ptr);
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
uint8_t convertAnyFanCount(uint8_t count);
uint8_t convertLedSpeed(uint8_t speed);
uint8_t convertLedDirection(uint8_t direction);
uint8_t convertLedBrightness(uint8_t brightness);
uint8_t convertLedCountToFanCount(uint8_t count);
private:
LianLiUniHub_AL10Controller* controller;
bool initializedMode;
};