diff --git a/Controllers/HyperXController/HyperXController.cpp b/Controllers/HyperXController/HyperXController.cpp index 351777f5..1367d8be 100644 --- a/Controllers/HyperXController/HyperXController.cpp +++ b/Controllers/HyperXController/HyperXController.cpp @@ -10,13 +10,23 @@ #include "HyperXController.h" #include -HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev) +HyperXController::HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots) { - this->bus = bus; - this->dev = dev; + this->bus = bus; + this->dev = dev; + slots_valid = slots; strcpy(device_name, "HyperX Predator RGB"); - led_count = 5; + + led_count = 0; + + for(int i = 0; i < 8; i++) + { + if((slots_valid & (1 << i)) != 0) + { + led_count += 5; + } + } mode = HYPERX_MODE_DIRECT; } @@ -55,9 +65,10 @@ void HyperXController::SetEffectColor(unsigned char red, unsigned char green, un { 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_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_EFFECT_BRIGHTNESS, 0x64 ); bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x02); bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x03); @@ -67,24 +78,32 @@ void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsi { bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); + /*-----------------------------------------------------*\ + | Loop through all slots and only set those which are | + | active. | + \*-----------------------------------------------------*/ 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) + if((slots_valid & (1 << slot)) != 0) { - bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_MODE3, HYPERX_MODE3_DIRECT); - } + unsigned char base = slot_base[slot]; + unsigned char red_base = base + 0x00; + unsigned char green_base = base + 0x01; + unsigned char blue_base = base + 0x02; + unsigned char bright_base = base + 0x10; - 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 ); + 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 ); + } } } @@ -92,12 +111,62 @@ void HyperXController::SetAllColors(unsigned char red, unsigned char green, unsi 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) +{ + /*-----------------------------------------------------*\ + | led_slot - the unmapped slot ID for the given LED | + | led - the LED ID within that slot | + | slot_id - counts enabled slots | + | slot - the mapped slot ID for the given LED | + \*-----------------------------------------------------*/ + int led_slot = led / 5; + int slot_id = -1; + int slot; + + led -= (led_slot * 5); + + /*-----------------------------------------------------*\ + | Loop through all possible slots and only count those | + | which are active. | + \*-----------------------------------------------------*/ + for(slot = 0; slot < 4; slot++) + { + if((slots_valid & ( 1 << slot)) != 0) + { + slot_id++; + } + + if(slot_id == led_slot) + { + break; + } + } + + unsigned char base = slot_base[slot]; + unsigned char red_base = base + 0x00; + unsigned char green_base = base + 0x01; + unsigned char blue_base = base + 0x02; + unsigned char bright_base = base + 0x10; + + bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); + + 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 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); + unsigned char base = slot_base[slot]; + unsigned char red_base = base + 0x00; + unsigned char green_base = base + 0x01; + unsigned char blue_base = base + 0x02; + unsigned char bright_base = base + 0x10; bus->i2c_smbus_write_byte_data(dev, HYPERX_REG_APPLY, 0x01); diff --git a/Controllers/HyperXController/HyperXController.h b/Controllers/HyperXController/HyperXController.h index 64f99cc2..9e73d8ce 100644 --- a/Controllers/HyperXController/HyperXController.h +++ b/Controllers/HyperXController/HyperXController.h @@ -38,68 +38,68 @@ enum 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_SLOT1_LED0_RED = 0x41, /* R color register for LED 0, Slot 1 */ + HYPERX_REG_SLOT1_LED0_GREEN = 0x42, /* G color register for LED 0, Slot 1 */ + HYPERX_REG_SLOT1_LED0_BLUE = 0x43, /* B color register for LED 0, Slot 1 */ + HYPERX_REG_SLOT1_LED1_RED = 0x44, /* R color register for LED 1, Slot 1 */ + HYPERX_REG_SLOT1_LED1_GREEN = 0x45, /* G color register for LED 1, Slot 1 */ + HYPERX_REG_SLOT1_LED1_BLUE = 0x46, /* B color register for LED 1, Slot 1 */ + HYPERX_REG_SLOT1_LED2_RED = 0x47, /* R color register for LED 2, Slot 1 */ + HYPERX_REG_SLOT1_LED2_GREEN = 0x48, /* G color register for LED 2, Slot 1 */ + HYPERX_REG_SLOT1_LED2_BLUE = 0x49, /* B color register for LED 2, Slot 1 */ + HYPERX_REG_SLOT1_LED3_RED = 0x4A, /* R color register for LED 3, Slot 1 */ + HYPERX_REG_SLOT1_LED3_GREEN = 0x4B, /* G color register for LED 3, Slot 1 */ + HYPERX_REG_SLOT1_LED3_BLUE = 0x4C, /* B color register for LED 3, Slot 1 */ + HYPERX_REG_SLOT1_LED4_RED = 0x4D, /* R color register for LED 4, Slot 1 */ + HYPERX_REG_SLOT1_LED4_GREEN = 0x4E, /* G color register for LED 4, Slot 1 */ + HYPERX_REG_SLOT1_LED4_BLUE = 0x4F, /* B color register for LED 4, Slot 1 */ + HYPERX_REG_SLOT1_LED0_BRIGHTNESS = 0x51, /* Brightness for LED 0, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED1_BRIGHTNESS = 0x54, /* Brightness for LED 1, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED2_BRIGHTNESS = 0x57, /* Brightness for LED 2, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED3_BRIGHTNESS = 0x5A, /* Brightness for LED 3, Slot 1 (0-100) */ + HYPERX_REG_SLOT1_LED4_BRIGHTNESS = 0x5D, /* 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_SLOT2_LED0_RED = 0x71, /* R color register for LED 0, Slot 2 */ + HYPERX_REG_SLOT2_LED0_GREEN = 0x72, /* G color register for LED 0, Slot 2 */ + HYPERX_REG_SLOT2_LED0_BLUE = 0x73, /* B color register for LED 0, Slot 2 */ + HYPERX_REG_SLOT2_LED1_RED = 0x74, /* R color register for LED 1, Slot 2 */ + HYPERX_REG_SLOT2_LED1_GREEN = 0x75, /* G color register for LED 1, Slot 2 */ + HYPERX_REG_SLOT2_LED1_BLUE = 0x76, /* B color register for LED 1, Slot 2 */ + HYPERX_REG_SLOT2_LED2_RED = 0x77, /* R color register for LED 2, Slot 2 */ + HYPERX_REG_SLOT2_LED2_GREEN = 0x78, /* G color register for LED 2, Slot 2 */ + HYPERX_REG_SLOT2_LED2_BLUE = 0x79, /* B color register for LED 2, Slot 2 */ + HYPERX_REG_SLOT2_LED3_RED = 0x7A, /* R color register for LED 3, Slot 2 */ + HYPERX_REG_SLOT2_LED3_GREEN = 0x7B, /* G color register for LED 3, Slot 2 */ + HYPERX_REG_SLOT2_LED3_BLUE = 0x7C, /* B color register for LED 3, Slot 2 */ + HYPERX_REG_SLOT2_LED4_RED = 0x7D, /* R color register for LED 4, Slot 2 */ + HYPERX_REG_SLOT2_LED4_GREEN = 0x7E, /* G color register for LED 4, Slot 2 */ + HYPERX_REG_SLOT2_LED4_BLUE = 0x7F, /* B color register for LED 4, Slot 2 */ + HYPERX_REG_SLOT2_LED0_BRIGHTNESS = 0x81, /* Brightness for LED 0, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED1_BRIGHTNESS = 0x84, /* Brightness for LED 1, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED2_BRIGHTNESS = 0x87, /* Brightness for LED 2, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED3_BRIGHTNESS = 0x8A, /* Brightness for LED 3, Slot 2 (0-100) */ + HYPERX_REG_SLOT2_LED4_BRIGHTNESS = 0x8D, /* 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_SLOT3_LED0_RED = 0xA1, /* R color register for LED 0, Slot 3 */ + HYPERX_REG_SLOT3_LED0_GREEN = 0xA2, /* G color register for LED 0, Slot 3 */ + HYPERX_REG_SLOT3_LED0_BLUE = 0xA3, /* B color register for LED 0, Slot 3 */ + HYPERX_REG_SLOT3_LED1_RED = 0xA4, /* R color register for LED 1, Slot 3 */ + HYPERX_REG_SLOT3_LED1_GREEN = 0xA5, /* G color register for LED 1, Slot 3 */ + HYPERX_REG_SLOT3_LED1_BLUE = 0xA6, /* B color register for LED 1, Slot 3 */ + HYPERX_REG_SLOT3_LED2_RED = 0xA7, /* R color register for LED 2, Slot 3 */ + HYPERX_REG_SLOT3_LED2_GREEN = 0xA8, /* G color register for LED 2, Slot 3 */ + HYPERX_REG_SLOT3_LED2_BLUE = 0xA9, /* B color register for LED 2, Slot 3 */ + HYPERX_REG_SLOT3_LED3_RED = 0xAA, /* R color register for LED 3, Slot 3 */ + HYPERX_REG_SLOT3_LED3_GREEN = 0xAB, /* G color register for LED 3, Slot 3 */ + HYPERX_REG_SLOT3_LED3_BLUE = 0xAC, /* B color register for LED 3, Slot 3 */ + HYPERX_REG_SLOT3_LED4_RED = 0xAD, /* R color register for LED 4, Slot 3 */ + HYPERX_REG_SLOT3_LED4_GREEN = 0xAE, /* G color register for LED 4, Slot 3 */ + HYPERX_REG_SLOT3_LED4_BLUE = 0xAF, /* B color register for LED 4, Slot 3 */ + HYPERX_REG_SLOT3_LED0_BRIGHTNESS = 0xB1, /* Brightness for LED 0, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED1_BRIGHTNESS = 0xB4, /* Brightness for LED 1, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED2_BRIGHTNESS = 0xB7, /* Brightness for LED 2, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED3_BRIGHTNESS = 0xBA, /* Brightness for LED 3, Slot 3 (0-100) */ + HYPERX_REG_SLOT3_LED4_BRIGHTNESS = 0xBD, /* 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 */ @@ -146,11 +146,18 @@ enum HYPERX_NUMBER_MODES /* Number of HyperX modes */ }; +static const unsigned char slot_base[4] = +{ + HYPERX_REG_SLOT0_LED0_RED, /* SPD 0x50 maps to slot 0 */ + HYPERX_REG_SLOT1_LED0_RED, /* SPD 0x51 maps to slot 1 */ + HYPERX_REG_SLOT2_LED0_RED, /* SPD 0x52 maps to slot 2 */ + HYPERX_REG_SLOT3_LED0_RED /* SPD 0x53 maps to slot 3 */ +}; class HyperXController { public: - HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev); + HyperXController(i2c_smbus_interface* bus, hyperx_dev_id dev, unsigned char slots); ~HyperXController(); std::string GetDeviceName(); @@ -161,11 +168,13 @@ public: void SetAllColors(unsigned char red, unsigned char green, unsigned char blue); void SetEffectColor(unsigned char red, unsigned char green, unsigned char blue); + void SetLEDColor(unsigned int led, 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; + unsigned char slots_valid; i2c_smbus_interface* bus; hyperx_dev_id dev; unsigned int mode; diff --git a/Controllers/HyperXController/HyperXControllerDetect.cpp b/Controllers/HyperXController/HyperXControllerDetect.cpp index 9e6f5e97..a3c1339f 100644 --- a/Controllers/HyperXController/HyperXControllerDetect.cpp +++ b/Controllers/HyperXController/HyperXControllerDetect.cpp @@ -6,6 +6,17 @@ #include #include +#ifdef WIN32 +#include +#else +#include + +void Sleep(unsigned int milliseconds) +{ + usleep(1000 * milliseconds); +} +#endif + /******************************************************************************************\ * * * TestForHyperXController * @@ -58,13 +69,34 @@ void DetectHyperXControllers(std::vector &busses, std::vec for (unsigned int bus = 0; bus < busses.size(); bus++) { + unsigned char slots_valid = 0x00; + // Check for HyperX controller at 0x27 if (TestForHyperXController(busses[bus], 0x27)) { - new_hyperx = new HyperXController(busses[bus], 0x27); - new_controller = new RGBController_HyperX(new_hyperx); - rgb_controllers.push_back(new_controller); + for(int slot_addr = 0x50; slot_addr <= 0x57; slot_addr++) + { + // Test for HyperX SPD at slot_addr + // This test was copied from NGENUITY software + // Tests SPD addresses in order: 0x40, 0x41, 0x68, and 0x67 + if((busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x40) == 0x01) + &&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x41) == 0x98) + &&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x68) == 0x10) + &&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x67) == 0x00)) + { + slots_valid |= (1 << (slot_addr - 0x50)); + } + + Sleep(1); + } + + if(slots_valid != 0) + { + new_hyperx = new HyperXController(busses[bus], 0x27, slots_valid); + new_controller = new RGBController_HyperX(new_hyperx); + rgb_controllers.push_back(new_controller); + } } } -} /* DetectHyperXControllers() */ \ No newline at end of file +} /* DetectHyperXControllers() */ diff --git a/RGBController/RGBController_HyperX.cpp b/RGBController/RGBController_HyperX.cpp index ad84935c..61b33f9f 100644 --- a/RGBController/RGBController_HyperX.cpp +++ b/RGBController/RGBController_HyperX.cpp @@ -53,7 +53,7 @@ void RGBController_HyperX::SetAllZoneLEDs(int zone, RGBColor color) { for (int y = 0; y < zones[zone].map[x].size(); y++) { - hyperx->SetLEDColor(0, zones[zone].map[x][y], red, grn, blu); + hyperx->SetLEDColor(zones[zone].map[x][y], red, grn, blu); } } } @@ -71,7 +71,7 @@ void RGBController_HyperX::SetLED(int led, RGBColor color) if(hyperx->GetMode() == HYPERX_MODE_DIRECT) { - hyperx->SetLEDColor(0, led, red, grn, blu); + hyperx->SetLEDColor(led, red, grn, blu); } else {