From 6e467fe8cd2d32e31ab88d83c363ec51268bf51e Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 22 Dec 2019 02:18:20 -0600 Subject: [PATCH] Initial work on direct mode for HyperX Predator RGB --- .../HyperXController/HyperXController.cpp | 66 ++++++++-- .../HyperXController/HyperXController.h | 122 ++++++++++++++++-- RGBController/RGBController_HyperX.cpp | 53 +++++--- 3 files changed, 203 insertions(+), 38 deletions(-) diff --git a/Controllers/HyperXController/HyperXController.cpp b/Controllers/HyperXController/HyperXController.cpp index eb853d92..351777f5 100644 --- a/Controllers/HyperXController/HyperXController.cpp +++ b/Controllers/HyperXController/HyperXController.cpp @@ -16,7 +16,9 @@ HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev) this->dev = dev; strcpy(device_name, "HyperX Predator RGB"); - led_count = 1; + led_count = 5; + + mode = HYPERX_MODE_DIRECT; } HyperXController::~HyperXController() @@ -44,36 +46,82 @@ unsigned int HyperXController::GetLEDCount() return(led_count); } +unsigned int HyperXController::GetMode() +{ + return(mode); +} + +void HyperXController::SetEffectColor(unsigned char red, unsigned char green, unsigned char blue) +{ + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); + + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_RED, red); + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_GREEN, green); + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_EFFECT_BLUE, blue); + + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02); + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03); +} + void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue) { bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_RED, red); - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_GREEN, green); - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_BLUE, blue); + for(int slot = 0; slot < 4; slot++) + { + unsigned char red_base = HYPERX_REG_SLOT0_LED0_RED + (0x20 * slot); + unsigned char green_base = HYPERX_REG_SLOT0_LED0_GREEN + (0x20 * slot); + unsigned char blue_base = HYPERX_REG_SLOT0_LED0_BLUE + (0x20 * slot); + unsigned char bright_base = HYPERX_REG_SLOT0_LED0_BRIGHTNESS + (0x20 * slot); + + if(mode == HYPERX_MODE_DIRECT) + { + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE3, HYPERX_MODE3_DIRECT); + } + + for(int led = 0; led < 5; led++) + { + bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red ); + bus->i2c_smbus_write_byte_data(dev, green_base + (3 * led), green); + bus->i2c_smbus_write_byte_data(dev, blue_base + (3 * led), blue ); + bus->i2c_smbus_write_byte_data(dev, bright_base + (3 * led), 0x64 ); + } + } bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02); bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03); } -void HyperXController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue) +void HyperXController::SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue) { + unsigned char red_base = HYPERX_REG_SLOT0_LED0_RED + (0x20 * slot); + unsigned char green_base = HYPERX_REG_SLOT0_LED0_GREEN + (0x20 * slot); + unsigned char blue_base = HYPERX_REG_SLOT0_LED0_BLUE + (0x20 * slot); + unsigned char bright_base = HYPERX_REG_SLOT0_LED0_BRIGHTNESS + (0x20 * slot); + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_RED, red); - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_GREEN, green); - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_BLUE, blue); + bus->i2c_smbus_write_byte_data(dev, red_base + (3 * led), red ); + bus->i2c_smbus_write_byte_data(dev, green_base + (3 * led), green); + bus->i2c_smbus_write_byte_data(dev, blue_base + (3 * led), blue ); + bus->i2c_smbus_write_byte_data(dev, bright_base + (3 * led), 0x64 ); bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02); bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03); } -void HyperXController::SetMode(unsigned char mode) +void HyperXController::SetMode(unsigned char new_mode) { + mode = new_mode; + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); switch (mode) { + case HYPERX_MODE_DIRECT: + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE3, HYPERX_MODE3_DIRECT); + break; + case HYPERX_MODE_STATIC: bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE2, HYPERX_MODE2_STATIC); break; diff --git a/Controllers/HyperXController/HyperXController.h b/Controllers/HyperXController/HyperXController.h index 3545fdc4..64f99cc2 100644 --- a/Controllers/HyperXController/HyperXController.h +++ b/Controllers/HyperXController/HyperXController.h @@ -17,13 +17,98 @@ typedef unsigned short hyperx_register; enum { - HYPERX_REG_BRIGHTNESS = 0xDD, /* Brightness control register (0-100) */ + HYPERX_REG_SLOT0_LED0_RED = 0x11, /* R color register for LED 0, Slot 0 */ + HYPERX_REG_SLOT0_LED0_GREEN = 0x12, /* G color register for LED 0, Slot 0 */ + HYPERX_REG_SLOT0_LED0_BLUE = 0x13, /* B color register for LED 0, Slot 0 */ + HYPERX_REG_SLOT0_LED1_RED = 0x14, /* R color register for LED 1, Slot 0 */ + HYPERX_REG_SLOT0_LED1_GREEN = 0x15, /* G color register for LED 1, Slot 0 */ + HYPERX_REG_SLOT0_LED1_BLUE = 0x16, /* B color register for LED 1, Slot 0 */ + HYPERX_REG_SLOT0_LED2_RED = 0x17, /* R color register for LED 2, Slot 0 */ + HYPERX_REG_SLOT0_LED2_GREEN = 0x18, /* G color register for LED 2, Slot 0 */ + HYPERX_REG_SLOT0_LED2_BLUE = 0x19, /* B color register for LED 2, Slot 0 */ + HYPERX_REG_SLOT0_LED3_RED = 0x1A, /* R color register for LED 3, Slot 0 */ + HYPERX_REG_SLOT0_LED3_GREEN = 0x1B, /* G color register for LED 3, Slot 0 */ + HYPERX_REG_SLOT0_LED3_BLUE = 0x1C, /* B color register for LED 3, Slot 0 */ + HYPERX_REG_SLOT0_LED4_RED = 0x1D, /* R color register for LED 4, Slot 0 */ + HYPERX_REG_SLOT0_LED4_GREEN = 0x1E, /* G color register for LED 4, Slot 0 */ + HYPERX_REG_SLOT0_LED4_BLUE = 0x1F, /* B color register for LED 4, Slot 0 */ + HYPERX_REG_SLOT0_LED0_BRIGHTNESS = 0x21, /* Brightness for LED 0, Slot 0 (0-100) */ + HYPERX_REG_SLOT0_LED1_BRIGHTNESS = 0x24, /* Brightness for LED 1, Slot 0 (0-100) */ + HYPERX_REG_SLOT0_LED2_BRIGHTNESS = 0x27, /* Brightness for LED 2, Slot 0 (0-100) */ + HYPERX_REG_SLOT0_LED3_BRIGHTNESS = 0x2A, /* Brightness for LED 3, Slot 0 (0-100) */ + HYPERX_REG_SLOT0_LED4_BRIGHTNESS = 0x2D, /* Brightness for LED 4, Slot 0 (0-100) */ + + HYPERX_REG_SLOT1_LED0_RED = 0x31, /* R color register for LED 0, Slot 1 */ + HYPERX_REG_SLOT1_LED0_GREEN = 0x32, /* G color register for LED 0, Slot 1 */ + HYPERX_REG_SLOT1_LED0_BLUE = 0x33, /* B color register for LED 0, Slot 1 */ + HYPERX_REG_SLOT1_LED1_RED = 0x34, /* R color register for LED 1, Slot 1 */ + HYPERX_REG_SLOT1_LED1_GREEN = 0x35, /* G color register for LED 1, Slot 1 */ + HYPERX_REG_SLOT1_LED1_BLUE = 0x36, /* B color register for LED 1, Slot 1 */ + HYPERX_REG_SLOT1_LED2_RED = 0x37, /* R color register for LED 2, Slot 1 */ + HYPERX_REG_SLOT1_LED2_GREEN = 0x38, /* G color register for LED 2, Slot 1 */ + HYPERX_REG_SLOT1_LED2_BLUE = 0x39, /* B color register for LED 2, Slot 1 */ + HYPERX_REG_SLOT1_LED3_RED = 0x3A, /* R color register for LED 3, Slot 1 */ + HYPERX_REG_SLOT1_LED3_GREEN = 0x3B, /* G color register for LED 3, Slot 1 */ + HYPERX_REG_SLOT1_LED3_BLUE = 0x3C, /* B color register for LED 3, Slot 1 */ + HYPERX_REG_SLOT1_LED4_RED = 0x3D, /* R color register for LED 4, Slot 1 */ + HYPERX_REG_SLOT1_LED4_GREEN = 0x3E, /* G color register for LED 4, Slot 1 */ + HYPERX_REG_SLOT1_LED4_BLUE = 0x3F, /* B color register for LED 4, Slot 1 */ + HYPERX_REG_SLOT1_LED0_BRIGHTNESS = 0x41, /* Brightness for LED 0, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED1_BRIGHTNESS = 0x44, /* Brightness for LED 1, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED2_BRIGHTNESS = 0x47, /* Brightness for LED 2, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED3_BRIGHTNESS = 0x4A, /* Brightness for LED 3, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED4_BRIGHTNESS = 0x4D, /* Brightness for LED 4, Slot 1 (0-100) */ + + HYPERX_REG_SLOT2_LED0_RED = 0x51, /* R color register for LED 0, Slot 2 */ + HYPERX_REG_SLOT2_LED0_GREEN = 0x52, /* G color register for LED 0, Slot 2 */ + HYPERX_REG_SLOT2_LED0_BLUE = 0x53, /* B color register for LED 0, Slot 2 */ + HYPERX_REG_SLOT2_LED1_RED = 0x54, /* R color register for LED 1, Slot 2 */ + HYPERX_REG_SLOT2_LED1_GREEN = 0x55, /* G color register for LED 1, Slot 2 */ + HYPERX_REG_SLOT2_LED1_BLUE = 0x56, /* B color register for LED 1, Slot 2 */ + HYPERX_REG_SLOT2_LED2_RED = 0x57, /* R color register for LED 2, Slot 2 */ + HYPERX_REG_SLOT2_LED2_GREEN = 0x58, /* G color register for LED 2, Slot 2 */ + HYPERX_REG_SLOT2_LED2_BLUE = 0x59, /* B color register for LED 2, Slot 2 */ + HYPERX_REG_SLOT2_LED3_RED = 0x5A, /* R color register for LED 3, Slot 2 */ + HYPERX_REG_SLOT2_LED3_GREEN = 0x5B, /* G color register for LED 3, Slot 2 */ + HYPERX_REG_SLOT2_LED3_BLUE = 0x5C, /* B color register for LED 3, Slot 2 */ + HYPERX_REG_SLOT2_LED4_RED = 0x5D, /* R color register for LED 4, Slot 2 */ + HYPERX_REG_SLOT2_LED4_GREEN = 0x5E, /* G color register for LED 4, Slot 2 */ + HYPERX_REG_SLOT2_LED4_BLUE = 0x5F, /* B color register for LED 4, Slot 2 */ + HYPERX_REG_SLOT2_LED0_BRIGHTNESS = 0x61, /* Brightness for LED 0, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED1_BRIGHTNESS = 0x64, /* Brightness for LED 1, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED2_BRIGHTNESS = 0x67, /* Brightness for LED 2, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED3_BRIGHTNESS = 0x6A, /* Brightness for LED 3, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED4_BRIGHTNESS = 0x6D, /* Brightness for LED 4, Slot 2 (0-100) */ + + HYPERX_REG_SLOT3_LED0_RED = 0x71, /* R color register for LED 0, Slot 3 */ + HYPERX_REG_SLOT3_LED0_GREEN = 0x72, /* G color register for LED 0, Slot 3 */ + HYPERX_REG_SLOT3_LED0_BLUE = 0x73, /* B color register for LED 0, Slot 3 */ + HYPERX_REG_SLOT3_LED1_RED = 0x74, /* R color register for LED 1, Slot 3 */ + HYPERX_REG_SLOT3_LED1_GREEN = 0x75, /* G color register for LED 1, Slot 3 */ + HYPERX_REG_SLOT3_LED1_BLUE = 0x76, /* B color register for LED 1, Slot 3 */ + HYPERX_REG_SLOT3_LED2_RED = 0x77, /* R color register for LED 2, Slot 3 */ + HYPERX_REG_SLOT3_LED2_GREEN = 0x78, /* G color register for LED 2, Slot 3 */ + HYPERX_REG_SLOT3_LED2_BLUE = 0x79, /* B color register for LED 2, Slot 3 */ + HYPERX_REG_SLOT3_LED3_RED = 0x7A, /* R color register for LED 3, Slot 3 */ + HYPERX_REG_SLOT3_LED3_GREEN = 0x7B, /* G color register for LED 3, Slot 3 */ + HYPERX_REG_SLOT3_LED3_BLUE = 0x7C, /* B color register for LED 3, Slot 3 */ + HYPERX_REG_SLOT3_LED4_RED = 0x7D, /* R color register for LED 4, Slot 3 */ + HYPERX_REG_SLOT3_LED4_GREEN = 0x7E, /* G color register for LED 4, Slot 3 */ + HYPERX_REG_SLOT3_LED4_BLUE = 0x7F, /* B color register for LED 4, Slot 3 */ + HYPERX_REG_SLOT3_LED0_BRIGHTNESS = 0x81, /* Brightness for LED 0, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED1_BRIGHTNESS = 0x84, /* Brightness for LED 1, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED2_BRIGHTNESS = 0x87, /* Brightness for LED 2, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED3_BRIGHTNESS = 0x8A, /* Brightness for LED 3, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED4_BRIGHTNESS = 0x8D, /* Brightness for LED 4, Slot 3 (0-100) */ + + HYPERX_REG_EFFECT_BRIGHTNESS = 0xDD, /* Brightness for effects (0-100) */ HYPERX_REG_APPLY = 0xE1, /* Apply changes register */ HYPERX_REG_MODE1 = 0xE3, /* Mode control register 1 */ HYPERX_REG_MODE2 = 0xE4, /* Mode control register 2 */ - HYPERX_REG_RED = 0xEC, /* Red color register */ - HYPERX_REG_GREEN = 0xED, /* Green color register */ - HYPERX_REG_BLUE = 0xEE, /* Blue color register */ + HYPERX_REG_MODE3 = 0xE5, /* Mode control register 3 */ + HYPERX_REG_EFFECT_RED = 0xEC, /* Red color register for effects */ + HYPERX_REG_EFFECT_GREEN = 0xED, /* Green color register for effects */ + HYPERX_REG_EFFECT_BLUE = 0xEE, /* Blue color register for effects */ }; enum @@ -44,14 +129,20 @@ enum enum { - HYPERX_MODE_STATIC = 0, /* Static color mode */ - HYPERX_MODE_RAINBOW = 1, /* Rainbow wave mode */ - HYPERX_MODE_COMET = 2, /* Comet (chase) mode */ - HYPERX_MODE_HEARTBEAT = 3, /* Heartbeat (pulsing) mode */ - HYPERX_MODE_CYCLE = 4, /* Spectrum cycle mode */ - HYPERX_MODE_BREATHING = 5, /* Breathing mode */ - HYPERX_MODE_BOUNCE = 6, /* Bounce mode */ - HYPERX_MODE_BLINK = 7, /* Blinking mode */ + HYPERX_MODE3_DIRECT = 0x21, /* Mode 3 direct control */ +}; + +enum +{ + HYPERX_MODE_DIRECT = 0, /* Direct control mode */ + HYPERX_MODE_STATIC = 1, /* Static color mode */ + HYPERX_MODE_RAINBOW = 2, /* Rainbow wave mode */ + HYPERX_MODE_COMET = 3, /* Comet (chase) mode */ + HYPERX_MODE_HEARTBEAT = 4, /* Heartbeat (pulsing) mode */ + HYPERX_MODE_CYCLE = 5, /* Spectrum cycle mode */ + HYPERX_MODE_BREATHING = 6, /* Breathing mode */ + HYPERX_MODE_BOUNCE = 7, /* Bounce mode */ + HYPERX_MODE_BLINK = 8, /* Blinking mode */ HYPERX_NUMBER_MODES /* Number of HyperX modes */ }; @@ -65,14 +156,17 @@ public: std::string GetDeviceName(); std::string GetDeviceLocation(); unsigned int GetLEDCount(); - void SetMode(unsigned char mode); + unsigned int GetMode(); + void SetMode(unsigned char new_mode); void SetAllColors(unsigned char red, unsigned char green, unsigned char blue); - void SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue); + void SetEffectColor(unsigned char red, unsigned char green, unsigned char blue); + void SetLEDColor(unsigned int slot, unsigned int led, unsigned char red, unsigned char green, unsigned char blue); private: char device_name[32]; unsigned int led_count; i2c_smbus_interface* bus; hyperx_dev_id dev; + unsigned int mode; }; diff --git a/RGBController/RGBController_HyperX.cpp b/RGBController/RGBController_HyperX.cpp index da058f1d..ad84935c 100644 --- a/RGBController/RGBController_HyperX.cpp +++ b/RGBController/RGBController_HyperX.cpp @@ -21,7 +21,7 @@ void RGBController_HyperX::SetMode(int mode) void RGBController_HyperX::SetCustomMode() { - hyperx->SetMode(HYPERX_MODE_STATIC); + hyperx->SetMode(HYPERX_MODE_DIRECT); } void RGBController_HyperX::SetAllLEDs(RGBColor color) @@ -30,7 +30,15 @@ void RGBController_HyperX::SetAllLEDs(RGBColor color) unsigned char grn = RGBGetGValue(color); unsigned char blu = RGBGetBValue(color); - hyperx->SetAllColors(red, grn, blu); + if(hyperx->GetMode() == HYPERX_MODE_DIRECT) + { + hyperx->SetAllColors(red, grn, blu); + } + else + { + hyperx->SetEffectColor(red, grn, blu); + } + } void RGBController_HyperX::SetAllZoneLEDs(int zone, RGBColor color) @@ -39,13 +47,20 @@ void RGBController_HyperX::SetAllZoneLEDs(int zone, RGBColor color) unsigned char grn = RGBGetGValue(color); unsigned char blu = RGBGetBValue(color); - for (int x = 0; x < zones[zone].map.size(); x++) + if(hyperx->GetMode() == HYPERX_MODE_DIRECT) { - for (int y = 0; y < zones[zone].map[x].size(); y++) + for (int x = 0; x < zones[zone].map.size(); x++) { - hyperx->SetLEDColor(zones[zone].map[x][y], red, grn, blu); + for (int y = 0; y < zones[zone].map[x].size(); y++) + { + hyperx->SetLEDColor(0, zones[zone].map[x][y], red, grn, blu); + } } } + else + { + hyperx->SetEffectColor(red, grn, blu); + } } void RGBController_HyperX::SetLED(int led, RGBColor color) @@ -54,7 +69,14 @@ void RGBController_HyperX::SetLED(int led, RGBColor color) unsigned char grn = RGBGetGValue(color); unsigned char blu = RGBGetBValue(color); - hyperx->SetLEDColor(led, red, grn, blu); + if(hyperx->GetMode() == HYPERX_MODE_DIRECT) + { + hyperx->SetLEDColor(0, led, red, grn, blu); + } + else + { + hyperx->SetEffectColor(red, grn, blu); + } } void RGBController_HyperX::UpdateLEDs() @@ -68,19 +90,20 @@ RGBController_HyperX::RGBController_HyperX(HyperXController* hyperx_ptr) name = hyperx->GetDeviceName(); location = hyperx->GetDeviceLocation(); - + type = DEVICE_TYPE_DRAM; mode hyperx_modes[HYPERX_NUMBER_MODES]; - hyperx_modes[0].name = "Static"; - hyperx_modes[1].name = "Rainbow"; - hyperx_modes[2].name = "Comet"; - hyperx_modes[3].name = "Heartbeat"; - hyperx_modes[4].name = "Spectrum Cycle"; - hyperx_modes[5].name = "Breathing"; - hyperx_modes[6].name = "Bounce"; - hyperx_modes[7].name = "Blink"; + hyperx_modes[0].name = "Direct"; + hyperx_modes[1].name = "Static"; + hyperx_modes[2].name = "Rainbow"; + hyperx_modes[3].name = "Comet"; + hyperx_modes[4].name = "Heartbeat"; + hyperx_modes[5].name = "Spectrum Cycle"; + hyperx_modes[6].name = "Breathing"; + hyperx_modes[7].name = "Bounce"; + hyperx_modes[8].name = "Blink"; for (int i = 0; i < HYPERX_NUMBER_MODES; i++) {