From 25807902c92be49814f73df8907bd2286f100e0f Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Fri, 13 Mar 2020 21:41:23 +0000 Subject: [PATCH] Set each LED independently for Crucial effect modes --- .../CrucialController/CrucialController.cpp | 35 ++++++++++++++----- .../CrucialController/CrucialController.h | 10 +++++- RGBController/RGBController_Crucial.cpp | 5 +-- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Controllers/CrucialController/CrucialController.cpp b/Controllers/CrucialController/CrucialController.cpp index 4f313b95..fd589933 100644 --- a/Controllers/CrucialController/CrucialController.cpp +++ b/Controllers/CrucialController/CrucialController.cpp @@ -52,16 +52,15 @@ void CrucialController::SetAllColorsDirect(RGBColor* colors) SendDirectColors(colors); } -void CrucialController::SendEffectColors(unsigned char red, unsigned char green, unsigned char blue) +void CrucialController::SetAllColorsEffect(RGBColor* colors) { - CrucialRegisterWrite(0x82E9, 0xFF); - CrucialRegisterWrite(0x82EA, 0x00); - CrucialRegisterWrite(0x82EB, 0x00); - CrucialRegisterWrite(0x82EC, 0x00); - CrucialRegisterWrite(0x82ED, red); - CrucialRegisterWrite(0x82EE, green); - CrucialRegisterWrite(0x82EF, blue); - CrucialRegisterWrite(0x82F0, 0x01); + for(int led_idx = 0; led_idx < 8; led_idx++) + { + unsigned char red = RGBGetRValue(colors[led_idx]); + unsigned char grn = RGBGetGValue(colors[led_idx]); + unsigned char blu = RGBGetBValue(colors[led_idx]); + SendEffectColor(led_idx, red, grn, blu); + } } void CrucialController::SendBrightness(unsigned char brightness) @@ -131,3 +130,21 @@ void CrucialController::CrucialRegisterWrite(crucial_register reg, unsigned char bus->i2c_smbus_write_byte_data(dev, 0x01, val); } + +void CrucialController::SendEffectColor + ( + unsigned int led_idx, + unsigned int red, + unsigned int green, + unsigned int blue + ) +{ + CrucialRegisterWrite(0x82E9, (1 << led_idx)); + CrucialRegisterWrite(0x82EA, 0x00); + CrucialRegisterWrite(0x82EB, 0x00); + CrucialRegisterWrite(0x82EC, 0x00); + CrucialRegisterWrite(0x82ED, red); + CrucialRegisterWrite(0x82EE, green); + CrucialRegisterWrite(0x82EF, blue); + CrucialRegisterWrite(0x82F0, 0x01); +} \ No newline at end of file diff --git a/Controllers/CrucialController/CrucialController.h b/Controllers/CrucialController/CrucialController.h index 2638f56c..09b1e84f 100644 --- a/Controllers/CrucialController/CrucialController.h +++ b/Controllers/CrucialController/CrucialController.h @@ -42,7 +42,7 @@ public: std::string GetDeviceLocation(); unsigned int GetLEDCount(); void SetAllColorsDirect(RGBColor* colors); - void SendEffectColors(unsigned char red, unsigned char green, unsigned char blue); + void SetAllColorsEffect(RGBColor* colors); void SetMode(unsigned char mode); unsigned char CrucialRegisterRead(crucial_register reg); @@ -56,6 +56,14 @@ private: i2c_smbus_interface * bus; crucial_dev_id dev; + void SendEffectColor + ( + unsigned int led_idx, + unsigned int red, + unsigned int green, + unsigned int blue + ); + void SendDirectColors(RGBColor* color_buf); void SendBrightness(unsigned char brightness); void SendEffectMode(unsigned char mode, unsigned char speed); diff --git a/RGBController/RGBController_Crucial.cpp b/RGBController/RGBController_Crucial.cpp index 98816998..9cdbf3b6 100644 --- a/RGBController/RGBController_Crucial.cpp +++ b/RGBController/RGBController_Crucial.cpp @@ -156,10 +156,7 @@ void RGBController_Crucial::UpdateLEDs() } else { - unsigned char red = RGBGetRValue(colors[0]); - unsigned char grn = RGBGetGValue(colors[0]); - unsigned char blu = RGBGetBValue(colors[0]); - crucial->SendEffectColors(red, grn, blu); + crucial->SetAllColorsEffect(&colors[0]); } }