Add mode parameters to Corsair Vengeance RGB Pro controller

This commit is contained in:
Adam Honse
2020-01-13 23:55:54 -06:00
parent c70943da18
commit fb3103e458
6 changed files with 117 additions and 50 deletions

View File

@@ -104,7 +104,17 @@ void CorsairProController::ApplyColors()
bus->i2c_smbus_write_byte_data(dev, 0x82, 0x02);
}
void CorsairProController::SetEffect(unsigned char mode)
void CorsairProController::SetEffect(unsigned char mode,
unsigned char speed,
unsigned char direction,
bool random,
unsigned char red1,
unsigned char grn1,
unsigned char blu1,
unsigned char red2,
unsigned char grn2,
unsigned char blu2
)
{
effect_mode = mode;
@@ -113,17 +123,28 @@ void CorsairProController::SetEffect(unsigned char mode)
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, effect_mode); //Mode
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_SPEED_MEDIUM); //Speed
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_EFFECT_RANDOM_COLORS); //Custom color
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, CORSAIR_PRO_DIRECTION_UP); //Direction
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 1 blue
unsigned char random_byte;
if(random)
{
random_byte = CORSAIR_PRO_EFFECT_RANDOM_COLORS;
}
else
{
random_byte = CORSAIR_PRO_EFFECT_CUSTOM_COLORS;
}
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, effect_mode); //Mode
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, speed); //Speed
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, random_byte); //Custom color
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, direction); //Direction
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, red1); // Custom color 1 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, grn1); // Custom color 1 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, blu1); // Custom color 1 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00); // Custom color 2 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, red2); // Custom color 2 red
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, grn2); // Custom color 2 green
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, blu2); // Custom color 2 blue
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0xFF);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
bus->i2c_smbus_write_byte_data(dev, CORSAIR_PRO_REG_COMMAND, 0x00);
@@ -140,7 +161,13 @@ void CorsairProController::SetEffect(unsigned char mode)
void CorsairProController::SetCustom()
{
SetEffect(CORSAIR_PRO_MODE_STATIC);
SetEffect(CORSAIR_PRO_MODE_STATIC,
0x00,
0x00,
false,
0x00, 0x00, 0x00,
0x00, 0x00, 0x00
);
}
bool CorsairProController::WaitReady()

View File

@@ -70,7 +70,17 @@ public:
std::string GetDeviceLocation();
unsigned int GetLEDCount();
unsigned char GetEffect();
void SetEffect(unsigned char mode);
void SetEffect(unsigned char mode,
unsigned char speed,
unsigned char direction,
bool random,
unsigned char red1,
unsigned char grn1,
unsigned char blu1,
unsigned char red2,
unsigned char grn2,
unsigned char blu2
);
void SetCustom();
void SetAllColors(unsigned char red, unsigned char green, unsigned char blue);

View File

@@ -51,15 +51,17 @@ int RGBController_Aura::GetMode()
void RGBController_Aura::SetMode(int mode)
{
if (modes[mode].value == 0xFFFF)
active_mode = mode;
if (modes[active_mode].value == 0xFFFF)
{
aura->SetDirect(true);
}
else
{
int new_mode = modes[mode].value;
int new_mode = modes[active_mode].value;
if(modes[mode].random == true)
if(modes[active_mode].random == true)
{
switch(new_mode)
{

View File

@@ -11,22 +11,23 @@
int RGBController_CorsairPro::GetMode()
{
int dev_mode = corsair->GetEffect();
for(int mode = 0; mode < modes.size(); mode++)
{
if(modes[mode].value == dev_mode)
{
return(mode);
}
}
return(0);
return(active_mode);
}
void RGBController_CorsairPro::SetMode(int mode)
{
corsair->SetEffect(modes[mode].value);
active_mode = mode;
corsair->SetEffect(modes[active_mode].value,
CORSAIR_PRO_SPEED_MEDIUM,
CORSAIR_PRO_DIRECTION_UP,
modes[active_mode].random,
RGBGetRValue(colors[0]),
RGBGetGValue(colors[0]),
RGBGetBValue(colors[0]),
RGBGetRValue(colors[1]),
RGBGetGValue(colors[1]),
RGBGetBValue(colors[1]));
}
void RGBController_CorsairPro::SetCustomMode()

View File

@@ -75,6 +75,11 @@ OpenRGBDevicePage::OpenRGBDevicePage(RGBController *dev, QWidget *parent) :
ui->ModeBox->setCurrentIndex(device->GetMode());
ui->ModeBox->blockSignals(false);
/*-----------------------------------------------------*\
| Update mode user interface elements |
\*-----------------------------------------------------*/
UpdateModeUi();
ui->ZoneBox->blockSignals(true);
ui->ZoneBox->clear();
@@ -130,22 +135,9 @@ void Ui::OpenRGBDevicePage::on_LEDBox_currentIndexChanged(int index)
void Ui::OpenRGBDevicePage::on_ModeBox_currentIndexChanged(int /*index*/)
{
/*-----------------------------------------------------*\
| Read new mode flags and settings |
| Update mode user interface elements |
\*-----------------------------------------------------*/
int selected_mode = ui->ModeBox->currentIndex();
bool supports_random = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_COLOR )
&& ( device->modes[selected_mode].flags & MODE_FLAG_RANDOM_COLOR );
bool random = device->modes[selected_mode].random;
if(supports_random)
{
ui->RandomCheck->setEnabled(true);
ui->RandomCheck->setCheckState(random ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
}
else
{
ui->RandomCheck->setEnabled(false);
}
UpdateModeUi();
/*-----------------------------------------------------*\
| Change device mode |
@@ -161,6 +153,34 @@ void Ui::OpenRGBDevicePage::on_RandomCheck_clicked()
UpdateMode();
}
void Ui::OpenRGBDevicePage::UpdateModeUi()
{
/*-----------------------------------------------------*\
| Read new mode flags and settings |
\*-----------------------------------------------------*/
int selected_mode = ui->ModeBox->currentIndex();
/*-----------------------------------------------------*\
| Don't update the UI if the current mode is invalid |
\*-----------------------------------------------------*/
if(selected_mode < device->modes.size())
{
bool supports_random = ( device->modes[selected_mode].flags & MODE_FLAG_HAS_COLOR )
&& ( device->modes[selected_mode].flags & MODE_FLAG_RANDOM_COLOR );
bool random = device->modes[selected_mode].random;
if(supports_random)
{
ui->RandomCheck->setEnabled(true);
ui->RandomCheck->setCheckState(random ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
}
else
{
ui->RandomCheck->setEnabled(false);
}
}
}
void Ui::OpenRGBDevicePage::UpdateMode()
{
/*-----------------------------------------------------*\
@@ -171,15 +191,21 @@ void Ui::OpenRGBDevicePage::UpdateMode()
bool current_random = ui->RandomCheck->checkState();
/*-----------------------------------------------------*\
| Update mode parameters |
| Don't set the mode if the current mode is invalid |
\*-----------------------------------------------------*/
device->modes[current_mode].speed = current_speed;
device->modes[current_mode].random = current_random;
if(current_mode < device->modes.size())
{
/*-----------------------------------------------------*\
| Update mode parameters |
\*-----------------------------------------------------*/
device->modes[current_mode].speed = current_speed;
device->modes[current_mode].random = current_random;
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
device->SetMode(current_mode);
/*-----------------------------------------------------*\
| Change device mode |
\*-----------------------------------------------------*/
device->SetMode(current_mode);
}
}
void Ui::OpenRGBDevicePage::SetDevice(unsigned char red, unsigned char green, unsigned char blue)

View File

@@ -20,6 +20,7 @@ public:
void SetDevice(unsigned char red, unsigned char green, unsigned char blue);
void UpdateMode();
void UpdateModeUi();
private slots:
void on_ButtonRed_clicked();