Add Random Color checkbox and combine Aura fixed-color and cycling ("random") modes to use this new checkbox

This commit is contained in:
Adam Honse 2020-01-13 22:22:15 -06:00
parent 2efd0dc81d
commit c70943da18
5 changed files with 127 additions and 11 deletions

View file

@ -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<mode> modes; /* Modes */
std::vector<RGBColor> colors; /* Color buffer */
device_type type; /* device type */
int active_mode; /* active mode */
virtual ~RGBController() = default;

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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;

View file

@ -381,6 +381,19 @@
<string>Set All Devices</string>
</property>
</widget>
<widget class="QCheckBox" name="RandomCheck">
<property name="geometry">
<rect>
<x>100</x>
<y>240</y>
<width>100</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Random Color</string>
</property>
</widget>
</widget>
<resources/>
<connections/>