From 3ea73ee80cee607ff5a13b0f0f6f6978b15872c6 Mon Sep 17 00:00:00 2001 From: K900 Date: Fri, 20 Nov 2020 11:22:29 +0300 Subject: [PATCH] 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. --- Controllers/CrucialController/CrucialController.cpp | 7 +++++++ Controllers/CrucialController/CrucialController.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/Controllers/CrucialController/CrucialController.cpp b/Controllers/CrucialController/CrucialController.cpp index 6eaaa0175..d2d492634 100644 --- a/Controllers/CrucialController/CrucialController.cpp +++ b/Controllers/CrucialController/CrucialController.cpp @@ -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) diff --git a/Controllers/CrucialController/CrucialController.h b/Controllers/CrucialController/CrucialController.h index 09b1e84f3..25795188f 100644 --- a/Controllers/CrucialController/CrucialController.h +++ b/Controllers/CrucialController/CrucialController.h @@ -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;