CrucialController: keep track of the last set mode

This saves an extra control transfer when applying settings
that have already been applied. Mostly useful for direct mode.
This commit is contained in:
K900
2020-11-20 11:22:29 +03:00
committed by Adam Honse
parent 7cfdaaa501
commit 3ea73ee80c
2 changed files with 9 additions and 0 deletions

View File

@@ -15,6 +15,9 @@ CrucialController::CrucialController(i2c_smbus_interface* bus, crucial_dev_id de
{
this->bus = bus;
this->dev = dev;
// We don't know what mode the sticks are in until we set one.
this->last_mode = CRUCIAL_MODE_UNKNOWN;
}
CrucialController::~CrucialController()
@@ -44,7 +47,11 @@ unsigned int CrucialController::GetLEDCount()
void CrucialController::SetMode(unsigned char mode)
{
// Don't set a mode if we've already set the same one before.
// This is mostly useful for direct mode and updating colors often.
if (mode == last_mode) return;
SendEffectMode(mode, 0x10);
last_mode = mode;
}
void CrucialController::SetAllColorsDirect(RGBColor* colors)

View File

@@ -18,6 +18,7 @@ typedef unsigned short crucial_register;
enum
{
CRUCIAL_MODE_UNKNOWN = 0x00, /* We don't know what the mode is */
CRUCIAL_MODE_SHIFT = 0x1F, /* Shift effect mode */
CRUCIAL_MODE_GRADIENT_SHIFT = 0x2F, /* Gradient shift mode */
CRUCIAL_MODE_FILL = 0x3F, /* Fill effect mode */
@@ -53,6 +54,7 @@ private:
unsigned char config_table[64];
unsigned int led_count;
unsigned char channel_cfg;
unsigned char last_mode;
i2c_smbus_interface * bus;
crucial_dev_id dev;