Moved GB_Fusion2USB calibration & custom layout loading to config file

+ Adding layout for Z390 AORUS MASTER-CF
+ Adding destructor to RGBController_GigabyteRGBFusion2USB.cpp to
'delete controller'

+ Allows custom layout saving to config
+ Custom config will save out to config if not present
+ Layout is enablable and disabled by default
+ Added a lookup map from mapping in config
+ Added a template for the reverse_map for saving to the config
+ Removed the header integers from the config to avoid invalid values
+ Changed internal mapping closer to JSON for ease of lookup
+ Added protection to the led count

+ Added calibration to config
* Disabled execution of calibration until explicitely enabled in config

Commit amended for code style of changes as well as general cleanup of RGB Fusion 2 USB controller by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
Chris 2021-04-15 11:06:04 +10:00 committed by Adam Honse
parent 9b2296b0bc
commit 727fd9efb9
5 changed files with 695 additions and 271 deletions

View file

@ -4,27 +4,59 @@
| Driver for Gigabyte Aorus RGB Fusion 2.0 |
| USB lighting controller |
| |
| jackun 1/8/2020 |
| Author: jackun 1/8/2020 |
| Maintainer: Chris M (Dr_No) |
\*-----------------------------------------*/
#include "GigabyteRGBFusion2USBController.h"
#include <algorithm>
#include <array>
#include <thread>
#include <chrono>
#include "ResourceManager.h"
#include "SettingsManager.h"
/*-------------------------------------------------------------------------*\
| 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} }
};
static calibration GigabyteBoardCalibration
{
{ "D_LED1", "GRB" },
{ "D_LED2", "GRB" },
{ "Mainboard", "BGR" },
{ "Spare", "BGR" }
};
static LEDCount LedCountToEnum(unsigned int c)
{
if (c <= 32)
if(c <= 32)
{
return(LEDS_32);
if (c <= 64)
}
else if(c <= 64)
{
return(LEDS_64);
if (c <= 256)
}
else if(c <= 256)
{
return(LEDS_256);
if (c <= 512)
}
else if(c <= 512)
{
return(LEDS_512);
}
else
{
return(LEDS_1024);
}
}
RGBFusion2USBController::RGBFusion2USBController(hid_device* handle, const char *path, std::string mb_name) : dev(handle)
@ -33,17 +65,21 @@ RGBFusion2USBController::RGBFusion2USBController(hid_device* handle, const char
char text[64] = { 0x00 };
unsigned char buffer[64] = { 0x00 };
if( dev )
if(dev)
{
SetCalibration();
name = mb_name;
// hid report read needs 0x60 packet or it gives IO error
/*---------------------------------------------------------*\
| 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 )
if(res > 0)
{
report = *reinterpret_cast<IT8297Report*>(buffer);
@ -59,6 +95,7 @@ RGBFusion2USBController::RGBFusion2USBController(hid_device* handle, const char
D_LED1_count = LedCountToEnum(report.total_leds & 0x0F);
D_LED2_count = LedCountToEnum(report.total_leds & 0xF0);
}
location = path;
EnableBeat(false);
@ -75,61 +112,117 @@ 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.
RGBA RGBFusion2USBController::GetCalibration(std::string rgb_order)
{
/*-------------------------------------------------*\
| Check for RGB order string in calibration table |
| If not found return the "BGR" calibration |
\*-------------------------------------------------*/
if(GigabyteCalibrationsLookup.count(rgb_order))
{
return GigabyteCalibrationsLookup.find(rgb_order)->second;
}
else
{
return GigabyteCalibrationsLookup.find("BGR")->second;
}
}
void RGBFusion2USBController::SetCalibrationBuffer(std::string rgb_order, uint8_t* buffer, uint8_t offset)
{
RGBA rgb_cal;
int raw_size = sizeof(rgb_cal.raw) / sizeof(rgb_cal.raw[0]);
rgb_cal = GetCalibration(rgb_order);
for(int i = 0; i < raw_size; i++)
{
buffer[offset + i] = rgb_cal.raw[i];
}
}
/*---------------------------------------------------------------------------------------------*\
| 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] {};
const std::string detector_name = "Gigabyte RGB Fusion 2 USB";
const std::string json_cal = "Calibration";
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
json device_settings = settings_manager->GetSettings(detector_name);
/*---------------------------------------------------------*\
| Get Layouts from the settings manager |
| If Calibration settings are not found then write them out |
| Calibration will only be executed if it is explicitly |
| enabled by the user |
\*---------------------------------------------------------*/
if(!device_settings.contains(json_cal))
{
device_settings[json_cal]["Enabled"] = false;
device_settings[json_cal]["Data"] = GigabyteBoardCalibration;
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
else if(device_settings[json_cal]["Enabled"])
{
GigabyteBoardCalibration["D_LED1"] = device_settings[json_cal]["Data"]["D_LED1"];
GigabyteBoardCalibration["D_LED2"] = device_settings[json_cal]["Data"]["D_LED2"];
GigabyteBoardCalibration["Mainboard"] = device_settings[json_cal]["Data"]["Mainboard"];
GigabyteBoardCalibration["Spare"] = device_settings[json_cal]["Data"]["Spare"];
uint8_t buffer[64] = { 0x00 };
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;
SetCalibrationBuffer( GigabyteBoardCalibration.find("D_LED1")->second, buffer, 2);
SetCalibrationBuffer( GigabyteBoardCalibration.find("D_LED2")->second, buffer, 6);
SetCalibrationBuffer( GigabyteBoardCalibration.find("Mainboard")->second, buffer, 10);
SetCalibrationBuffer( GigabyteBoardCalibration.find("Spare")->second, buffer, 14);
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);
/*-----------------------------------------------------------------*\
| Check which Digital LED we're setting then send the value of both |
\*-----------------------------------------------------------------*/
if(led == HDR_D_LED1)
{
D_LED1_count = LedCountToEnum(count);
}
else
{
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
/*-----------------------------------------------------------------*\
| Sometimes effect doesn't apply at first, delay a little and let |
| MCU react, if this packet is the cause |
\*-----------------------------------------------------------------*/
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return res;
}
@ -174,8 +267,19 @@ void RGBFusion2USBController::SetStripColors
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;
/*-------------------------------------------------------------------------*\
| FIXME assuming that LED strips ports are 0x58/0x59 for all boards |
\*-------------------------------------------------------------------------*/
uint32_t byteorder;
if(hdr == HDR_D_LED1_RGB)
{
byteorder = report.byteorder0;
}
else
{
byteorder = report.byteorder1;
}
unsigned char bo_r = byteorder >> 16;
unsigned char bo_g = byteorder >> 8;
@ -187,8 +291,10 @@ void RGBFusion2USBController::SetStripColors
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
/*-------------------------------------------------------------------------*\
| 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;
@ -220,17 +326,25 @@ void RGBFusion2USBController::SetStripColors
}
res = SendPacket(pkt.buffer);
if(res < 0)
{
return;
}
}
if (hdr == HDR_D_LED1_RGB)
if(hdr == HDR_D_LED1_RGB)
{
DisableBuiltinEffect(0x01, 0x01);
}
else
{
DisableBuiltinEffect(0x02, 0x02);
}
}
static const std::array< std::array<int, 3>, 5> speeds = {
static const std::array< std::array<int, 3>, 5> speeds =
{
{
{1600, 1600, 200},
{1200, 1200, 200},
@ -243,12 +357,15 @@ static const std::array< std::array<int, 3>, 5> speeds = {
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];
if(speed < speeds.size())
{
const std::array<int, 3>& s = speeds[speed];
pkt.e.period0 = s[0];
pkt.e.period1 = s[1];
pkt.e.period2 = s[2];
@ -256,26 +373,41 @@ void RGBFusion2USBController::SetLEDEffect(unsigned int led, int mode, unsigned
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
case 0:
break;
case 4: // color cycle
// Static
case 1:
break;
// Breathing
case 2:
// Blink
case 3:
if(random)
{
pkt.e.effect_param0 = 7; // cycle through up to 7 (max?) colors
}
break;
// Color Cycle
case 4:
pkt.e.effect_param0 = 7; // cycle through up to 7 (max?) colors
break;
// "fake" effects
// "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;
}
@ -290,11 +422,13 @@ bool RGBFusion2USBController::ApplyEffect()
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);
return(SendPacket(buffer) == 64);
}
int RGBFusion2USBController::SendPacket(unsigned char* packet)

View file

@ -4,26 +4,52 @@
| Definitions and types for Gigabyte Aorus |
| RGB Fusion 2.0 USB lighting controller |
| |
| jackun 1/8/2020 |
| Author: jackun 1/8/2020 |
| Maintainer: Chris M (Dr_No) |
\*-----------------------------------------*/
#include "RGBController.h"
#include <algorithm>
#include <array>
#include <chrono>
#include <cstring>
#include <hidapi/hidapi.h>
#include <map>
#include <thread>
#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;
#define GB_CALIBRATION_SIZE (sizeof(GB_Calibrations) / sizeof(GB_Calibrations[0]))
const uint8_t HDR_D_LED1_RGB = 0x58; // FIXME assuming that it is 0x58 for all boards
/*-------------------------------------------------------------*\
| Standardising LED naming for external config layout |
\*-------------------------------------------------------------*/
const uint8_t LED1 = 0x20;
const uint8_t LED2 = 0x21;
const uint8_t LED3 = 0x22;
const uint8_t LED4 = 0x23;
const uint8_t LED5 = 0x24;
const uint8_t LED6 = 0x25;
const uint8_t LED7 = 0x26;
const uint8_t LED8 = 0x27;
/*-------------------------------------------------------------*\
| LED "headers" 0x20..0x27, As seen on Gigabyte X570 Elite board|
| Internal legacy shorthand naming and possibly depracated |
\*-------------------------------------------------------------*/
const uint8_t HDR_BACK_IO = LED1;
const uint8_t HDR_CPU = LED2;
const uint8_t HDR_LED_2 = LED3;
const uint8_t HDR_PCIE = LED4;
const uint8_t HDR_LED_C1C2 = LED5;
const uint8_t HDR_D_LED1 = LED6;
const uint8_t HDR_D_LED2 = LED7;
const uint8_t HDR_LED_7 = LED8;
/*-------------------------------------------------------------*\
| FIXME assuming that it is 0x58 for all boards |
\*-------------------------------------------------------------*/
const uint8_t HDR_D_LED1_RGB = 0x58;
const uint8_t HDR_D_LED2_RGB = 0x59;
enum EffectType
@ -54,6 +80,24 @@ struct LEDs
#pragma pack(push, 1)
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;
union PktRGB
{
unsigned char buffer[64];
@ -61,7 +105,7 @@ union PktRGB
{
uint8_t report_id;
uint8_t header;
uint16_t boffset; // in bytes, absolute
uint16_t boffset; // In bytes, absolute
uint8_t bcount;
LEDs leds[19];
uint16_t padding0;
@ -88,7 +132,7 @@ union PktEffect
{
uint8_t report_id;
uint8_t header;
uint32_t zone0; // rgb fusion seems to set it to pow(2, header - 0x20)
uint32_t zone0; // RGB Fusion seems to set it to pow(2, header - 0x20)
uint32_t zone1;
uint8_t reserved0;
uint8_t effect_type;
@ -96,9 +140,9 @@ union PktEffect
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 period0; // Fade in
uint16_t period1; // Fade out
uint16_t period2; // Hold
uint16_t period3;
uint8_t effect_param0;
uint8_t effect_param1;
@ -114,11 +158,18 @@ union PktEffect
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
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;
@ -184,6 +235,8 @@ private:
bool EnableBeat(bool enable);
bool SendPacket(uint8_t a, uint8_t b, uint8_t c = 0);
int SendPacket(unsigned char* packet);
RGBA GetCalibration( std::string rgb_order);
void SetCalibrationBuffer(std::string rgb_order, uint8_t* buffer, uint8_t offset);
hid_device* dev;
int mode;

View file

@ -2,6 +2,7 @@
#include "GigabyteRGBFusion2USBController.h"
#include "RGBController_GigabyteRGBFusion2USB.h"
#include "dependencies/dmiinfo.h"
#define DETECTOR_NAME "Gigabyte RGB Fusion 2 USB"
#define IT8297_VID 0x048D
#define IT8297_IFC 0
@ -23,17 +24,17 @@ void DetectGigabyteRGBFusion2USBControllers(hid_device_info* info, const std::st
if (dev)
{
RGBFusion2USBController * controller = new RGBFusion2USBController(dev, info->path, MB_info.getMainboard());
RGBController_RGBFusion2USB * rgb_controller = new RGBController_RGBFusion2USB(controller);
RGBController_RGBFusion2USB * rgb_controller = new RGBController_RGBFusion2USB(controller, DETECTOR_NAME);
// Constructor sets the name
ResourceManager::get()->RegisterRGBController(rgb_controller);
}
} /* DetectRGBFusion2USBControllers() */
#ifdef USE_HID_USAGE
REGISTER_HID_DETECTOR_PU("Gigabyte RGB Fusion 2 USB", DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8297, IT8297_UPG, IT8297_U);
REGISTER_HID_DETECTOR_PU("Gigabyte RGB Fusion 2 USB", DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5702, IT8297_UPG, IT8297_U);
REGISTER_HID_DETECTOR_PU(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8297, IT8297_UPG, IT8297_U);
REGISTER_HID_DETECTOR_PU(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5702, IT8297_UPG, IT8297_U);
#else
REGISTER_HID_DETECTOR_I("Gigabyte RGB Fusion 2 USB", DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8297, IT8297_IFC);
REGISTER_HID_DETECTOR_I("Gigabyte RGB Fusion 2 USB", DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5702, IT8297_IFC);
REGISTER_HID_DETECTOR_I(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x8297, IT8297_IFC);
REGISTER_HID_DETECTOR_I(DETECTOR_NAME, DetectGigabyteRGBFusion2USBControllers, IT8297_VID, 0x5702, IT8297_IFC);
#endif

View file

@ -4,26 +4,84 @@
| Generic RGB Interface for OpenRGB |
| Gigabyte RGB Fusion 2.0 USB Driver |
| |
| jackun 1/8/2020 |
| Author: jackun 1/8/2020 |
| Maintainer: Chris M (Dr_No) |
\*-----------------------------------------*/
#include "RGBController_GigabyteRGBFusion2USB.h"
#include "ResourceManager.h"
#include "SettingsManager.h"
#include <sstream>
#include <array>
static const MBName MBName2Layout
/*-------------------------------------------------*\
| LedHeaders is a map of the led header addresses |
\*-------------------------------------------------*/
static FwdLedHeaders LedLookup
{
{"LED1", 0x20}, {"LED2", 0x21}, {"LED3", 0x22}, {"LED4", 0x23},
{"LED5", 0x24}, {"LED6", 0x25}, {"LED7", 0x26}, {"LED8", 0x27},
{"D_LED1", 0x58}, {"D_LED2", 0x59},
};
/*-------------------------------------------------*\
| This is the default knownLayouts structure and |
| will be written into config if it doesn't exist |
\*-------------------------------------------------*/
static MBName MBName2LayoutLookup
{
{"B550 AORUS PRO", "STD_ATX"},
{"B550 AORUS ELITE", "STD_ATX"},
{"B550 AORUS PRO", "STD_ATX"},
{"B550I AORUS PRO AX", "ITX"},
{"X570 AORUS ELITE", "STD_ATX"},
{"X570 AORUS ELITE WIFI", "STD_ATX"},
{"X570 AORUS PRO WIFI", "STD_ATX"},
{"X570 AORUS ULTRA", "STD_ATX"},
{"B550I AORUS PRO AX", "ITX"},
{"X570 I AORUS PRO WIFI", "ITX"}
{"X570 I AORUS PRO WIFI", "ITX"},
{"Z390 AORUS MASTER-CF", "MSTR_ATX"}
};
static const KnownLayout knownLayoutsLookup
/*-------------------------------------------------*\
| This is the default Custom layout that will be |
| written into config if it doesn't exist |
\*-------------------------------------------------*/
static const KnownLayout HardcodedCustom
{
{
"Custom",
{
{
"Motherboard",
{
{ "Name for Led 1", LED1, 1 },
{ "Name for Led 2", LED2, 1 },
{ "Name for Led 3", LED3, 1 },
{ "Name for Led 4", LED4, 1 },
{ "Name for Led 5", LED5, 1 },
{ "Name for Led 8", LED8, 1 },
}
},
{
"D_LED1 Bottom",
{
{ "Name for LED Strip 1", HDR_D_LED1, 0 },
}
},
{
"D_LED2 Top",
{
{ "Name for LED Strip 2", HDR_D_LED2, 0 },
}
}
}
}
};
/*-------------------------------------------------*\
| KnownLayoutsLookup now needs to be variable to |
| allow for a custom addition from config |
\*-------------------------------------------------*/
static KnownLayout knownLayoutsLookup
{
{
"IT8297BX-GBX570", //Left as a catch all
@ -31,26 +89,26 @@ static const KnownLayout knownLayoutsLookup
{
"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 },
{ "Name for Led 1", LED1, 1 },
{ "Name for Led 2", LED2, 1 },
{ "Name for Led 3", LED3, 1 },
{ "Name for Led 4", LED4, 1 },
{ "Name for Led 5", LED5, 1 },
{ "Name for Led 6", LED6, 1 },
{ "Name for Led 7", LED7, 1 },
{ "Name for Led 8", LED8, 1 },
}
},
{
"D_LED1 Bottom",
{
{ "LED Strip 1", HDR_D_LED1, 0 },
{ "Name for LED Strip 1", HDR_D_LED1, 0 },
}
},
{
"D_LED2 Top",
{
{ "LED Strip 2", HDR_D_LED2, 0 },
{ "Name for LED Strip 2", HDR_D_LED2, 0 },
}
}
}
@ -102,13 +160,40 @@ static const KnownLayout knownLayoutsLookup
}
}
},
{
"MSTR_ATX",
{
{
"Digital Headers",
{
{ "D_LED1 / D_LED2", LED6, 0},
}
},
{
"ARGB Strip",
{
{ "Back IO / VRM", LED7, 0},
}
},
{
"Motherboard",
{
{ "XMP Logo", LED2, 1},
{ "Chipset Logo", LED3, 1},
{ "PCIe", LED4, 1},
{ "LED C1/C2", LED5, 1},
}
}
}
},
};
RGBController_RGBFusion2USB::RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr)
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();
@ -182,7 +267,8 @@ RGBController_RGBFusion2USB::RGBController_RGBFusion2USB(RGBFusion2USBController
Flashing.speed = 2;
modes.push_back(Flashing);
Init_Controller(); //Only processed on first run
Load_Device_Config();
Init_Controller();
SetupZones();
}
@ -191,12 +277,120 @@ RGBController_RGBFusion2USB::~RGBController_RGBFusion2USB()
delete controller;
}
void RGBController_RGBFusion2USB::Load_Device_Config()
{
const std::string SectionLayout = "MotherboardLayouts";
const std::string SectionCustom = "CustomLayout";
SettingsManager* settings_manager = ResourceManager::get()->GetSettingsManager();
json device_settings = settings_manager->GetSettings(detector_name);
RvrseLedHeaders ReverseLedLookup = reverse_map(LedLookup);
/*-------------------------------------------------*\
| Get Layouts from the settings manager |
| If MotherboardLayouts is not found then write it |
| to settings |
\*-------------------------------------------------*/
if(!device_settings.contains(SectionLayout))
{
device_settings[SectionLayout] = MBName2LayoutLookup;
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
MBName2Layout = MBName2LayoutLookup;
}
else
{
for(nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::json>>& it : device_settings[SectionLayout].items())
{
MBName2Layout.insert( std::pair<std::string, std::string>(it.key(), it.value() ));
}
}
/*-------------------------------------------------*\
| Get Custom Layout from the settings manager |
\*-------------------------------------------------*/
layout = HardcodedCustom.find("Custom")->second;
if (!device_settings.contains(SectionCustom))
{
/*---------------------------------------------*\
| If the Custom layout is not found then write |
| it to settings |
\*---------------------------------------------*/
json json_HCL;
for(ZoneLeds::iterator zl = layout.begin(); zl != layout.end(); zl++)
{
std::vector<LedPort> v_lp = zl->second;
json json_zl;
for(std::vector<LedPort>::iterator lp_it = v_lp.begin(); lp_it != v_lp.end(); lp_it++)
{
json json_lp;
json_lp["name"] = lp_it[0].name;
json_lp["header"] = ReverseLedLookup.find(lp_it[0].header)->second;
json_zl.push_back(json_lp);
}
json_HCL.emplace(zl->first, json_zl);
}
device_settings[SectionCustom]["Enabled"] = false;
device_settings[SectionCustom]["Data"] = json_HCL;
settings_manager->SetSettings(detector_name, device_settings);
settings_manager->SaveSettings();
}
else
{
custom_layout = device_settings[SectionCustom]["Enabled"];
/*---------------------------------------------*\
| If the Custom layout is found and enabled |
| then read it in from config |
\*---------------------------------------------*/
if(custom_layout)
{
json json_HCL = device_settings[SectionCustom]["Data"];
layout.clear();
for(nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::json>>& json_layout_it : json_HCL.items())
{
json json_zl = json_layout_it.value();
std::vector<LedPort> v_lp;
for(json& zl : json_zl)
{
json json_vlp = zl;
LedPort lp;
/*---------------------------------*\
| Initialize the name, header, and |
| count values. Set the D_LED |
| headers LED count to 0 |
\*---------------------------------*/
lp.name = json_vlp["name"].get<std::string>();
lp.header = LedLookup.find(json_vlp["header"].get<std::string>())->second;
lp.count = ((lp.header == LED6) || (lp.header == LED7)) ? 0 : 1;
v_lp.push_back(lp);
}
layout.insert(std::pair<std::string,std::vector<LedPort>>(json_layout_it.key(),v_lp));
}
}
}
}
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()
if (!custom_layout)
{
/*-----------------------------------------------------*\
| If the layout is custom then it's loaded and ready, |
| otherwise get known layouts |
| This check is a quick way to get a boolean on find() |
\*-----------------------------------------------------*/
if(MBName2Layout.count(controller->GetDeviceName()))
{
layout = knownLayoutsLookup.find(MBName2Layout.find(controller->GetDeviceName())->second )->second;
}
@ -204,25 +398,38 @@ void RGBController_RGBFusion2USB::Init_Controller()
{
layout = knownLayoutsLookup.find("IT8297BX-GBX570")->second;
}
}
/*---------------------------------------------------------*\
| Initialize the number of zones from the layout |
\*---------------------------------------------------------*/
zones.resize(layout.size());
/*---------------------------------------------------------*\
| Iterate through layout and process each zone |
\*---------------------------------------------------------*/
int zone_idx = 0;
for(ZoneLeds::iterator zl = layout.begin(); zl != layout.end(); ++zl)
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
int LED_count = 0;
bool single_zone = true;
for(std::size_t lp_idx = 0; lp_idx < lp.size(); lp_idx++)
{
/*-------------------------------------------------*\
| Get LED count and check if it is a single LED zone|
\*-------------------------------------------------*/
int lp_count = lp[lp_idx].count;
boolSingleLED = boolSingleLED && (lp_count == 1); //Is this a single LED zone??
single_zone = single_zone && (lp_count == 1);
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].leds_min = (single_zone) ? LED_count : RGBFusion2_Digital_LEDS_Min;
zones[zone_idx].leds_max = (single_zone) ? LED_count : RGBFusion2_Digital_LEDS_Max;
zones[zone_idx].leds_count = (single_zone) ? LED_count : 0;
zones[zone_idx].type = (single_zone) ? ZONE_TYPE_SINGLE : ZONE_TYPE_LINEAR;
zones[zone_idx].matrix_map = NULL;
zone_idx++;
}
@ -240,11 +447,11 @@ void RGBController_RGBFusion2USB::SetupZones()
| Set up zones |
\*---------------------------------------------------------*/
int zone_idx = 0;
for(ZoneLeds::iterator zl = layout.begin(); zl != layout.end(); ++zl)
for(ZoneLeds::iterator zl = layout.begin(); zl != layout.end(); zl++)
{
bool boolSingleLED = (zones[zone_idx].type == ZONE_TYPE_SINGLE); //Calculated for later use
bool single_zone = (zones[zone_idx].type == ZONE_TYPE_SINGLE);
if (!boolSingleLED)
if(!single_zone)
{
controller->SetLedCount(zl->second.at(0).header, zones[zone_idx].leds_count);
controller->DisableBuiltinEffect(0, 0x3);
@ -254,7 +461,7 @@ void RGBController_RGBFusion2USB::SetupZones()
{
led new_led;
if(boolSingleLED)
if(single_zone)
{
new_led.name = zl->second.at(lp_idx).name;
new_led.value = zl->second.at(lp_idx).header;
@ -268,6 +475,7 @@ void RGBController_RGBFusion2USB::SetupZones()
leds.push_back(new_led);
}
zone_idx++;
}
@ -361,17 +569,17 @@ void RGBController_RGBFusion2USB::UpdateZoneLEDs(int zone)
\*---------------------------------------------------------*/
else
{
if(zones[zone].leds_count) //If the Digital zone has been resized i.e. > 0
if(zones[zone].leds_count)
{
unsigned char hdr = zones[zone].leds->value;
/*---------------------------------------------------------*\
| Direct mode |
| Direct mode addresses a different register |
\*---------------------------------------------------------*/
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);
hdr += RGBFusion2_Digital_Direct_Offset;
controller->DisableBuiltinEffect(1, ((hdr == HDR_D_LED1_RGB) ? 0x01 : 0x02));
controller->SetStripColors(hdr, zones[zone].colors, zones[zone].leds_count);
}
/*---------------------------------------------------------*\
@ -463,13 +671,19 @@ void RGBController_RGBFusion2USB::DeviceUpdateMode()
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)
if((zone_start <= led_idx) && (zone_end >= led_idx))
{
return(zone_idx);
}
return -1; // NotFound error?
}
/*---------------------------------*\
| If zone is not found, return -1 |
\*---------------------------------*/
return(-1);
}

View file

@ -4,7 +4,8 @@
| Generic RGB Interface for OpenRGB |
| Gigabyte RGB Fusion 2.0 USB Driver |
| |
| jackun 1/8/2020 |
| Author: jackun 1/8/2020 |
| Maintainer: Chris M (Dr_No) |
\*-----------------------------------------*/
#pragma once
@ -17,9 +18,25 @@
#define RGBFusion2_Digital_LEDS_Max 1024;
#define RGBFusion2_Digital_Direct_Offset (HDR_D_LED1_RGB - HDR_D_LED1);
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;
}
typedef std::map< std::string, int > FwdLedHeaders;
typedef std::map< int, std::string > RvrseLedHeaders;
struct LedPort
{
const char* name;
std::string name;
int header;
int count;
};
@ -31,7 +48,7 @@ typedef std::map< std::string, ZoneLeds> KnownLayout;
class RGBController_RGBFusion2USB: public RGBController
{
public:
RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr);
RGBController_RGBFusion2USB(RGBFusion2USBController* controller_ptr, std::string _detector_name);
~RGBController_RGBFusion2USB();
void SetupZones();
@ -46,10 +63,15 @@ public:
void DeviceUpdateMode();
private:
void Init_Controller();
int GetLED_Zone(int led_idx);
MBName MBName2Layout;
bool custom_layout;
std::string detector_name;
RGBFusion2USBController* controller;
IT8297Report report;
ZoneLeds layout;
void Load_Device_Config();
void Init_Controller();
int GetLED_Zone(int led_idx);
};