Name cleanup: adding brand names to all controllers

This commit is contained in:
TheRogueZeta 2020-11-15 20:25:51 +00:00 committed by Adam Honse
parent dde857dfb4
commit 8ffd302a57
74 changed files with 283 additions and 283 deletions

View file

@ -0,0 +1,305 @@
/*-----------------------------------------*\
| GigabyteRGBFusion2USBController.cpp |
| |
| Driver for Gigabyte Aorus RGB Fusion 2.0 |
| USB lighting controller |
| |
| jackun 1/8/2020 |
\*-----------------------------------------*/
#include "GigabyteRGBFusion2USBController.h"
#include <algorithm>
#include <array>
#include <thread>
#include <chrono>
static LEDCount LedCountToEnum(unsigned int c)
{
if (c <= 32)
return(LEDS_32);
if (c <= 64)
return(LEDS_64);
if (c <= 256)
return(LEDS_256);
if (c <= 512)
return(LEDS_512);
return(LEDS_1024);
}
RGBFusion2USBController::RGBFusion2USBController(hid_device* handle, const char *path, std::string mb_name) : dev(handle)
{
int res = 0;
char text[64] = { 0x00 };
unsigned char buffer[64] = { 0x00 };
if( dev )
{
SetCalibration();
name = mb_name;
// hid report read needs 0x60 packet or it gives IO error
SendPacket(0x60, 0x00);
buffer[0] = report_id;
res = hid_get_feature_report(dev, buffer, 64);
if( res > 0 )
{
report = *reinterpret_cast<IT8297Report*>(buffer);
description = std::string(report.str_product, 32);
description.erase(std::find(description.begin(), description.end(), '\0'), description.end());
snprintf(text, 11, "0x%08X", report.fw_ver);
version = text;
snprintf(text, 11, "0x%08X", report.chip_id);
chip_id = text;
D_LED1_count = LedCountToEnum(report.total_leds & 0x0F);
D_LED2_count = LedCountToEnum(report.total_leds & 0xF0);
}
loc = path;
EnableBeat(false);
}
}
RGBFusion2USBController::~RGBFusion2USBController()
{
if( dev ) {
hid_close(dev);
}
}
void RGBFusion2USBController::SetMode(int m)
{
mode = m;
}
// Sets RGB color mapping to LED pins.
// "Custom" RGB packets don't seem to get remapped so use report.byteorderN and do it manually.
// Of course it all depends how we send data to the controller, but bios/rgb fusion 2 itself
// set it up like this.
void RGBFusion2USBController::SetCalibration()
{
uint8_t buffer[64] {};
buffer[0] = report_id;
buffer[1] = 0x33;
// D_LED1 WS2812 GRB, 0x00RRGGBB to 0x00GGRRBB
buffer[2] = 0x02; // B
buffer[3] = 0x00; // G
buffer[4] = 0x01; // R
buffer[5] = 0x00;
// D_LED2 WS2812 GRB
buffer[6] = 0x02;
buffer[7] = 0x00;
buffer[8] = 0x01;
buffer[9] = 0x00;
// LED C1/C2 12vGRB, seems pins already connect to LEDs correctly
buffer[10] = 0x00;
buffer[11] = 0x01;
buffer[12] = 0x02;
buffer[13] = 0x00;
// Spare set seen in some Motherboard models
buffer[14] = 0x00;
buffer[15] = 0x01;
buffer[16] = 0x02;
buffer[17] = 0x00;
SendPacket(buffer);
}
void RGBFusion2USBController::SetLedCount(unsigned int led, unsigned int count)
{
//Check which Digital LED we're setting then send the value of both
( led == HDR_D_LED1 ) ? D_LED1_count = LedCountToEnum(count) : D_LED2_count = LedCountToEnum(count);
SendPacket(0x34, D_LED1_count | (D_LED2_count << 4));
}
bool RGBFusion2USBController::DisableBuiltinEffect(int enable_bit, int mask)
{
if(effect_disabled & enable_bit)
return(true);
effect_disabled &= ~mask;
effect_disabled |= enable_bit;
int res = SendPacket(0x32, effect_disabled);
// Sometimes effect doesn't apply at first, delay a little and let MCU to react, if this packet is the cause
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return res;
}
bool RGBFusion2USBController::EnableBeat(bool e)
{
return SendPacket(0x31, e ? 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(loc);
}
std::string RGBFusion2USBController::GetSerial()
{
return(chip_id);
}
void RGBFusion2USBController::SetStripColors
(
unsigned int hdr,
RGBColor * colors,
unsigned int num_colors,
int single_led
)
{
PktRGB pkt;
pkt.Init(hdr, report_id);
// FIXME assuming that LED strips ports are 0x58/0x59 for all boards
uint32_t byteorder = hdr == HDR_D_LED1_RGB ? report.byteorder0 : report.byteorder1;
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 */
// other leds stay at whatever the builtin effect was doing at that moment
// if breathing/pulse effect faded out then they stay dark
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];
unsigned char red = RGBGetRValue(color);
unsigned char grn = RGBGetGValue(color);
unsigned char blu = RGBGetBValue(color);
pkt.buffer[5 + i * 3 + bo_r] = red;
pkt.buffer[5 + i * 3 + bo_g] = grn;
pkt.buffer[5 + i * 3 + bo_b] = blu;
k++;
}
res = SendPacket(pkt.buffer);
if(res < 0)
return;
}
if (hdr == HDR_D_LED1_RGB)
DisableBuiltinEffect(0x01, 0x01);
else
DisableBuiltinEffect(0x02, 0x02);
}
static const std::array< std::array<int, 3>, 5> speeds = {
{
{1600, 1600, 200},
{1200, 1200, 200},
{800, 800, 200},
{400, 400, 200},
{200, 200, 200},
},
};
void RGBFusion2USBController::SetLEDEffect(unsigned int led, int mode, unsigned int speed, bool random, unsigned char r, unsigned char g, unsigned char b)
{
PktEffect pkt;
pkt.Init(led, report_id);
pkt.e.effect_type = mode;
pkt.e.color0 = r << 16 | g << 8 | b;
if (speed < speeds.size()) {
const auto& s = speeds[speed];
pkt.e.period0 = s[0];
pkt.e.period1 = s[1];
pkt.e.period2 = s[2];
}
switch(mode)
{
case 0: break;
case 1: break; // static
case 2: // breathing
case 3: // blink
if (random)
pkt.e.effect_param0 = 7; // cycle through up to 7 (max?) colors
break;
case 4: // color cycle
pkt.e.effect_param0 = 7; // cycle through up to 7 (max?) colors
break;
// "fake" effects
case 10: // flashing, flashing color cycle
pkt.e.period0 = 200;
pkt.e.period1 = 200;
pkt.e.period2 = 5000 - 1000 * speed; // time between flashing, doesn't seem to be affected by period0/period1
pkt.e.effect_type = 3;
pkt.e.effect_param2 = 2; // flash twice
if (random)
pkt.e.effect_param0 = 7;
break;
}
SendPacket(pkt.buffer);
}
bool RGBFusion2USBController::ApplyEffect()
{
return SendPacket(0x28, 0xFF);
}
bool RGBFusion2USBController::SendPacket(uint8_t a, uint8_t b, uint8_t c)
{
unsigned char buffer[64] {};
buffer[0] = report_id;
buffer[1] = a;
buffer[2] = b;
buffer[3] = c;
return (SendPacket(buffer) == 64);
}
int RGBFusion2USBController::SendPacket(unsigned char* packet)
{
return hid_send_feature_report(dev, packet, 64);
}

View file

@ -0,0 +1,200 @@
/*-----------------------------------------*\
| GigabyteRGBFusion2USBController.h |
| |
| Definitions and types for Gigabyte Aorus |
| RGB Fusion 2.0 USB lighting controller |
| |
| jackun 1/8/2020 |
\*-----------------------------------------*/
#include "RGBController.h"
#include <cstring>
#include <hidapi/hidapi.h>
#pragma once
// LED "headers" 0x20..0x27, As seen on Gigabyte X570 Elite board
const uint8_t HDR_BACK_IO = 0x20;
const uint8_t HDR_CPU = 0x21;
const uint8_t HDR_LED_2 = 0x22;
const uint8_t HDR_PCIE = 0x23;
const uint8_t HDR_LED_C1C2 = 0x24;
const uint8_t HDR_D_LED1 = 0x25;
const uint8_t HDR_D_LED2 = 0x26;
const uint8_t HDR_LED_7 = 0x27;
const uint8_t HDR_D_LED1_RGB = 0x58; // FIXME assuming that it is 0x58 for all boards
const uint8_t HDR_D_LED2_RGB = 0x59;
enum EffectType
{
EFFECT_NONE = 0,
EFFECT_STATIC = 1,
EFFECT_PULSE = 2,
EFFECT_BLINKING = 3,
EFFECT_COLORCYCLE = 4,
// to be continued...
};
enum LEDCount
{
LEDS_32 = 0,
LEDS_64,
LEDS_256,
LEDS_512,
LEDS_1024,
};
struct LEDs
{
uint8_t r;
uint8_t g;
uint8_t b;
};
#pragma pack(push, 1)
union PktRGB
{
unsigned char buffer[64];
struct RGBData
{
uint8_t report_id;
uint8_t header;
uint16_t boffset; // in bytes, absolute
uint8_t bcount;
LEDs leds[19];
uint16_t padding0;
} s;
PktRGB() : s {}
{
}
void Init(uint8_t header, uint8_t report_id)
{
s.report_id = report_id;
s.header = header;
s.boffset = 0;
s.bcount = 0;
memset(s.leds, 0, sizeof(s.leds));
}
};
union PktEffect
{
unsigned char buffer[64];
struct Effect
{
uint8_t report_id;
uint8_t header;
uint32_t zone0; // rgb fusion seems to set it to pow(2, header - 0x20)
uint32_t zone1;
uint8_t reserved0;
uint8_t effect_type;
uint8_t max_brightness;
uint8_t min_brightness;
uint32_t color0;
uint32_t color1;
uint16_t period0; // fade in
uint16_t period1; // fade out
uint16_t period2; // hold
uint16_t period3;
uint8_t effect_param0;
uint8_t effect_param1;
uint8_t effect_param2;
uint8_t effect_param3;
uint8_t padding0[30];
} e;
PktEffect() : e {}
{
}
void Init(int header, uint8_t report_id)
{
memset(buffer, 0, sizeof(buffer));
e.report_id = report_id;
if (header < 8)
e.header = 32 + header; // set as default
else
e.header = header;
e.zone0 = (uint32_t)(1 << (e.header - 32));
e.effect_type = EFFECT_STATIC;
e.max_brightness = 100;
e.min_brightness = 0;
e.color0 = 0x00FF2100; //orange
e.period0 = 1200;
e.period1 = 1200;
e.period2 = 200;
e.period3 = 200;
e.effect_param0 = 0; // ex color count to cycle through (max seems to be 7)
e.effect_param1 = 0;
e.effect_param2 = 1; // ex flash repeat count
e.effect_param3 = 0;
}
};
struct IT8297Report
{
uint8_t report_id;
uint8_t product;
uint8_t device_num;
uint8_t total_leds;
uint32_t fw_ver;
uint16_t curr_led_count;
uint16_t reserved0;
char str_product[32]; // might be 28 and an extra byteorder3
uint32_t byteorder0; // is little-endian 0x00RRGGBB ?
uint32_t byteorder1;
uint32_t byteorder2;
uint32_t chip_id;
uint32_t reserved1;
};
#pragma pack(pop)
class RGBFusion2USBController
{
public:
RGBFusion2USBController(hid_device* handle, const char *path, std::string mb_name);
~RGBFusion2USBController();
void SetStripColors
(
unsigned int hdr,
RGBColor * colors,
unsigned int num_colors,
int single_led = -1
);
void SetLEDEffect(unsigned int led, int mode, unsigned int speed, bool random, unsigned char red, unsigned char green, unsigned char blue);
void SetLedCount(unsigned int led, unsigned int count);
void SetMode(int mode);
bool ApplyEffect();
bool DisableBuiltinEffect(int enable_bit, int mask);
void SetCalibration();
std::string GetDeviceName();
std::string GetDeviceDescription();
std::string GetDeviceLocation();
std::string GetFWVersion();
std::string GetSerial();
private:
bool EnableBeat(bool enable);
bool SendPacket(uint8_t a, uint8_t b, uint8_t c = 0);
int SendPacket(unsigned char* packet);
hid_device* dev;
int mode;
IT8297Report report;
std::string name;
std::string description;
std::string loc;
std::string version;
std::string chip_id;
int effect_disabled = 0;
int report_id = 0xCC;
LEDCount D_LED1_count;
LEDCount D_LED2_count;
};

View file

@ -0,0 +1,73 @@
#include "Detector.h"
#include "GigabyteRGBFusion2USBController.h"
#include "RGBController_GigabyteRGBFusion2USB.h"
#include "dependencies/dmiinfo.h"
#define IT8297_VID 0x048D
#define IT8297_IFC 0
#define IT8297_U 0xCC
#define IT8297_UPG 0xFF89
#define COUNT_RGBFUSION2_PIDS (sizeof(RGBFusion2_pids) / sizeof(RGBFusion2_pids[ 0 ]))
static const unsigned short RGBFusion2_pids[] =
{
0x8297, //PID for the ITE 8595 found on the X570
0x5702 //PID for the ITE 8595 found on the B550
};
/******************************************************************************************\
* *
* DetectGigabyteRGBFusion2USBControllers *
* *
* Detect GigabyteRGB Fusion 2 devices that use IT8297 RGB controller *
* *
\******************************************************************************************/
void DetectGigabyteRGBFusion2USBControllers(std::vector<RGBController*> &rgb_controllers)
{
hid_device_info* info;
hid_device* dev;
DMIInfo MB_info;
unsigned short tmpPID;
if (hid_init() < 0)
{
return;
}
for(unsigned int dev_idx = 0; dev_idx < COUNT_RGBFUSION2_PIDS; dev_idx++)
{
dev = NULL;
tmpPID = RGBFusion2_pids[dev_idx];
info = hid_enumerate(IT8297_VID, tmpPID);
while(info)
{
if((info->vendor_id == IT8297_VID)
#ifdef USE_HID_USAGE
&&(info->product_id == tmpPID)
&&(info->usage == IT8297_U) //Usage and usage page required to get the correct interface
&&(info->usage_page == IT8297_UPG))
#else
&&(info->interface_number == IT8297_IFC) //Interface is only valid on Windows where there is > 1 interface
&&(info->product_id == tmpPID))
#endif
{
dev = hid_open_path(info->path);
if (dev)
{
RGBFusion2USBController * controller = new RGBFusion2USBController(dev, info->path, MB_info.getMainboard());
RGBController_RGBFusion2USB * rgb_controller = new RGBController_RGBFusion2USB(controller);
rgb_controllers.push_back(rgb_controller);
}
}
info = info->next;
}
}
hid_free_enumeration(info);
} /* DetectGigabyteRGBFusion2USBControllers() */
REGISTER_DETECTOR("Gigabyte RGB Fusion 2 USB", DetectGigabyteRGBFusion2USBControllers);

View file

@ -0,0 +1,468 @@
/*-----------------------------------------*\
| RGBController_GigabyteRGBFusion2USB.cpp |
| |
| Generic RGB Interface for OpenRGB |
| Gigabyte RGB Fusion 2.0 USB Driver |
| |
| jackun 1/8/2020 |
\*-----------------------------------------*/
#include "RGBController_GigabyteRGBFusion2USB.h"
#include <sstream>
#include <array>
static const MBName MBName2Layout
{
{"B550 AORUS PRO", "STD_ATX"},
{"B550 AORUS ELITE", "STD_ATX"},
{"X570 AORUS ELITE", "STD_ATX"},
{"X570 AORUS PRO WIFI", "STD_ATX"},
{"X570 AORUS ULTRA", "STD_ATX"},
{"B550I AORUS PRO AX", "ITX"},
{"X570 I AORUS PRO WIFI", "ITX"}
};
static const KnownLayout knownLayoutsLookup
{
{
"IT8297BX-GBX570", //Left as a catch all
{
{
"Motherboard",
{
{ "Led 1", 0x20, 1 },
{ "Led 2", 0x21, 1 },
{ "Led 3", 0x22, 1 },
{ "Led 4", 0x23, 1 },
{ "Led 5", 0x24, 1 },
{ "Led 6", 0x25, 1 },
{ "Led 7", 0x26, 1 },
{ "Led 8", 0x27, 1 },
}
},
{
"D_LED1 Bottom",
{
{ "LED Strip 1", HDR_D_LED1, 0 },
}
},
{
"D_LED2 Top",
{
{ "LED Strip 2", HDR_D_LED2, 0 },
}
}
}
},
{
"STD_ATX",
{
{
"Motherboard",
{
{ "Back I/O", HDR_BACK_IO, 1 },
{ "CPU Header", HDR_CPU, 1 },
{ "PCIe", HDR_PCIE, 1},
{ "LED C1/C2", HDR_LED_C1C2, 1 }, // 12VGRB headers seem to be connected
}
},
{
"D_LED1 Bottom",
{
{ "D_LED1 Bottom", HDR_D_LED1, 0 },
}
},
{
"D_LED2 Top",
{
{ "D_LED2 Top", HDR_D_LED2, 0 },
}
}
}
},
{
"ITX",
{
{
"Motherboard",
{
{ "LED Group0", HDR_BACK_IO, 1 },
{ "LED Group1", HDR_CPU, 1 },
{ "LED Group2", HDR_LED_2, 1 },
{ "LED Group3", HDR_PCIE, 1 },
{ "LED C1/C2", HDR_LED_C1C2, 1 }, // 12VGRB headers seem to be connected
}
},
{
"D_LED1",
{
{ "D_LED1", HDR_D_LED1, 0 },
}
}
}
},
};
RGBController_RGBFusion2USB::RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr)
{
controller = controller_ptr;
name = controller->GetDeviceName();
type = DEVICE_TYPE_MOTHERBOARD;
description = controller->GetDeviceDescription();
version = controller->GetFWVersion();
location = controller->GetDeviceLocation();
serial = controller->GetSerial();
mode Direct;
Direct.name = "Direct";
Direct.value = 0xFFFF;
Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
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.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.speed_min = 0;
Breathing.speed_max = 4;
Breathing.colors_min = 1;
Breathing.colors_max = 1;
Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Breathing.colors.resize(1);
Breathing.speed = 2;
modes.push_back(Breathing);
mode Blinking;
Blinking.name = "Blinking";
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.speed_min = 0;
Blinking.speed_max = 4;
Blinking.colors_min = 1;
Blinking.colors_max = 1;
Blinking.color_mode = MODE_COLORS_MODE_SPECIFIC;
Blinking.colors.resize(1);
Blinking.speed = 2;
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.speed_min = 0;
ColorCycle.speed_max = 4;
ColorCycle.color_mode = MODE_COLORS_NONE;
ColorCycle.speed = 2;
modes.push_back(ColorCycle);
mode Flashing;
Flashing.name = "Flashing";
Flashing.value = 10;
Flashing.flags = MODE_FLAG_HAS_BRIGHTNESS | MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR;
Flashing.speed_min = 0;
Flashing.speed_max = 4;
Flashing.colors_min = 1;
Flashing.colors_max = 1;
Flashing.color_mode = MODE_COLORS_MODE_SPECIFIC;
Flashing.colors.resize(1);
Flashing.speed = 2;
modes.push_back(Flashing);
Init_Controller(); //Only processed on first run
SetupZones();
}
void RGBController_RGBFusion2USB::Init_Controller()
{
/*---------------------------------------------------------*\
| Look up channel map based on device name |
\*---------------------------------------------------------*/
if ( MBName2Layout.count(controller->GetDeviceName()) ) //Quick way to get a boolean on find()
{
layout = knownLayoutsLookup.find(MBName2Layout.find(controller->GetDeviceName())->second )->second;
}
else
{
layout = knownLayoutsLookup.find("IT8297BX-GBX570")->second;
}
zones.resize(layout.size());
int zone_idx = 0;
for(ZoneLeds::iterator zl = layout.begin(); zl != layout.end(); ++zl)
{
std::vector<LedPort> lp = zl->second;
int LED_count = 0; //We're going to count the leds in the zone
bool boolSingleLED = true; //If all the Ledport.count == 1 then the zone is ZONE_TYPE_SINGLE
for(std::size_t lp_idx = 0; lp_idx < lp.size(); lp_idx++)
{
int lp_count = lp[lp_idx].count;
boolSingleLED = boolSingleLED && (lp_count == 1); //Is this a single LED zone??
LED_count += lp_count;
}
zones[zone_idx].name = zl->first;
zones[zone_idx].leds_min = (boolSingleLED) ? LED_count : RGBFusion2_Digital_LEDS_Min;
zones[zone_idx].leds_max = (boolSingleLED) ? LED_count : RGBFusion2_Digital_LEDS_Max;
zones[zone_idx].leds_count = (boolSingleLED) ? LED_count : 0; //Digital LEDS will not be set yet
zones[zone_idx].type = (boolSingleLED) ? ZONE_TYPE_SINGLE : ZONE_TYPE_LINEAR;
zones[zone_idx].matrix_map = NULL;
zone_idx++;
}
}
void RGBController_RGBFusion2USB::SetupZones()
{
/*-------------------------------------------------*\
| Clear any existing color/LED configuration |
\*-------------------------------------------------*/
leds.clear();
colors.clear();
/*---------------------------------------------------------*\
| Set up zones |
\*---------------------------------------------------------*/
int zone_idx = 0;
for(ZoneLeds::iterator zl = layout.begin(); zl != layout.end(); ++zl)
{
bool boolSingleLED = (zones[zone_idx].type == ZONE_TYPE_SINGLE); //Calculated for later use
if (!boolSingleLED)
{
controller->SetLedCount(zl->second.at(0).header, zones[zone_idx].leds_count);
controller->DisableBuiltinEffect(0, 0x3);
}
for(unsigned int lp_idx = 0; lp_idx < zones[zone_idx].leds_count; lp_idx++)
{
led new_led;
if(boolSingleLED)
{
new_led.name = zl->second.at(lp_idx).name;
new_led.value = zl->second.at(lp_idx).header;
}
else
{
new_led.name = zl->second.at(0).name;
new_led.name.append(" LED " + std::to_string(lp_idx));
new_led.value = zl->second.at(0).header;
}
leds.push_back(new_led);
}
zone_idx++;
}
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::SetCustomMode()
{
active_mode = 0;
}
void RGBController_RGBFusion2USB::DeviceUpdateLEDs()
{
for(size_t zone_idx = 0; zone_idx < zones.size(); zone_idx++)
{
UpdateZoneLEDs(zone_idx);
}
}
void RGBController_RGBFusion2USB::UpdateZoneLEDs(int zone)
{
/*---------------------------------------------------------*\
| Get mode parameters |
\*---------------------------------------------------------*/
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
int mode_value = (modes[active_mode].value);
/*---------------------------------------------------------*\
| Set motherboard LEDs |
\*---------------------------------------------------------*/
if(zones[zone].type == ZONE_TYPE_SINGLE)
{
unsigned char red = 0;
unsigned char grn = 0;
unsigned char blu = 0;
for(std::size_t led_idx = 0; led_idx < zones[zone].leds_count; led_idx++)
{
/*---------------------------------------------------------*\
| Initialize mode value |
\*---------------------------------------------------------*/
mode_value = modes[active_mode].value;
/*---------------------------------------------------------*\
| Motherboard LEDs always use effect mode, so use static for|
| direct mode but get colors from zone |
\*---------------------------------------------------------*/
if(mode_value == 0xFFFF)
{
red = RGBGetRValue(zones[zone].colors[led_idx]);
grn = RGBGetGValue(zones[zone].colors[led_idx]);
blu = RGBGetBValue(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)
{
red = RGBGetRValue(modes[active_mode].colors[0]);
grn = RGBGetGValue(modes[active_mode].colors[0]);
blu = RGBGetBValue(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, random, red, grn, blu);
}
controller->ApplyEffect();
}
/*---------------------------------------------------------*\
| Set strip LEDs |
\*---------------------------------------------------------*/
else
{
if(zones[zone].leds_count) //If the Digital zone has been resized i.e. > 0
{
unsigned char hdr = zones[zone].leds->value;
/*---------------------------------------------------------*\
| Direct mode |
\*---------------------------------------------------------*/
if(mode_value == 0xFFFF)
{
hdr += RGBFusion2_Digital_Direct_Offset; //Direct mode addresses a different register
controller->DisableBuiltinEffect(1, hdr == HDR_D_LED1_RGB ? 0x01 : 0x02);
controller->SetStripColors(hdr, zones[zone].colors, zones[zone].leds_count);
}
/*---------------------------------------------------------*\
| Effect mode |
\*---------------------------------------------------------*/
else
{
unsigned char red = 0;
unsigned char grn = 0;
unsigned char blu = 0;
/*---------------------------------------------------------*\
| If mode has mode specific color, load color from mode |
\*---------------------------------------------------------*/
if(modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC)
{
red = RGBGetRValue(modes[active_mode].colors[0]);
grn = RGBGetGValue(modes[active_mode].colors[0]);
blu = RGBGetBValue(modes[active_mode].colors[0]);
}
/*---------------------------------------------------------*\
| Apply built-in effects to LED strips |
\*---------------------------------------------------------*/
controller->DisableBuiltinEffect(0, hdr == HDR_D_LED1 ? 0x01 : 0x02);
controller->SetLEDEffect(hdr, modes[active_mode].value, modes[active_mode].speed, random, red, grn, blu);
controller->ApplyEffect();
}
}
}
}
void RGBController_RGBFusion2USB::UpdateSingleLED(int led)
{
/*---------------------------------------------------------*\
| Get mode parameters |
\*---------------------------------------------------------*/
bool random = (modes[active_mode].color_mode == MODE_COLORS_RANDOM);
int mode_value = (modes[active_mode].value);
unsigned int zone_idx = GetLED_Zone(led);
/*---------------------------------------------------------*\
| Set motherboard LEDs |
\*---------------------------------------------------------*/
if(zones[zone_idx].type == ZONE_TYPE_SINGLE)
{
unsigned char red = 0;
unsigned char grn = 0;
unsigned char blu = 0;
/*---------------------------------------------------------*\
| Motherboard LEDs always use effect mode, so use static for|
| direct mode but get colors from zone |
\*---------------------------------------------------------*/
if(mode_value == 0xFFFF)
{
red = RGBGetRValue(colors[led]);
grn = RGBGetGValue(colors[led]);
blu = RGBGetBValue(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)
{
red = RGBGetRValue(modes[active_mode].colors[0]);
grn = RGBGetGValue(modes[active_mode].colors[0]);
blu = RGBGetBValue(modes[active_mode].colors[0]);
}
controller->SetLEDEffect(leds[led].value, mode_value, modes[active_mode].speed, random, red, grn, blu);
controller->ApplyEffect();
}
/*---------------------------------------------------------*\
| Set strip LEDs |
\*---------------------------------------------------------*/
else
{
UpdateZoneLEDs(zone_idx);
}
}
void RGBController_RGBFusion2USB::DeviceUpdateMode()
{
DeviceUpdateLEDs();
}
int RGBController_RGBFusion2USB::GetLED_Zone(int led_idx)
{
//This may be more useful in the abstract RGBController.cpp
for(size_t zone_idx = 0; zone_idx < 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);
}
return -1; // NotFound error?
}

View file

@ -0,0 +1,54 @@
/*-----------------------------------------*\
| RGBController_GigabyteRGBFusion2USB.h |
| |
| Generic RGB Interface for OpenRGB |
| Gigabyte RGB Fusion 2.0 USB Driver |
| |
| jackun 1/8/2020 |
\*-----------------------------------------*/
#pragma once
#include "RGBController.h"
#include "GigabyteRGBFusion2USBController.h"
#include <map>
#include <vector>
#define RGBFusion2_Digital_LEDS_Min 0;
#define RGBFusion2_Digital_LEDS_Max 1024;
#define RGBFusion2_Digital_Direct_Offset (HDR_D_LED1_RGB - HDR_D_LED1);
struct LedPort
{
const char* name;
int header;
int count;
};
typedef std::map< std::string, std::string > MBName;
typedef std::map< std::string, std::vector<LedPort> > ZoneLeds;
typedef std::map< std::string, ZoneLeds> KnownLayout;
class RGBController_RGBFusion2USB: public RGBController
{
public:
RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr);
void SetupZones();
void ResizeZone(int zone, int new_size);
void DeviceUpdateLEDs();
void UpdateZoneLEDs(int zone);
void UpdateSingleLED(int led);
void SetCustomMode();
void DeviceUpdateMode();
private:
void Init_Controller();
int GetLED_Zone(int led_idx);
RGBFusion2USBController* controller;
IT8297Report report;
ZoneLeds layout;
};