diff --git a/RGBController/RGBController.h b/RGBController/RGBController.h index d146007f..c97a69a0 100644 --- a/RGBController/RGBController.h +++ b/RGBController/RGBController.h @@ -20,11 +20,9 @@ typedef unsigned int RGBColor; #define ToRGBColor(r, g, b) ((b << 16) | (g << 8) | (r)) -typedef struct -{ - std::string name; /* LED name */ -} led; - +/*------------------------------------------------------------------*\ +| Mode Flags | +\*------------------------------------------------------------------*/ enum { MODE_FLAG_HAS_SPEED = (1 << 0), /* Mode has speed parameter */ @@ -37,14 +35,30 @@ enum MODE_FLAG_PER_LED_COLOR = (1 << 7), /* Mode uses device LED colors */ }; +/*------------------------------------------------------------------*\ +| Mode Type | +\*------------------------------------------------------------------*/ typedef struct { + /*--------------------------------------------------------------*\ + | Mode Information | + \*--------------------------------------------------------------*/ std::string name; /* Mode name */ int value; /* Device-specific mode value */ - unsigned int speed; /* Mode speed parameter value */ unsigned int flags; /* Mode flags bitfield */ + + /*--------------------------------------------------------------*\ + | Mode Settings | + \*--------------------------------------------------------------*/ + unsigned int speed; /* Mode speed parameter value */ + bool random; /* Random color mode enabled */ } mode; +typedef struct +{ + std::string name; /* LED name */ +} led; + typedef int zone_type; enum @@ -91,6 +105,7 @@ public: std::vector modes; /* Modes */ std::vector colors; /* Color buffer */ device_type type; /* device type */ + int active_mode; /* active mode */ virtual ~RGBController() = default; diff --git a/RGBController/RGBController_Aura.cpp b/RGBController/RGBController_Aura.cpp index ab7998b9..1267d725 100644 --- a/RGBController/RGBController_Aura.cpp +++ b/RGBController/RGBController_Aura.cpp @@ -11,7 +11,26 @@ int RGBController_Aura::GetMode() { - int dev_mode = aura->AuraRegisterRead(AURA_REG_MODE); + int dev_mode = aura->AuraRegisterRead(AURA_REG_MODE); + bool random = false; + + switch(dev_mode) + { + case AURA_MODE_SPECTRUM_CYCLE_CHASE: + dev_mode = AURA_MODE_CHASE; + random = true; + break; + + case AURA_MODE_SPECTRUM_CYCLE_BREATHING: + dev_mode = AURA_MODE_BREATHING; + random = true; + break; + + case AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE: + dev_mode = AURA_MODE_CHASE_FADE; + random = true; + break; + } if (aura->AuraRegisterRead(AURA_REG_DIRECT)) { @@ -22,11 +41,12 @@ int RGBController_Aura::GetMode() { if(modes[mode].value == dev_mode) { - return(mode); + active_mode = mode; + modes[mode].random = random; } } - return(0); + return(active_mode); } void RGBController_Aura::SetMode(int mode) @@ -37,7 +57,25 @@ void RGBController_Aura::SetMode(int mode) } else { - aura->SetMode(modes[mode].value); + int new_mode = modes[mode].value; + + if(modes[mode].random == true) + { + switch(new_mode) + { + case AURA_MODE_CHASE: + new_mode = AURA_MODE_SPECTRUM_CYCLE_CHASE; + break; + case AURA_MODE_BREATHING: + new_mode = AURA_MODE_SPECTRUM_CYCLE_BREATHING; + break; + case AURA_MODE_CHASE_FADE: + new_mode = AURA_MODE_SPECTRUM_CYCLE_CHASE_FADE; + break; + } + } + + aura->SetMode(new_mode); aura->SetDirect(false); } } diff --git a/qt/OpenRGBDevicePage.cpp b/qt/OpenRGBDevicePage.cpp index 98118032..65e4d3a1 100644 --- a/qt/OpenRGBDevicePage.cpp +++ b/qt/OpenRGBDevicePage.cpp @@ -129,10 +129,57 @@ void Ui::OpenRGBDevicePage::on_LEDBox_currentIndexChanged(int index) void Ui::OpenRGBDevicePage::on_ModeBox_currentIndexChanged(int /*index*/) { + /*-----------------------------------------------------*\ + | Read new mode flags and settings | + \*-----------------------------------------------------*/ + 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); + } + /*-----------------------------------------------------*\ | Change device mode | \*-----------------------------------------------------*/ - device->SetMode(ui->ModeBox->currentIndex()); + UpdateMode(); +} + +void Ui::OpenRGBDevicePage::on_RandomCheck_clicked() +{ + /*-----------------------------------------------------*\ + | Change device mode | + \*-----------------------------------------------------*/ + UpdateMode(); +} + +void Ui::OpenRGBDevicePage::UpdateMode() +{ + /*-----------------------------------------------------*\ + | Read user interface | + \*-----------------------------------------------------*/ + int current_mode = ui->ModeBox->currentIndex(); + int current_speed = 0; + bool current_random = ui->RandomCheck->checkState(); + + /*-----------------------------------------------------*\ + | Update mode parameters | + \*-----------------------------------------------------*/ + device->modes[current_mode].speed = current_speed; + device->modes[current_mode].random = current_random; + + /*-----------------------------------------------------*\ + | Change device mode | + \*-----------------------------------------------------*/ + device->SetMode(current_mode); } void Ui::OpenRGBDevicePage::SetDevice(unsigned char red, unsigned char green, unsigned char blue) diff --git a/qt/OpenRGBDevicePage.h b/qt/OpenRGBDevicePage.h index 080e2e95..0185a9b2 100644 --- a/qt/OpenRGBDevicePage.h +++ b/qt/OpenRGBDevicePage.h @@ -19,6 +19,7 @@ public: ~OpenRGBDevicePage(); void SetDevice(unsigned char red, unsigned char green, unsigned char blue); + void UpdateMode(); private slots: void on_ButtonRed_clicked(); @@ -42,6 +43,8 @@ private slots: void on_SetAllButton_clicked(); + void on_RandomCheck_clicked(); + private: Ui::OpenRGBDevicePageUi *ui; RGBController *device; diff --git a/qt/OpenRGBDevicePage.ui b/qt/OpenRGBDevicePage.ui index 0f788b72..51bfd48f 100644 --- a/qt/OpenRGBDevicePage.ui +++ b/qt/OpenRGBDevicePage.ui @@ -381,6 +381,19 @@ Set All Devices + + + + 100 + 240 + 100 + 20 + + + + Random Color + +