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
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,132 @@
/*---------------------------------------------------------*\
| Gigabyte_Fusion2_USB_Devices.h |
| |
| Gigabyte Fusion 2 USB Device layouts and |
| and mapping to the device IDs stored on chip |
| |
| megadjc 31 Jul 2025 |
| chrism 29 Aug 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-only |
\*---------------------------------------------------------*/
#pragma once
#include <map>
#include "RGBController.h"
#define GB_FUSION2_ZONES_MAX 12
/*--------------------------------------------------------*\
| Base LED mappings found on all controllers. |
\*--------------------------------------------------------*/
enum GB_FUSION2_LED_IDX
{
LED1 = 0,
LED2 = 1,
LED3 = 2,
LED4 = 3,
LED5 = 4,
LED6 = 5,
LED7 = 6,
LED8 = 7,
/*--------------------------------------------------------*\
| IT8297/IT5701/IT5702 ARGB Headers |
\*--------------------------------------------------------*/
HDR_D_LED1 = 5,
HDR_D_LED2 = 6,
HDR_D_LED1_ARGB = 0x58,
HDR_D_LED2_ARGB = 0x59,
/*--------------------------------------------------------*\
| Additional LED mappings found on IT5711 controllers. |
\*--------------------------------------------------------*/
LED9 = 8,
LED10 = 9,
LED11 = 10,
/*--------------------------------------------------------*\
| IT5711 additional ARGB Headers. |
\*--------------------------------------------------------*/
HDR_D_LED3 = 7,
HDR_D_LED4 = 8,
HDR_D_LED3_ARGB = 0x62,
HDR_D_LED4_ARGB = 0x63,
};
/*-------------------------------------------------*\
| LED mapping |
\*-------------------------------------------------*/
using FwdLedHeaders = std::map<std::string, GB_FUSION2_LED_IDX>;
using RvrseLedHeaders = std::map<GB_FUSION2_LED_IDX, std::string>;
const FwdLedHeaders LedLookup =
{
{"LED1", LED1 },
{"LED2", LED2 },
{"LED3", LED3 },
{"LED4", LED4 },
{"LED5", LED5 },
{"LED6", LED6 },
{"LED7", LED7 },
{"LED8", LED8 },
{"LED9", LED9 },
{"LED10", LED10 },
{"LED11", LED11 },
{"HDR_D_LED1", HDR_D_LED1 },
{"HDR_D_LED2", HDR_D_LED2 },
{"HDR_D_LED3", HDR_D_LED3 },
{"HDR_D_LED4", HDR_D_LED4 },
/*-------------------------------------------------*\
| The DLED ARGB index is not required for parsing |
\*-------------------------------------------------*/
/*-------------------------------------------------*\
{"HDR_D_LED1_RGB", HDR_D_LED1_ARGB },
{"HDR_D_LED2_RGB", HDR_D_LED2_ARGB },
{"HDR_D_LED3_RGB", HDR_D_LED3_ARGB },
{"HDR_D_LED4_RGB", HDR_D_LED4_ARGB },
\*-------------------------------------------------*/
};
/*--------------------------------------------------------*\
| The layout_id masks for supported effects. |
\*--------------------------------------------------------*/
enum GB_LID_EFFECTS_MASKS : uint32_t
{
GB_EFF_BREATH = 0x001,
GB_EFF_BEAT = 0x002,
GB_EFF_CYCLE = 0x004,
GB_EFF_FLASH = 0x008,
GB_EFF_RANDOM = 0x010,
GB_EFF_WAVE = 0x020,
GB_EFF_DFLASH = 0x040,
GB_EFF_WAVE1 = 0x080,
GB_EFF_WAVE2 = 0x100,
GB_EFF_CORE_MASK = 0x1FF
};
typedef struct
{
GB_FUSION2_LED_IDX idx;
uint16_t leds_min;
uint16_t leds_max;
std::string name;
} gb_fusion2_zone;
typedef const gb_fusion2_zone* gb_fusion2_layout[GB_FUSION2_ZONES_MAX];
typedef struct
{
gb_fusion2_layout* zones;
uint32_t layout_id;
uint8_t device_num;
std::string name;
} gb_fusion2_device;
/*---------------------------------------------------------------------*\
| These constant values are defined in GigabyteFusion2USB_Devices.cpp |
\*---------------------------------------------------------------------*/
extern const unsigned int GB_FUSION2_DEVICE_COUNT;
extern const gb_fusion2_device** gb_fusion2_device_list;
@@ -0,0 +1,815 @@
/*---------------------------------------------------------*\
| GigabyteRGBFusion2USBController.cpp |
| |
| Driver for Gigabyte Aorus RGB Fusion 2 USB motherboard |
| |
| jackun 08 Jan 2020 |
| megadjc 31 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "GigabyteRGBFusion2USBController.h"
/*-------------------------------------------------------------------------*\
| Low level RGB value conversion table |
| This is stored as a uint32_t in the chip so is trasmitted LSB to MSB |
| Therefore the numbers represent the index where the controller will find |
| respective colour in a regular packet |
\*-------------------------------------------------------------------------*/
static RGBCalibration GigabyteCalibrationsLookup
{
{ "BGR", {{{0x00, 0x01, 0x02, 0x00}}}},
{ "BRG", {{{0x01, 0x00, 0x02, 0x00}}}},
{ "GRB", {{{0x02, 0x00, 0x01, 0x00}}}},
{ "GBR", {{{0x00, 0x02, 0x01, 0x00}}}},
{ "RGB", {{{0x02, 0x01, 0x00, 0x00}}}},
{ "RBG", {{{0x01, 0x02, 0x00, 0x00}}}}
};
/*---------------------------------------------------------*\
| Converts LED counts to divisions in hardware |
\*---------------------------------------------------------*/
static LEDCount LedCountToEnum(unsigned int c)
{
if(c <= 32)
{
return(LEDS_32);
}
else if(c <= 64)
{
return(LEDS_64);
}
else if(c <= 256)
{
return(LEDS_256);
}
else if(c <= 512)
{
return(LEDS_512);
}
else
{
return(LEDS_1024);
}
}
RGBFusion2USBController::RGBFusion2USBController(hid_device* handle, const char* path, std::string mb_name, uint16_t pid): dev(handle), product_id(pid)
{
name = mb_name;
location = path;
if(!RefreshHardwareInfo())
{
return;
}
if(report.support_cmd_flag >= 0x02)
{
EnableLampArray(false);
}
ResetController();
EnableBeat(false);
}
RGBFusion2USBController::~RGBFusion2USBController()
{
hid_close(dev);
}
/*---------------------------------------------------------*\
| Read configuration data from hardware. |
| Returns false if read fails. |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::RefreshHardwareInfo()
{
unsigned char buffer[FUSION2_USB_BUFFER_SIZE] = {0};
SendCCReport(0x60, 0x00);
buffer[0] = report_id;
int res = hid_get_feature_report(dev, buffer, sizeof(buffer));
if(res < static_cast<int>(sizeof(IT8297Report)))
{
report_loaded = false;
return false;
}
std::memcpy(&report, buffer, sizeof(IT8297Report));
report_loaded = true;
device_num = report.device_num;
description = std::string(report.str_product, 28);
if(std::string::iterator nul = std::find(description.begin(), description.end(), '\0');
nul != description.end())
{
description.erase(nul, description.end());
}
{
char text[16]{};
std::snprintf(
text,
sizeof(text),
"%u.%u.%u.%u",
(report.fw_ver ) & 0xFF,
(report.fw_ver >> 8) & 0xFF,
(report.fw_ver >> 16) & 0xFF,
(report.fw_ver >> 24) & 0xFF
);
version = text;
std::snprintf(text, sizeof(text), "0x%08X", report.chip_id);
chip_id = text;
}
D_LED1_count = LedCountToEnum(report.curr_led_count_low & 0x0F);
D_LED2_count = LedCountToEnum((report.curr_led_count_low >> 4) & 0x0F);
D_LED3_count = LedCountToEnum(report.curr_led_count_high & 0x0F);
D_LED4_count = LedCountToEnum((report.curr_led_count_high >> 4) & 0x0F);
cal_data.dled[0] = report.cal_strip0;
cal_data.dled[1] = report.cal_strip1;
cal_data.mainboard = report.rgb_cali;
cal_data.spare[0] = report.cal_spare0;
cal_data.spare[1] = report.cal_spare1;
cali_loaded = false;
if(product_id == 0x5711)
{
unsigned char buffer2[FUSION2_USB_BUFFER_SIZE] = {0};
SendCCReport(0x61, 0x00);
buffer2[0] = report_id;
int res2 = hid_get_feature_report(dev, buffer2, sizeof(buffer2));
if(res2 >= static_cast<int>(sizeof(IT5711Calibration)))
{
IT5711Calibration cali;
std::memcpy(&cali, buffer2, sizeof(IT5711Calibration));
cali_loaded = true;
cal_data.dled[2] = cali.cal_strip2;
cal_data.dled[3] = cali.cal_strip3;
cal_data.spare[2] = cali.cal_spare2;
cal_data.spare[3] = cali.cal_spare3;
}
else
{
cal_data.dled[2] = 0;
cal_data.dled[3] = 0;
cal_data.spare[2] = 0;
cal_data.spare[3] = 0;
cali_loaded = false;
}
}
else
{
cal_data.dled[2] = 0;
cal_data.dled[3] = 0;
cal_data.spare[2] = 0;
cal_data.spare[3] = 0;
}
return report_loaded;
}
std::string RGBFusion2USBController::DecodeCalibrationBuffer(uint32_t value) const
{
std::string out = "OFF";
if(value == 0)
{
return out;
}
uint8_t bo_b = value & 0xFF;
uint8_t bo_g = (value >> 8 ) & 0xFF;
uint8_t bo_r = (value >> 16) & 0xFF;
bool in_range = (bo_r < 3 && bo_g < 3 && bo_b < 3);
bool distinct = (bo_r != bo_g && bo_r != bo_b && bo_g != bo_b);
if(in_range && distinct)
{
out[bo_r] = 'R';
out[bo_g] = 'G';
out[bo_b] = 'B';
return out;
}
return "BAD";
}
uint32_t RGBFusion2USBController::EncodeCalibrationBuffer(const std::string& rgb_order)
{
if(rgb_order.empty())
{
return 0u;
}
std::string key = rgb_order;
std::transform(key.begin(), key.end(), key.begin(),
[](unsigned char c){ return char(std::toupper(c)); });
if(key=="OFF" || key=="0")
{
return 0u;
}
RGBCalibration::const_iterator it = GigabyteCalibrationsLookup.find(key);
if(it == GigabyteCalibrationsLookup.end())
{
return 0u;
}
const RGBA &rgb_cal = it->second;
return (uint32_t(rgb_cal.raw[0]))
| (uint32_t(rgb_cal.raw[1]) << 8)
| (uint32_t(rgb_cal.raw[2]) << 16)
| (uint32_t(rgb_cal.raw[3]) << 24);
}
EncodedCalibration RGBFusion2USBController::GetCalibration(bool refresh_from_hw)
{
if(refresh_from_hw || !report_loaded || (product_id == 0x5711 && !cali_loaded))
{
if(!RefreshHardwareInfo())
{
return EncodedCalibration{};
}
}
EncodedCalibration out{};
out.dled[0] = DecodeCalibrationBuffer(cal_data.dled[0]);
out.dled[1] = DecodeCalibrationBuffer(cal_data.dled[1]);
out.spare[0] = DecodeCalibrationBuffer(cal_data.spare[0]);
out.spare[1] = DecodeCalibrationBuffer(cal_data.spare[1]);
out.mainboard = DecodeCalibrationBuffer(cal_data.mainboard);
if(product_id == 0x5711)
{
out.dled[2] = DecodeCalibrationBuffer(cal_data.dled[2]);
out.dled[3] = DecodeCalibrationBuffer(cal_data.dled[3]);
out.spare[2] = DecodeCalibrationBuffer(cal_data.spare[2]);
out.spare[3] = DecodeCalibrationBuffer(cal_data.spare[3]);
}
else
{
out.dled[2] = "OFF";
out.dled[3] = "OFF";
out.spare[2] = "OFF";
out.spare[3] = "OFF";
}
return out;
}
bool RGBFusion2USBController::SetCalibration(const EncodedCalibration& cal, bool refresh_from_hw)
{
if(refresh_from_hw && !RefreshHardwareInfo())
{
return false;
}
if(EncodeCalibrationBuffer(cal.dled[0]) == cal_data.dled[0]
&& EncodeCalibrationBuffer(cal.dled[1]) == cal_data.dled[1]
&& EncodeCalibrationBuffer(cal.mainboard) == cal_data.mainboard
&& EncodeCalibrationBuffer(cal.spare[0]) == cal_data.spare[0]
&& EncodeCalibrationBuffer(cal.spare[1]) == cal_data.spare[1]
&& (product_id != 0x5711
|| (EncodeCalibrationBuffer(cal.dled[2]) == cal_data.dled[2]
&& EncodeCalibrationBuffer(cal.dled[3]) == cal_data.dled[3]
&& EncodeCalibrationBuffer(cal.spare[2]) == cal_data.spare[2]
&& EncodeCalibrationBuffer(cal.spare[3]) == cal_data.spare[3])))
{
return true;
}
CMD_0x33 desired;
desired.c.d_strip_c0 = EncodeCalibrationBuffer(cal.dled[0]);
desired.c.d_strip_c1 = EncodeCalibrationBuffer(cal.dled[1]);
desired.c.rgb_cali = EncodeCalibrationBuffer(cal.mainboard);
desired.c.c_spare0 = EncodeCalibrationBuffer(cal.spare[0]);
desired.c.c_spare1 = EncodeCalibrationBuffer(cal.spare[1]);
if(product_id == 0x5711)
{
desired.c.d_strip_c2 = EncodeCalibrationBuffer(cal.dled[2]);
desired.c.d_strip_c3 = EncodeCalibrationBuffer(cal.dled[3]);
desired.c.c_spare2 = EncodeCalibrationBuffer(cal.spare[2]);
desired.c.c_spare3 = EncodeCalibrationBuffer(cal.spare[3]);
}
int rc = SendPacket(desired.buffer);
if(rc < 0)
{
return false;
}
ResetController();
std::this_thread::sleep_for(std::chrono::milliseconds(20));
SaveCalState();
std::this_thread::sleep_for(std::chrono::milliseconds(20));
cal_data.dled[0] = desired.c.d_strip_c0;
cal_data.dled[1] = desired.c.d_strip_c1;
cal_data.mainboard = desired.c.rgb_cali;
cal_data.spare[0] = desired.c.c_spare0;
cal_data.spare[1] = desired.c.c_spare1;
if(product_id == 0x5711)
{
cal_data.dled[2] = desired.c.d_strip_c2;
cal_data.dled[3] = desired.c.d_strip_c3;
cal_data.spare[2] = desired.c.c_spare2;
cal_data.spare[3] = desired.c.c_spare3;
}
else
{
cal_data.dled[2] = 0u;
cal_data.dled[3] = 0u;
cal_data.spare[2] = 0u;
cal_data.spare[3] = 0u;
}
return true;
}
void RGBFusion2USBController::SetLedCount(unsigned int c0, unsigned int c1, unsigned int c2, unsigned int c3)
{
LEDCount new_d1 = LedCountToEnum(c0);
LEDCount new_d2 = LedCountToEnum(c1);
LEDCount new_d3 = LedCountToEnum(c2);
LEDCount new_d4 = LedCountToEnum(c3);
if(new_d1 == D_LED1_count && new_d2 == D_LED2_count && new_d3 == D_LED3_count && new_d4 == D_LED4_count)
{
return;
}
D_LED1_count = new_d1;
D_LED2_count = new_d2;
D_LED3_count = new_d3;
D_LED4_count = new_d4;
SendCCReport(0x34, (new_d2 << 4) | new_d1, (new_d4 << 4) | new_d3);
}
/*---------------------------------------------------------*\
| Switch ARGB header mode (single/addressable) |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::SetStripBuiltinEffectState(int hdr, bool enable)
{
int bitmask = 0;
if(hdr == -1)
{
bitmask = 0x01 | 0x02 | 0x08 | 0x10;
}
else
{
switch(hdr)
{
case LED4:
case HDR_D_LED2:
case HDR_D_LED2_ARGB:
bitmask = 0x02;
break;
case HDR_D_LED3:
case HDR_D_LED3_ARGB:
bitmask = 0x08;
break;
case HDR_D_LED4:
case HDR_D_LED4_ARGB:
bitmask = 0x10;
break;
default:
bitmask = 0x01;
break;
}
}
int base_mask = (effect_disabled < 0) ? 0 : effect_disabled;
int new_effect_disabled = enable
? (base_mask & ~bitmask)
: (base_mask | bitmask);
// Skip redundant writes only after we have synchronized at least once
if(effect_disabled >= 0 && new_effect_disabled == effect_disabled)
{
return true;
}
effect_disabled = new_effect_disabled;
int res = SendCCReport(0x32, effect_disabled);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return res;
}
/*---------------------------------------------------------*\
| Persist LED config data |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::SaveLEDState(bool e)
{
return SendCCReport(0x47, e ? 1 : 0);
}
/*---------------------------------------------------------*\
| Persist calibration |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::SaveCalState()
{
return SendCCReport(0x5E, 0);
}
/*---------------------------------------------------------*\
| Set beat mode (hardware audio sync mode) |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::EnableBeat(bool e)
{
return SendCCReport(0x31, e ? 1 : 0);
}
/*---------------------------------------------------------*\
| Set Lamp Array mode (MSDL) |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::EnableLampArray(bool enable)
{
return SendCCReport(0x48, enable ? 1 : 0);
}
std::string RGBFusion2USBController::GetDeviceName()
{
return(name);
}
std::string RGBFusion2USBController::GetDeviceDescription()
{
return(description);
}
std::string RGBFusion2USBController::GetFWVersion()
{
return(version);
}
std::string RGBFusion2USBController::GetDeviceLocation()
{
return("HID: " + location);
}
std::string RGBFusion2USBController::GetSerial()
{
return(chip_id);
}
/*---------------------------------------------------------*\
| PID (controller feature support) |
\*---------------------------------------------------------*/
uint16_t RGBFusion2USBController::GetProductID()
{
return(product_id);
}
/*---------------------------------------------------------*\
| Low level controller number (multi-controller) |
\*---------------------------------------------------------*/
uint8_t RGBFusion2USBController::GetDeviceNum()
{
return(device_num);
}
/*---------------------------------------------------------*\
| Set ARGB strips (addressable) |
\*---------------------------------------------------------*/
void RGBFusion2USBController::SetStripColors(unsigned int hdr, RGBColor* colors, unsigned int num_colors, int single_led)
{
PktRGB pkt;
pkt.Init(hdr, report_id);
uint32_t byteorder;
switch(pkt.s.header)
{
case HDR_D_LED2_ARGB:
byteorder = cal_data.dled[1];
break;
case HDR_D_LED3_ARGB:
byteorder = cal_data.dled[2];
break;
case HDR_D_LED4_ARGB:
byteorder = cal_data.dled[3];
break;
default:
byteorder = cal_data.dled[0];
break;
}
unsigned char bo_r = byteorder >> 16;
unsigned char bo_g = byteorder >> 8;
unsigned char bo_b = byteorder & 0xFF;
int res;
int leds_left = num_colors;
int sent_data = 0;
int k = 0;
int leds_in_pkt = sizeof(pkt.s.leds) / sizeof(*pkt.s.leds); /* 19 */
if(single_led > -1)
{
leds_left = 1;
k = single_led;
sent_data = k * 3;
leds_in_pkt = 1;
}
while(leds_left > 0)
{
leds_in_pkt = (std::min)(leds_in_pkt, leds_left);
leds_left -= leds_in_pkt;
pkt.s.bcount = leds_in_pkt * 3;
pkt.s.boffset = sent_data;
sent_data += pkt.s.bcount;
for(int i = 0; i < leds_in_pkt; i++)
{
RGBColor color = colors[k];
uint8_t offset = (i * 3) + 5;
pkt.buffer[offset + bo_r] = RGBGetRValue(color);
pkt.buffer[offset + bo_g] = RGBGetGValue(color);
pkt.buffer[offset + bo_b] = RGBGetBValue(color);
k++;
}
res = SendPacket(pkt.buffer);
if(res < 0)
{
return;
}
}
}
/*---------------------------------------------------------*\
| Set hardware effects (single) |
| Note: Effects paramters match that of gigabyte software. |
| -(2)Gigabyte breathe ranges are 400-1000ms in 100ms steps |
| and 1000-1600ms in 200ms steps |
| -(3)Gigabyte flash ranges are 600-2400ms in 200ms steps |
| -(4)Gigabyte color cycle ranges are 300-2400ms for period0|
| and 100-2200ms for period1 in 100ms steps. |
| the follow this trend between 300-1100/100-1000ms |
| then jump to 2400ms and 2200ms respective on speed 9. |
| -(6)Gigabyte Wave ranges are 30-300ms in steps following |
| the following formula. 2.5(s+1)^2 + 2.5(s+1) + 25. |
| -(15)Gigabyte dflash ranges are 800-2600ms in 200ms steps |
| -(3)(15)flash and dflash parameters were combined. |
\*---------------------------------------------------------*/
void RGBFusion2USBController::SetLEDEffect(int led, int mode, unsigned int speed, unsigned char brightness, bool random, uint32_t* color)
{
PktEffect pkt;
pkt.Init(led, report_id, product_id);
if(led == -1)
{
effect_zone_mask = pkt.e.zone0;
}
else if((effect_zone_mask & pkt.e.zone0) == 0)
{
effect_zone_mask |= pkt.e.zone0;
}
pkt.e.max_brightness = brightness;
pkt.e.effect_type = mode;
pkt.e.effect_param0 = random ? 7 : 0;
pkt.e.color0 = RGBToBGRColor(*color);
switch(mode)
{
case EFFECT_PULSE:
pkt.e.period0 = (speed <= 6) ? (400 + speed * 100) : (1000 + (speed - 6) * 200);
pkt.e.period1 = pkt.e.period0;
pkt.e.period2 = 200;
break;
case EFFECT_DFLASH:
pkt.e.effect_type = 3;
pkt.e.effect_param1 = 1;
pkt.e.effect_param2 = 2;
case EFFECT_BLINKING:
pkt.e.period0 = 100;
pkt.e.period1 = 100;
pkt.e.period2 = (speed * 200) + 700;
break;
case EFFECT_COLORCYCLE:
pkt.e.period0 = (speed * 100 + 300) + (speed > 8 ? 1300 * (speed - 8) : 0);
pkt.e.period1 = pkt.e.period0 -200;
pkt.e.effect_param0 = 7;
break;
case EFFECT_WAVE:
pkt.e.period0 = (((speed + 1)^2) + (speed + 1) + 10) * 5 / 2;
pkt.e.effect_param0 = 7;
pkt.e.effect_param1 = 1;
break;
case EFFECT_RANDOM:
pkt.e.period0 = 100;
pkt.e.effect_param0 = 1;
pkt.e.effect_param1 = 5;
break;
case EFFECT_WAVE1:
pkt.e.period0 = 1200;
pkt.e.period1 = 100;
pkt.e.period2 = 360;
pkt.e.period3 = 1200;
break;
case EFFECT_WAVE2:
case EFFECT_WAVE4:
pkt.e.period0 = 200;
pkt.e.effect_param0 = 7;
break;
case EFFECT_WAVE3:
pkt.e.period0 = 840;
pkt.e.period1 = 20;
pkt.e.period2 = 200;
pkt.e.period3 = 840;
break;
}
SendPacket(pkt.buffer);
}
/*---------------------------------------------------------*\
| Apply hardware effects (single) |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::ApplyEffect(bool fast_apply)
{
if(fast_apply)
{
if(product_id == 0x5711)
{
return SendCCReport(0x28, 0xFF, 0x07);
}
else
{
return SendCCReport(0x28, 0xFF, 0x00);
}
}
PktEffectApply pkt = {};
pkt.a.zone_sel0 = effect_zone_mask;
effect_zone_mask = 0;
return SendPacket(pkt.buffer);
}
bool RGBFusion2USBController::SendCCReport(uint8_t a, uint8_t b, uint8_t c)
{
return(SendReport(report_id, a, b, c));
}
bool RGBFusion2USBController::SendReport(uint8_t id, uint8_t a, uint8_t b, uint8_t c)
{
unsigned char buffer[FUSION2_USB_BUFFER_SIZE] {};
std::memset(buffer, 0, FUSION2_USB_BUFFER_SIZE);
buffer[0] = id;
buffer[1] = a;
buffer[2] = b;
buffer[3] = c;
return(SendPacket(buffer) == FUSION2_USB_BUFFER_SIZE);
}
int RGBFusion2USBController::SendPacket(unsigned char* packet)
{
return hid_send_feature_report(dev, packet, FUSION2_USB_BUFFER_SIZE);
}
/*---------------------------------------------------------*\
| Reset controller parameters |
\*---------------------------------------------------------*/
void RGBFusion2USBController::ResetController()
{
for(uint8_t reg = 0x20; reg <= 0x27; ++reg)
{
SendCCReport(reg, 0x00, 0x00);
}
if(product_id == 0x5711)
{
for(uint8_t reg = 0x90; reg <= 0x92; ++reg)
{
SendCCReport(reg, 0x00, 0x00);
}
}
ApplyEffect(true);
}
/*---------------------------------------------------------*\
| Check controller for gen2 ARGB support |
| Checks for supported device number |
| Then checks for supported controllers |
| Then checks for supported feature bit (SaveLEDState) |
| Finally checks for strip detection value. |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::SupportsGen2() const
{
bool supports_gen2 = false;
supports_gen2 = (device_num == 0x00)
&& (product_id == 0x5702 || product_id==0x5711 || product_id==0x8950)
&& (report.support_cmd_flag & 0x01)
&& (report.strip_detect == 0x01);
return supports_gen2;
}
std::vector<Gen2StripInfo> RGBFusion2USBController::ExportGen2Strips() const
{
size_t count = (product_id == 0x5711) ? 4u : 2u;
std::vector<Gen2StripInfo> out;
out.reserve(count);
for(size_t i = 0; i < count; ++i)
{
out.push_back(g2_strip_info[i]);
}
return out;
}
/*---------------------------------------------------------*\
| Scan Headers for Gen2 Devices |
\*---------------------------------------------------------*/
bool RGBFusion2USBController::ScanGen2Strips()
{
for(unsigned i = 0; i < 4; ++i)
{
if(g2_strip_info[i].LedsOfStrip.capacity() < 15)
{
g2_strip_info[i].LedsOfStrip.reserve(15);
}
g2_strip_info[i].numStrip = 0;
g2_strip_info[i].totalLeds = 0;
g2_strip_info[i].LedsOfStrip.resize(0);
}
const unsigned int hdr_lim = (product_id == 0x5711) ? 4u : 2u;
for(unsigned int slot = 0; slot < hdr_lim; ++slot)
{
static constexpr uint8_t delta[4] = {4, 5, 0, 1};
uint8_t scan_cmd = static_cast<uint8_t>(GEN2_LED_BASE_SCAN + delta[slot]);
uint8_t info_cmd = static_cast<uint8_t>(scan_cmd + 2);
if(!SendCCReport(scan_cmd, 0x00, 0x00))
{
return false;
}
std::this_thread::sleep_for(std::chrono::milliseconds(700));
if(!SendCCReport(info_cmd, 0x00, 0x00))
{
return false;
}
unsigned char feature_buf[64] = {0};
feature_buf[0] = report_id;
int recv_len = hid_get_feature_report(dev, feature_buf, sizeof(feature_buf));
if(recv_len < 64)
{
return false;
}
int seg_count = static_cast<int>(feature_buf[1]);
if(seg_count < 0)
{
seg_count = 0;
}
if(seg_count > 15)
{
seg_count = 15;
}
Gen2StripInfo& dst = g2_strip_info[slot];
dst.numStrip = static_cast<uint8_t>(seg_count);
dst.LedsOfStrip.resize(static_cast<size_t>(seg_count));
uint32_t total_leds = 0;
const int counts_base = 2;
for(int k = 0; k < seg_count; ++k)
{
const int off = counts_base + (k * 2);
uint16_t lo = static_cast<uint16_t>(feature_buf[off + 0]);
uint16_t hi = static_cast<uint16_t>(feature_buf[off + 1]);
uint16_t cnt = static_cast<uint16_t>(lo | (hi << 8));
dst.LedsOfStrip[static_cast<size_t>(k)] = cnt;
total_leds += cnt;
}
dst.totalLeds = total_leds;
SetLedCount(0, 0, 0, 0);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
SaveLEDState(false);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
return true;
}
@@ -0,0 +1,386 @@
/*---------------------------------------------------------*\
| GigabyteRGBFusion2USBController.h |
| |
| Driver for Gigabyte Aorus RGB Fusion 2 USB motherboard |
| |
| jackun 08 Jan 2020 |
| megadjc 31 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <algorithm>
#include <cstring>
#include <hidapi.h>
#include <map>
#include "RGBController.h"
#include "GigabyteFusion2USB_Devices.h"
#define FUSION2_USB_BUFFER_SIZE 64
/*--------------------------------------------------------*\
| Gen2 scan/info opcode base |
\*--------------------------------------------------------*/
#define GEN2_LED_BASE_SCAN 0x38
/*---------------------------------------------------------*\
| Effects mode list |
\*---------------------------------------------------------*/
enum EffectType
{
EFFECT_NONE = 0,
EFFECT_STATIC = 1,
EFFECT_PULSE = 2,
EFFECT_BLINKING = 3,
EFFECT_COLORCYCLE = 4,
EFFECT_WAVE = 6,
EFFECT_RANDOM = 8,
EFFECT_WAVE1 = 9,
EFFECT_WAVE2 = 10,
EFFECT_WAVE3 = 11,
EFFECT_WAVE4 = 12,
EFFECT_DFLASH = 15,
// to be continued...
};
/*---------------------------------------------------------*\
| Low level strip length divisions |
\*---------------------------------------------------------*/
enum LEDCount
{
LEDS_32 = 0,
LEDS_64,
LEDS_256,
LEDS_512,
LEDS_1024,
};
/*---------------------------------------------------------*\
| Defines the RGB led data structure. |
\*---------------------------------------------------------*/
struct LEDs
{
uint8_t r;
uint8_t g;
uint8_t b;
};
/*---------------------------------------------------------*\
| Defines structure for low level calibration data. |
\*---------------------------------------------------------*/
struct CalibrationData
{
uint32_t dled[4] = {0, 0, 0, 0};
uint32_t spare[4] = {0, 0, 0, 0};
uint32_t mainboard = 0;
};
/*---------------------------------------------------------*\
| Defines structure for high level calibration data. |
\*---------------------------------------------------------*/
struct EncodedCalibration
{
std::string dled[4];
std::string spare[4];
std::string mainboard;
};
/*---------------------------------------------------------*\
| High level struct to contain Gen2 Header Data |
\*---------------------------------------------------------*/
struct Gen2StripInfo
{
uint8_t numStrip = 0;
std::vector<uint16_t> LedsOfStrip;
uint32_t totalLeds = 0;
};
#pragma pack(push, 1)
/*---------------------------------------------------------*\
| Packet structure for applying effects |
\*---------------------------------------------------------*/
union PktEffectApply
{
unsigned char buffer[FUSION2_USB_BUFFER_SIZE];
struct apply_data
{
uint8_t report_id = 0xCC;
uint8_t command_id = 0x28;
uint32_t zone_sel0 = 0;
uint32_t zone_sel1 = 0;
uint8_t padding[54];
} a;
PktEffectApply() : a {}
{
std::memset(a.padding, 0, sizeof(a.padding));
}
};
/*---------------------------------------------------------*\
| Single LED Calibration struct |
\*---------------------------------------------------------*/
struct RGBA
{
union
{
uint8_t raw[4];
struct
{
uint8_t blue;
uint8_t green;
uint8_t red;
uint8_t alpha;
};
};
};
typedef std::map< std::string, RGBA > RGBCalibration;
typedef std::map< std::string, std::string> calibration;
/*---------------------------------------------------------*\
| Packet structure for ARGB headers (addressable) |
\*---------------------------------------------------------*/
union PktRGB
{
unsigned char buffer[FUSION2_USB_BUFFER_SIZE];
struct RGBData
{
uint8_t report_id;
uint8_t header;
uint16_t boffset;
uint8_t bcount;
LEDs leds[19];
uint16_t padding0;
} s;
PktRGB() : s {}
{
}
void Init(uint8_t header, uint8_t report_id)
{
switch(header)
{
case LED4:
case HDR_D_LED2:
header = HDR_D_LED2_ARGB;
break;
case HDR_D_LED3:
header = HDR_D_LED3_ARGB;
break;
case HDR_D_LED4:
header = HDR_D_LED4_ARGB;
break;
default:
header = HDR_D_LED1_ARGB;
break;
}
s.report_id = report_id;
s.header = header;
s.boffset = 0;
s.bcount = 0;
memset(s.leds, 0, sizeof(s.leds));
}
};
/*---------------------------------------------------------*\
| Packet structure for hardware effects |
| Default values for Hardware Effects mode. |
| Old init values. |
| (All values 0 unless otherwise noted below) |
| e.color0 = 0x00FF2100; //orange |
| e.period1 = 1200; |
| e.period2 = 200; |
| e.period3 = 200; |
| e.effect_param2 = 1; |
\*---------------------------------------------------------*/
union PktEffect
{
unsigned char buffer[FUSION2_USB_BUFFER_SIZE];
struct Effect
{
uint8_t report_id = 0;
uint8_t header = 0;
uint32_t zone0 = 0; // RGB Fusion sets it to pow(2, led)
uint32_t zone1 = 0;
uint8_t reserved0 = 0;
uint8_t effect_type = EFFECT_STATIC;
uint8_t max_brightness = 255;
uint8_t min_brightness = 0;
uint32_t color0 = 0;
uint32_t color1 = 0;
uint16_t period0 = 0; // Fade in - Rising Timer - Needs to be 0 for "Direct"
uint16_t period1 = 0; // Fade out
uint16_t period2 = 0; // Hold
uint16_t period3 = 0;
uint8_t effect_param0 = 0; // ex color count to cycle through (max seems to be 7)
uint8_t effect_param1 = 0;
uint8_t effect_param2 = 0; // ex flash repeat count
uint8_t effect_param3 = 0;
uint8_t padding0[30];
} e;
PktEffect() : e {}
{
}
void Init(int led, uint8_t report_id, uint16_t pid)
{
memset(buffer, 0, sizeof(buffer));
e.report_id = report_id;
if(led == -1)
{
e.zone0 = (pid == 0x5711) ? 0x07FF : 0xFF;
e.header = 0x20;
}
else if(led < 8)
{
e.zone0 = 1U << led;
e.header = 0x20 + led;
}
else if(led < 11)
{
e.zone0 = 1U << led;
e.header = 0x90 + (led - 8);
}
else
{
e.zone0 = 0;
e.header = 0;
}
}
};
/*---------------------------------------------------------*\
| Basic Controller Init Struct |
\*---------------------------------------------------------*/
struct IT8297Report
{
uint8_t report_id;
uint8_t product;
uint8_t device_num;
uint8_t strip_detect;
uint32_t fw_ver;
uint8_t curr_led_count_high;
uint8_t curr_led_count_low;
uint8_t strip_ctrl_length1;
uint8_t support_cmd_flag;
char str_product[28];
uint32_t cal_spare0;
uint32_t cal_strip0;
uint32_t cal_strip1;
uint32_t rgb_cali;
uint32_t chip_id;
uint32_t cal_spare1;
};
/*---------------------------------------------------------*\
| CC61 Calibration Struct (For IT5711) |
\*---------------------------------------------------------*/
struct IT5711Calibration
{
uint8_t report_id;
uint8_t reserved[3];
uint32_t cal_strip2;
uint32_t cal_strip3;
uint32_t cal_spare2;
uint32_t cal_spare3;
uint8_t padding[44];
};
/*---------------------------------------------------------*\
| CC33 Set Calibration Struct |
\*---------------------------------------------------------*/
union CMD_0x33
{
unsigned char buffer[FUSION2_USB_BUFFER_SIZE];
struct Calibration
{
uint8_t report_id = 0xCC;
uint8_t command_id = 0x33;
uint32_t d_strip_c0 = 0;
uint32_t d_strip_c1 = 0;
uint32_t rgb_cali = 0;
uint32_t c_spare0 = 0;
uint32_t c_spare1 = 0;
uint32_t d_strip_c2 = 0;
uint32_t d_strip_c3 = 0;
uint32_t c_spare2 = 0;
uint32_t c_spare3 = 0;
uint8_t reserved[25];
} c;
CMD_0x33() : c{}
{
memset(c.reserved, 0, sizeof(c.reserved));
}
};
#pragma pack(pop)
class RGBFusion2USBController
{
public:
RGBFusion2USBController(hid_device* handle, const char *path, std::string mb_name, uint16_t pid);
~RGBFusion2USBController();
bool ApplyEffect(bool batch_commit = false);
bool SetCalibration(const EncodedCalibration& cal, bool refresh_from_hw);
void SetLedCount(unsigned int c0, unsigned int c1, unsigned int c2, unsigned int c3);
void SetLEDEffect(int led, int mode, unsigned int speed, unsigned char brightness, bool random, uint32_t* color);
bool SetStripBuiltinEffectState(int hdr, bool enable);
void SetStripColors(unsigned int hdr, RGBColor * colors, unsigned int num_colors, int single_led = -1);
bool SupportsGen2() const;
bool ScanGen2Strips();
EncodedCalibration GetCalibration(bool refresh_from_hw = false);
std::string GetDeviceName();
uint8_t GetDeviceNum();
std::string GetDeviceDescription();
std::string GetDeviceLocation();
std::string GetFWVersion();
uint16_t GetProductID();
std::string GetSerial();
std::vector<Gen2StripInfo> ExportGen2Strips() const;
Gen2StripInfo g2_strip_info[4];
private:
std::string DecodeCalibrationBuffer(uint32_t value) const;
bool EnableLampArray(bool enable);
bool EnableBeat(bool enable);
uint32_t EncodeCalibrationBuffer(const std::string& rgb_order);
bool RefreshHardwareInfo();
void ResetController();
bool SaveLEDState(bool enable);
bool SaveCalState();
bool SendCCReport(uint8_t a, uint8_t b, uint8_t c = 0);
bool SendReport(uint8_t id, uint8_t a, uint8_t b, uint8_t c = 0);
int SendPacket(unsigned char* packet);
hid_device* dev;
uint8_t device_num;
uint16_t product_id;
uint32_t effect_zone_mask = 0;
int mode;
IT8297Report report;
CalibrationData cal_data;
std::string name;
std::string description;
std::string location;
std::string version;
std::string chip_id;
int effect_disabled = -1;
int report_id = 0xCC;
bool report_loaded = false;
bool cali_loaded = false;
LEDCount D_LED1_count;
LEDCount D_LED2_count;
LEDCount D_LED3_count;
LEDCount D_LED4_count;
};
@@ -0,0 +1,54 @@
/*---------------------------------------------------------*\
| GigabyteRGBFusion2USBControllerDetect.cpp |
| |
| Detector for Gigabyte Aorus RGB Fusion 2 USB |
| motherboard |
| |
| jackun 08 Jan 2020 |
| megadjc 31 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "Detector.h"
#include "GigabyteRGBFusion2USBController.h"
#include "RGBController_GigabyteRGBFusion2USB.h"
#include "dmiinfo.h"
#define DETECTOR_NAME "Gigabyte RGB Fusion 2 USB"
#define IT8297_VID 0x048D
#define IT8297_IFC 0
#define IT8297_U 0xCC
#define IT8297_UPG 0xFF89
/*---------------------------------------------------------*\
| Detector for Gigabyte RGB Fusion USB controllers |
\*---------------------------------------------------------*/
void DetectGigabyteRGBFusion2USBControllers(hid_device_info* info, const std::string&)
{
DMIInfo MB_info;
hid_device* dev = hid_open_path(info->path);
if(dev)
{
RGBFusion2USBController* controller = new RGBFusion2USBController(dev, info->path, MB_info.getMainboard(), info->product_id);
RGBController_RGBFusion2USB* rgb_controller = new RGBController_RGBFusion2USB(controller, DETECTOR_NAME);
// Constructor sets the name
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
}
#ifdef USE_HID_USAGE
REGISTER_HID_DETECTOR_PU(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8297, IT8297_UPG, IT8297_U);
REGISTER_HID_DETECTOR_PU(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8950, IT8297_UPG, IT8297_U);
REGISTER_HID_DETECTOR_PU(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5702, IT8297_UPG, IT8297_U);
REGISTER_HID_DETECTOR_PU(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5711, IT8297_UPG, IT8297_U);
#else
REGISTER_HID_DETECTOR_I(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8297, IT8297_IFC);
REGISTER_HID_DETECTOR_I(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8950, IT8297_IFC);
REGISTER_HID_DETECTOR_I(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5702, IT8297_IFC);
REGISTER_HID_DETECTOR_I(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5711, IT8297_IFC);
#endif
@@ -0,0 +1,980 @@
/*---------------------------------------------------------*\
| RGBController_GigabyteRGBFusion2USB.cpp |
| |
| RGBController for Gigabyte Aorus RGB Fusion 2 USB |
| motherboard |
| |
| jackun 08 Jan 2020 |
| megadjc 31 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#include "GigabyteFusion2USB_Devices.h"
#include "LogManager.h"
#include "RGBController_GigabyteRGBFusion2USB.h"
#include "ResourceManager.h"
/**------------------------------------------------------------------*\
@name Gigabyte RGB Fusion 2 USB
@category Motherboard
@type USB
@save :x:
@direct :white_check_mark:
@effects :white_check_mark:
@detectors DetectGigabyteRGBFusion2USBControllers
@comment The Fusion 2 USB controller applies to most AMD and
Intel mainboards from the X570 and z390 chipsets onwards.
\*-------------------------------------------------------------------*/
RGBController_RGBFusion2USB::RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr, std::string detector)
{
controller = controller_ptr;
name = controller->GetDeviceName();
detector_name = detector;
vendor = "Gigabyte";
type = DEVICE_TYPE_MOTHERBOARD;
description = controller->GetDeviceDescription();
version = controller->GetFWVersion();
location = controller->GetDeviceLocation();
serial = controller->GetSerial();
product_id = controller->GetProductID();
device_num = controller->GetDeviceNum();
mode Direct;
Direct.name = "Direct";
Direct.value = 0xFFFF;
Direct.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_PER_LED_COLOR;
Direct.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Direct.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Direct.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Direct.color_mode = MODE_COLORS_PER_LED;
modes.push_back(Direct);
mode Static;
Static.name = "Static";
Static.value = EFFECT_STATIC;
Static.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR;
Static.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Static.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Static.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Static.colors_min = 1;
Static.colors_max = 1;
Static.color_mode = MODE_COLORS_MODE_SPECIFIC;
Static.colors.resize(1);
modes.push_back(Static);
mode Breathing;
Breathing.name = "Breathing";
Breathing.value = EFFECT_PULSE;
Breathing.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
Breathing.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Breathing.brightness_max = 100; // Set 100 max due to controller quirks
Breathing.brightness = Breathing.brightness_max;
Breathing.speed_min = RGBFUSION2_SPEED_MIN;
Breathing.speed_max = RGBFUSION2_SPEED_MAX;
Breathing.speed = RGBFUSION2_SPEED_MID;
Breathing.colors_min = 1;
Breathing.colors_max = 1;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors.resize(1);
modes.push_back(Breathing);
mode Blinking;
Blinking.name = "Flashing";
Blinking.value = EFFECT_BLINKING;
Blinking.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
Blinking.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Blinking.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Blinking.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Blinking.speed_min = RGBFUSION2_SPEED_MIN;
Blinking.speed_max = RGBFUSION2_SPEED_MAX;
Blinking.speed = RGBFUSION2_SPEED_MID;
Blinking.colors_min = 1;
Blinking.colors_max = 1;
Blinking.color_mode = MODE_COLORS_MODE_SPECIFIC;
Blinking.colors.resize(1);
modes.push_back(Blinking);
mode ColorCycle;
ColorCycle.name = "Color Cycle";
ColorCycle.value = EFFECT_COLORCYCLE;
ColorCycle.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED;
ColorCycle.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
ColorCycle.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
ColorCycle.brightness = RGBFUSION2_BRIGHTNESS_MAX;
ColorCycle.speed_min = RGBFUSION2_SPEED_MIN;
ColorCycle.speed_max = RGBFUSION2_SPEED_MAX;
ColorCycle.speed = RGBFUSION2_SPEED_MID;
ColorCycle.color_mode = MODE_COLORS_NONE;
modes.push_back(ColorCycle);
mode Flashing;
Flashing.name = "Double Flash";
Flashing.value = EFFECT_DFLASH;
Flashing.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
Flashing.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Flashing.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Flashing.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Flashing.speed_min = RGBFUSION2_SPEED_MIN;
Flashing.speed_max = RGBFUSION2_SPEED_MAX;
Flashing.speed = RGBFUSION2_SPEED_MID;
Flashing.colors_min = 1;
Flashing.colors_max = 1;
Flashing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Flashing.colors.resize(1);
modes.push_back(Flashing);
mode Wave;
Wave.name = "Wave";
Wave.value = EFFECT_WAVE;
Wave.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED;
Wave.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Wave.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Wave.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Wave.speed_min = RGBFUSION2_SPEED_MIN;
Wave.speed_max = RGBFUSION2_SPEED_MAX;
Wave.speed = RGBFUSION2_SPEED_MID;
Wave.colors_min = 0;
Wave.colors_max = 0;
Wave.color_mode = MODE_COLORS_NONE;
modes.push_back(Wave);
mode Random;
Random.name = "Random";
Random.value = EFFECT_RANDOM;
Random.flags = MODE_FLAG_HAS_BRIGHTNESS;
Random.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Random.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Random.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Random.colors_min = 0;
Random.colors_max = 0;
Random.color_mode = MODE_COLORS_NONE;
modes.push_back(Random);
mode Wave1;
Wave1.name = "Wave 1";
Wave1.value = EFFECT_WAVE1;
Wave1.flags = MODE_FLAG_HAS_BRIGHTNESS;
Wave1.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Wave1.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Wave1.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Wave1.colors_min = 0;
Wave1.colors_max = 0;
Wave1.color_mode = MODE_COLORS_NONE;
modes.push_back(Wave1);
mode Wave2;
Wave2.name = "Wave 2";
Wave2.value = EFFECT_WAVE2;
Wave2.flags = MODE_FLAG_HAS_BRIGHTNESS;
Wave2.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Wave2.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Wave2.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Wave2.colors_min = 0;
Wave2.colors_max = 0;
Wave2.color_mode = MODE_COLORS_NONE;
modes.push_back(Wave2);
mode Wave3;
Wave3.name = "Wave 3";
Wave3.value = EFFECT_WAVE3;
Wave3.flags = MODE_FLAG_HAS_BRIGHTNESS;
Wave3.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Wave3.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Wave3.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Wave3.colors_min = 0;
Wave3.colors_max = 0;
Wave3.color_mode = MODE_COLORS_NONE;
modes.push_back(Wave3);
mode Wave4;
Wave4.name = "Wave 4";
Wave4.value = EFFECT_WAVE4;
Wave4.flags = MODE_FLAG_HAS_BRIGHTNESS;
Wave4.brightness_min = RGBFUSION2_BRIGHTNESS_MIN;
Wave4.brightness_max = RGBFUSION2_BRIGHTNESS_MAX;
Wave4.brightness = RGBFUSION2_BRIGHTNESS_MAX;
Wave4.colors_min = 0;
Wave4.colors_max = 0;
Wave4.color_mode = MODE_COLORS_NONE;
modes.push_back(Wave4);
Init_Controller();
SetupZones();
}
RGBController_RGBFusion2USB::~RGBController_RGBFusion2USB()
{
// Free any zones we allocated for the per-instance layout
for(gb_fusion2_zone* z : allocated_zones)
{
delete z;
}
allocated_zones.clear();
delete controller;
}
/*---------------------------------------------------------*\
| Loads JSON config data |
\*---------------------------------------------------------*/
void RGBController_RGBFusion2USB::Init_Controller()
{
const gb_fusion2_device* src_layout = gb_fusion2_device_list[device_index];
const std::string SectionGen2 = "Gigabyte-Gen2-ARGB";
const std::string SectionCustomBase = "CustomLayout";
const std::string SectionCustom = SectionCustomBase + std::to_string(device_num);
const std::string SectionCalibration = "Calibration";
RvrseLedHeaders ReverseLedLookup = reverse_map(LedLookup);
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
nlohmann::json device_settings = settings_manager->GetSettings(detector_name);
/*---------------------------------------------------------*\
| Checks for Gen2 support and adds flag to json. |
\*---------------------------------------------------------*/
if(controller->SupportsGen2())
{
if(!device_settings.contains(SectionGen2))
{
device_settings[SectionGen2]["Enabled"] = false;
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
supports_gen2 = device_settings[SectionGen2]["Enabled"];
if(supports_gen2)
{
controller->ScanGen2Strips();
}
}
/*---------------------------------------------------------*\
| Create the custom layout from the generic layout |
\*---------------------------------------------------------*/
switch(product_id)
{
case 0x8950:
src_layout = gb_fusion2_device_list[device_index + 1];
break;
case 0x5711:
src_layout = gb_fusion2_device_list[device_index + 2];
break;
default:
break;
}
if(!device_settings.contains(SectionCustom))
{
device_settings[SectionCustom]["Enabled"] = false;
device_settings[SectionCustom]["Data"] = BuildCustomLayoutJson(src_layout, ReverseLedLookup);
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
bool custom_layout = device_settings[SectionCustom]["Enabled"];
EncodedCalibration hw_cal = controller->GetCalibration(false);
if(device_num == 0)
{
if(!device_settings.contains(SectionCalibration))
{
device_settings[SectionCalibration]["Enabled"] = false;
device_settings[SectionCalibration]["Data"] = WriteCalJsonFrom(hw_cal);
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
else
{
nlohmann::json& cal_sec = device_settings[SectionCalibration];
bool cal_enable = cal_sec.value("Enabled", false);
if(!cal_sec.contains("Data") || !cal_sec["Data"].is_object())
{
cal_sec["Data"] = WriteCalJsonFrom(hw_cal);
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
else
{
nlohmann::json& cdata = cal_sec["Data"];
FillMissingWith(cdata, hw_cal);
if(!cal_enable)
{
cal_sec["Data"] = WriteCalJsonFrom(hw_cal);
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
}
if(cal_enable)
{
const nlohmann::json& cdata = cal_sec["Data"];
EncodedCalibration desired;
desired.dled[0] = GET_JSON_VAL_ELSE_OFF(cdata, "HDR_D_LED1");
desired.dled[1] = GET_JSON_VAL_ELSE_OFF(cdata, "HDR_D_LED2");
desired.mainboard = GET_JSON_VAL_ELSE_OFF(cdata, "Mainboard");
desired.spare[0] = GET_JSON_VAL_ELSE_OFF(cdata, "Spare0");
desired.spare[1] = GET_JSON_VAL_ELSE_OFF(cdata, "Spare1");
if(controller->GetProductID() == 0x5711)
{
desired.dled[2] = GET_JSON_VAL_ELSE_OFF(cdata, "HDR_D_LED3");
desired.dled[3] = GET_JSON_VAL_ELSE_OFF(cdata, "HDR_D_LED4");
desired.spare[2] = GET_JSON_VAL_ELSE_OFF(cdata, "Spare2");
desired.spare[3] = GET_JSON_VAL_ELSE_OFF(cdata, "Spare3");
}
else
{
desired.dled[2] = "OFF";
desired.dled[3] = "OFF";
desired.spare[2] = "OFF";
desired.spare[3] = "OFF";
}
controller->SetCalibration(desired, false);
}
}
}
/*---------------------------------------------------------------------*\
| When no match found the first entry (generic_device) will be used |
| otherwise look up channel map based on device name |
\*---------------------------------------------------------------------*/
if(!custom_layout)
{
/*-----------------------------------------------------------------*\
| Loop through all known devices to look for a name match |
| NB: Can be switched to device IDs lookup when acpi table |
| is able to be probed accurately |
\*-----------------------------------------------------------------*/
for(unsigned int i = 0; i < GB_FUSION2_DEVICE_COUNT; i++)
{
if(gb_fusion2_device_list[i]->name == name &&
gb_fusion2_device_list[i]->device_num == device_num)
{
/*---------------------------------------------------------*\
| Set device ID |
\*---------------------------------------------------------*/
device_index = i;
src_layout = gb_fusion2_device_list[i];
break;
}
}
}
/*---------------------------------------------------------------------*\
| Creates per instance copy of layouts. |
\*---------------------------------------------------------------------*/
instance_layout.zones = &instance_zones;
instance_layout.layout_id = src_layout->layout_id;
instance_layout.device_num = src_layout->device_num;
instance_layout.name = src_layout->name;
for(uint8_t zi = 0; zi < GB_FUSION2_ZONES_MAX; ++zi)
{
(*instance_layout.zones)[zi] = (*src_layout->zones)[zi];
}
if(custom_layout)
{
LoadCustomLayoutFromJson(device_settings[SectionCustom]["Data"], LedLookup, &instance_layout);
}
/*---------------------------------------------------------------------*\
| Culls the mode support based on layout_id. |
\*---------------------------------------------------------------------*/
const uint32_t effect_mask = instance_layout.layout_id & GB_EFF_CORE_MASK;
modes.erase(std::remove_if(modes.begin(), modes.end(),
[effect_mask](const mode& m)
{
if(m.value == 0xFFFF /* Direct */) { return false; }
if(m.value == EFFECT_STATIC) { return false; }
uint32_t bit = 0u;
switch(m.value)
{
case EFFECT_PULSE: bit = GB_EFF_BREATH; break;
case EFFECT_COLORCYCLE: bit = GB_EFF_CYCLE; break;
case EFFECT_BLINKING: bit = GB_EFF_FLASH; break;
case EFFECT_RANDOM: bit = GB_EFF_RANDOM; break;
case EFFECT_WAVE: bit = GB_EFF_WAVE; break;
case EFFECT_DFLASH: bit = GB_EFF_DFLASH; break;
case EFFECT_WAVE1: bit = GB_EFF_WAVE1; break;
case EFFECT_WAVE2: bit = GB_EFF_WAVE2; break;
case EFFECT_WAVE3: bit = GB_EFF_WAVE1; break;
case EFFECT_WAVE4: bit = GB_EFF_WAVE2; break;
default: bit = 0u; break;
}
return (bit == 0u) || ((effect_mask & bit) == 0u);
}),
modes.end());
/*---------------------------------------------------------*\
| Iterate through layout and process each zone |
\*---------------------------------------------------------*/
for(uint8_t zone_idx = 0; zone_idx < GB_FUSION2_ZONES_MAX; zone_idx++)
{
if(!(*instance_layout.zones)[zone_idx])
{
continue;
}
const gb_fusion2_zone* zone_at_idx = (*instance_layout.zones)[zone_idx];
zone new_zone;
new_zone.name = zone_at_idx->name;
new_zone.leds_min = zone_at_idx->leds_min;
new_zone.leds_max = zone_at_idx->leds_max;
new_zone.leds_count = new_zone.leds_min;
new_zone.type = ((new_zone.leds_min == 1) && (new_zone.leds_max == 1)) ? ZONE_TYPE_SINGLE : ZONE_TYPE_LINEAR;
new_zone.matrix_map = NULL;
zones.emplace_back(new_zone);
}
}
void RGBController_RGBFusion2USB::SetupZones()
{
/*---------------------------------------------------------*\
| Clear any existing color/LED configuration |
\*---------------------------------------------------------*/
leds.clear();
colors.clear();
unsigned int d1 = 0, d2 = 0, d3 = 0, d4 = 0;
/*---------------------------------------------------------*\
| Set up zones (Fixed so as to not spam the controller) |
\*---------------------------------------------------------*/
std::vector<Gen2StripInfo> strips = controller->ExportGen2Strips();
for(uint8_t zone_idx = 0; zone_idx < GB_FUSION2_ZONES_MAX; zone_idx++)
{
const gb_fusion2_zone* zone_at_idx = (*instance_layout.zones)[zone_idx];
if(!zone_at_idx)
{
continue;
}
bool single_zone = ((zone_at_idx->leds_min == 1) && (zone_at_idx->leds_max == 1));
if(!single_zone)
{
if(supports_gen2)
{
int slot = 0;
switch(zone_at_idx->idx)
{
case LED4:
case HDR_D_LED2:
slot = 1;
break;
case HDR_D_LED3:
slot = 2;
break;
case HDR_D_LED4:
slot = 3;
break;
default:
break;
}
if(slot >= 0 && static_cast<size_t>(slot) < strips.size())
{
const Gen2StripInfo& info = strips[static_cast<size_t>(slot)];
if(info.totalLeds > 0u)
{
zones[zone_idx].leds_count = static_cast<unsigned int>(info.totalLeds);
zones[zone_idx].leds_min = static_cast<unsigned int>(info.totalLeds);
zones[zone_idx].leds_max = static_cast<unsigned int>(info.totalLeds);
zones[zone_idx].segments.clear();
zones[zone_idx].segments.reserve(info.LedsOfStrip.size());
unsigned int offset = 0;
for(size_t si = 0; si < info.LedsOfStrip.size(); ++si)
{
const uint16_t cnt = info.LedsOfStrip[si];
if(cnt == 0) continue;
segment seg;
seg.name = std::string("Segment ") + std::to_string(si);
seg.type = ZONE_TYPE_LINEAR;
seg.start_idx = offset;
seg.leds_count = static_cast<unsigned int>(cnt);
zones[zone_idx].segments.push_back(seg);
offset += static_cast<unsigned int>(cnt);
}
}
}
}
switch(zone_at_idx->idx)
{
case LED4:
case HDR_D_LED2:
d2 = zones[zone_idx].leds_count;
break;
case HDR_D_LED3:
d3 = zones[zone_idx].leds_count;
break;
case HDR_D_LED4:
d4 = zones[zone_idx].leds_count;
break;
default:
d1 = zones[zone_idx].leds_count;
break;
}
}
for(unsigned int led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
{
led new_led;
new_led.name = zone_at_idx->name;
new_led.value = zone_at_idx->idx;
if(!single_zone)
{
new_led.name.append(" LED " + std::to_string(led_idx));
}
leds.push_back(new_led);
}
}
controller->SetLedCount(d1, d2, d3, d4);
controller->SetStripBuiltinEffectState(-1, false);
SetupColors();
}
void RGBController_RGBFusion2USB::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_RGBFusion2USB::DeviceUpdateLEDs()
{
int mode_value = (modes[active_mode].value);
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
uint32_t* color = &null_color;
/*---------------------------------------------------------*\
| If Wave 1-4 then use special sequence. |
\*---------------------------------------------------------*/
if(mode_value == 6 || (mode_value >= 9 && mode_value <= 12))
{
controller->SetStripBuiltinEffectState(-1, true);
controller->SetLEDEffect(-1, 1, 0, 0xFF, 0, color);
controller->ApplyEffect();
controller->SetLEDEffect( 2, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
controller->ApplyEffect();
return;
}
for(int zone_idx = 0; zone_idx < (int)zones.size(); zone_idx++)
{
if(zones[zone_idx].type == ZONE_TYPE_SINGLE)
{
for(std::size_t led_idx = 0; led_idx < zones[zone_idx].leds_count; led_idx++)
{
/*---------------------------------------------------------*\
| Motherboard LEDs always use effect mode, so use static for|
| direct mode but get colors from zone |
\*---------------------------------------------------------*/
if(modes[active_mode].value == 0xFFFF)
{
color = &zones[zone_idx].colors[led_idx];
mode_value = EFFECT_STATIC;
}
/*---------------------------------------------------------*\
| If the mode uses mode-specific color, get color from mode |
\*---------------------------------------------------------*/
else if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
color = &modes[active_mode].colors[0];
}
/*---------------------------------------------------------*\
| Apply the mode and color to the zone |
\*---------------------------------------------------------*/
controller->SetLEDEffect(zones[zone_idx].leds[led_idx].value, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
}
}
/*---------------------------------------------------------*\
| Set strip LEDs |
\*---------------------------------------------------------*/
else
{
if(zones[zone_idx].leds && zones[zone_idx].leds_count)
{
unsigned char hdr = zones[zone_idx].leds->value;
/*---------------------------------------------------------*\
| Direct mode addresses a different register |
\*---------------------------------------------------------*/
if(modes[active_mode].value == 0xFFFF)
{
controller->SetStripBuiltinEffectState(hdr, false);
controller->SetStripColors(hdr, zones[zone_idx].colors, zones[zone_idx].leds_count);
}
/*---------------------------------------------------------*\
| Effect mode |
\*---------------------------------------------------------*/
else
{
/*---------------------------------------------------------*\
| If mode has mode specific color, load color from mode |
\*---------------------------------------------------------*/
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
color = &modes[active_mode].colors[0];
}
/*---------------------------------------------------------*\
| Apply hardware effects to LED strips |
\*---------------------------------------------------------*/
controller->SetStripBuiltinEffectState(hdr, true);
controller->SetLEDEffect(hdr, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
}
}
}
}
controller->ApplyEffect();
}
void RGBController_RGBFusion2USB::UpdateZoneLEDs(int zone)
{
/*---------------------------------------------------------*\
| Get mode parameters |
\*---------------------------------------------------------*/
int mode_value = (modes[active_mode].value);
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
uint32_t* color = &null_color;
/*---------------------------------------------------------*\
| If Wave 1-4 then use special sequence. |
\*---------------------------------------------------------*/
if(mode_value == 6 || (mode_value >= 9 && mode_value <= 12))
{
controller->SetStripBuiltinEffectState(-1, true);
controller->SetLEDEffect(-1, 1, 0, 0xFF, 0, color);
controller->ApplyEffect();
controller->SetLEDEffect( 2, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
controller->ApplyEffect();
return;
}
/*---------------------------------------------------------*\
| Set motherboard LEDs |
\*---------------------------------------------------------*/
if(zones[zone].type == ZONE_TYPE_SINGLE)
{
for(std::size_t led_idx = 0; led_idx < zones[zone].leds_count; led_idx++)
{
/*------------------------------------------------------------*\
| Motherboard LEDs always use effect mode, so use static for |
| direct mode but get colors from zone |
\*------------------------------------------------------------*/
if(mode_value == 0xFFFF)
{
color = &zones[zone].colors[led_idx];
mode_value = EFFECT_STATIC;
}
/*---------------------------------------------------------*\
| If the mode uses mode-specific color, get color from mode |
\*---------------------------------------------------------*/
else if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
color = &modes[active_mode].colors[0];
}
/*---------------------------------------------------------*\
| Apply the mode and color to the zone |
\*---------------------------------------------------------*/
controller->SetLEDEffect(zones[zone].leds[led_idx].value, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
controller->ApplyEffect();
}
}
/*---------------------------------------------------------*\
| Set strip LEDs |
\*---------------------------------------------------------*/
else
{
if(zones[zone].leds && zones[zone].leds_count)
{
unsigned char hdr = zones[zone].leds->value;
/*---------------------------------------------------------*\
| Direct mode addresses a different register |
\*---------------------------------------------------------*/
if(mode_value == 0xFFFF)
{
controller->SetStripBuiltinEffectState(hdr, false);
controller->SetStripColors(hdr, zones[zone].colors, zones[zone].leds_count);
}
/*---------------------------------------------------------*\
| Effect mode |
\*---------------------------------------------------------*/
else
{
/*---------------------------------------------------------*\
| If mode has mode specific color, load color from mode |
\*---------------------------------------------------------*/
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
color = &modes[active_mode].colors[0];
}
/*---------------------------------------------------------*\
| Apply built-in effects to LED strips |
\*---------------------------------------------------------*/
controller->SetStripBuiltinEffectState(hdr, true);
controller->SetLEDEffect(hdr, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
controller->ApplyEffect();
}
}
}
}
void RGBController_RGBFusion2USB::UpdateSingleLED(int led)
{
/*---------------------------------------------------------*\
| Get mode parameters |
\*---------------------------------------------------------*/
int mode_value = (modes[active_mode].value);
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
uint32_t* color = &null_color;
/*---------------------------------------------------------*\
| If Wave 1-4 then use special sequence. |
\*---------------------------------------------------------*/
if(mode_value == 6 || (mode_value >= 9 && mode_value <= 12))
{
controller->SetStripBuiltinEffectState(-1, true);
controller->SetLEDEffect(-1, 1, 0, 0xFF, 0, color);
controller->ApplyEffect();
controller->SetLEDEffect( 2, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
controller->ApplyEffect();
return;
}
unsigned int zone_idx = GetLED_Zone(led);
/*---------------------------------------------------------*\
| Set motherboard LEDs |
\*---------------------------------------------------------*/
if(zones[zone_idx].type == ZONE_TYPE_SINGLE)
{
/*---------------------------------------------------------*\
| Motherboard LEDs always use effect mode, so use static for|
| direct mode but get colors from zone |
\*---------------------------------------------------------*/
if(mode_value == 0xFFFF)
{
color = &colors[led];
mode_value = EFFECT_STATIC;
}
/*---------------------------------------------------------*\
| If the mode uses mode-specific color, get color from mode |
\*---------------------------------------------------------*/
else if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
color = &modes[active_mode].colors[0];
}
controller->SetLEDEffect(leds[led].value, mode_value, modes[active_mode].speed, modes[active_mode].brightness, random, color);
controller->ApplyEffect();
}
/*---------------------------------------------------------*\
| Set strip LEDs |
\*---------------------------------------------------------*/
else
{
UpdateZoneLEDs(zone_idx);
}
}
void RGBController_RGBFusion2USB::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}
int RGBController_RGBFusion2USB::GetLED_Zone(int led_idx)
{
for(int zone_idx = 0; zone_idx < (int)zones.size(); zone_idx++)
{
int zone_start = zones[zone_idx].start_idx;
int zone_end = zone_start + zones[zone_idx].leds_count - 1;
if((zone_start <= led_idx) && (zone_end >= led_idx))
{
return(zone_idx);
}
}
/*---------------------------------------------------------*\
| If zone is not found, return -1 |
\*---------------------------------------------------------*/
return(-1);
}
/*---------------------------------------------------------*\
| Convert calibration data to JSON |
\*---------------------------------------------------------*/
nlohmann::json RGBController_RGBFusion2USB::WriteCalJsonFrom(const EncodedCalibration& src)
{
nlohmann::json calib_json;
calib_json["HDR_D_LED1"] = src.dled[0];
calib_json["HDR_D_LED2"] = src.dled[1];
calib_json["HDR_D_LED3"] = src.dled[2];
calib_json["HDR_D_LED4"] = src.dled[3];
calib_json["Mainboard"] = src.mainboard;
calib_json["Spare0"] = src.spare[0];
calib_json["Spare1"] = src.spare[1];
calib_json["Spare2"] = src.spare[2];
calib_json["Spare3"] = src.spare[3];
return calib_json;
}
/*---------------------------------------------------------*\
| Fill missing JSON calibration keys |
\*---------------------------------------------------------*/
void RGBController_RGBFusion2USB::FillMissingWith(nlohmann::json& dst, const EncodedCalibration& fb)
{
struct SetIfMissing
{
nlohmann::json& dst;
void operator()(const char* key, const std::string& val) const
{
if(!dst.contains(key))
{
dst[key] = val;
}
}
};
SetIfMissing set_if_missing{dst};
set_if_missing("HDR_D_LED1", fb.dled[0]);
set_if_missing("HDR_D_LED2", fb.dled[1]);
set_if_missing("Mainboard", fb.mainboard);
set_if_missing("Spare0", fb.spare[0]);
set_if_missing("Spare1", fb.spare[1]);
if(controller->GetProductID() == 0x5711)
{
set_if_missing("HDR_D_LED3", fb.dled[2]);
set_if_missing("HDR_D_LED4", fb.dled[3]);
set_if_missing("Spare2", fb.spare[2]);
set_if_missing("Spare3", fb.spare[3]);
}
}
/*---------------------------------------------------------*\
| Build custom layout in JSON |
\*---------------------------------------------------------*/
nlohmann::json RGBController_RGBFusion2USB::BuildCustomLayoutJson(
const gb_fusion2_device* layout,
const RvrseLedHeaders& reverseLookup)
{
nlohmann::json json_custom;
for(uint8_t zone_idx = 0; zone_idx < GB_FUSION2_ZONES_MAX; zone_idx++)
{
if(!layout->zones[0][zone_idx])
{
continue;
}
nlohmann::json json_zone;
json_zone["name"] = layout->zones[0][zone_idx]->name;
json_zone["header"] = reverseLookup.at(layout->zones[0][zone_idx]->idx);
json_zone["leds_min"] = layout->zones[0][zone_idx]->leds_min;
json_zone["leds_max"] = layout->zones[0][zone_idx]->leds_max;
json_custom[layout->name].push_back(json_zone);
}
return json_custom;
}
/*---------------------------------------------------------*\
| Build custom layout from JSON |
\*---------------------------------------------------------*/
void RGBController_RGBFusion2USB::LoadCustomLayoutFromJson(
const nlohmann::json& json_custom,
const FwdLedHeaders& forwardLookup,
gb_fusion2_device* layout)
{
for(uint8_t zone_idx = 0; zone_idx < GB_FUSION2_ZONES_MAX; zone_idx++)
{
/*---------------------------------------------------------*\
| Check if there are more JSON objects to parse |
\*---------------------------------------------------------*/
if(json_custom[layout->name].size() <= zone_idx)
{
layout->zones[0][zone_idx] = nullptr;
continue;
}
nlohmann::json json_zone = json_custom[layout->name].at(zone_idx);
gb_fusion2_zone* new_zone = new gb_fusion2_zone();
new_zone->name = json_zone["name"].get<std::string>();
std::string header = json_zone["header"].get<std::string>();
new_zone->idx = forwardLookup.at(header);
if( header == "HDR_D_LED1"
|| header == "HDR_D_LED2"
|| header == "HDR_D_LED3"
|| header == "HDR_D_LED4")
{
new_zone->leds_min = std::max(json_zone["leds_min"].get<int>(), 1);
new_zone->leds_max = std::min(json_zone["leds_max"].get<int>(), 1024);
}
else
{
new_zone->leds_min = 1;
new_zone->leds_max = 1;
}
/*---------------------------------------------------------*\
| Check for valid values from JSON |
\*---------------------------------------------------------*/
if(new_zone->name != ""
&& new_zone->leds_min <= new_zone->leds_max
&& new_zone->idx >= GB_FUSION2_LED_IDX::LED1
&& new_zone->idx <= GB_FUSION2_LED_IDX::LED11)
{
layout->zones[0][zone_idx] = new_zone;
allocated_zones.push_back(new_zone);
}
else
{
LOG_ERROR("[%s] Error creating zone %d: Validation failed for %s @ index %d (LEDs min %d to %d max)",
controller->GetDeviceName().c_str(),
zone_idx,
new_zone->name.c_str(),
new_zone->idx,
new_zone->leds_min,
new_zone->leds_max);
}
}
}
@@ -0,0 +1,97 @@
/*---------------------------------------------------------*\
| RGBController_GigabyteRGBFusion2USB.h |
| |
| RGBController for Gigabyte Aorus RGB Fusion 2 USB |
| motherboard |
| |
| jackun 08 Jan 2020 |
| megadjc 31 Jul 2025 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <map>
#include "RGBController.h"
#include "GigabyteFusion2USB_Devices.h"
#include "GigabyteRGBFusion2USBController.h"
#include "SettingsManager.h"
#define RGBFUSION2_DIGITAL_LEDS_MIN 0
#define RGBFUSION2_DIGITAL_LEDS_MAX 1024
#define RGBFUSION2_BRIGHTNESS_MIN 0
#define RGBFUSION2_BRIGHTNESS_MAX 255
#define RGBFUSION2_SPEED_MIN 9
#define RGBFUSION2_SPEED_MID 4
#define RGBFUSION2_SPEED_MAX 0
#define GET_JSON_VAL_ELSE_OFF(obj, key) obj.contains(key) ? obj.at(key).get<std::string>() : std::string("OFF")
template<typename K, typename V>
static std::map<V, K> reverse_map(const std::map<K, V>& map)
{
std::map<V, K> reversed_map;
for(const std::pair<K, V> entry : map)
{
reversed_map[entry.second] = entry.first;
}
return reversed_map;
}
class RGBController_RGBFusion2USB: public RGBController
{
public:
RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr, std::string _detector_name);
~RGBController_RGBFusion2USB();
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void DeviceUpdateMode();
private:
std::string detector_name;
RGBFusion2USBController* controller;
uint8_t device_num;
RGBColor null_color = 0;
bool supports_gen2 = 0;
/*---------------------------------------------------------*\
| The intial value of device_index should point to the |
| layout for the generic_device |
\*---------------------------------------------------------*/
uint32_t device_index = 0;
uint16_t product_id = 0;
uint32_t effects_mask = 0;
void Init_Controller();
int GetLED_Zone(int led_idx);
/*---------------------------------------------------------*\
| Per instance layout lookup tables. |
\*---------------------------------------------------------*/
gb_fusion2_device instance_layout{};
gb_fusion2_layout instance_zones{};
std::vector<gb_fusion2_zone*> allocated_zones;
nlohmann::json WriteCalJsonFrom(
const EncodedCalibration& src);
void FillMissingWith(
nlohmann::json& dst,
const EncodedCalibration& fb);
nlohmann::json BuildCustomLayoutJson(
const gb_fusion2_device* layout,
const RvrseLedHeaders& reverseLookup);
void LoadCustomLayoutFromJson(
const nlohmann::json& json_custom,
const FwdLedHeaders& forwardLookup,
gb_fusion2_device* layout);
};