diff --git a/Controllers/HyperXDRAMController/HyperXDRAMController.cpp b/Controllers/HyperXDRAMController/HyperXDRAMController.cpp index dfabbf2d..00629b89 100644 --- a/Controllers/HyperXDRAMController/HyperXDRAMController.cpp +++ b/Controllers/HyperXDRAMController/HyperXDRAMController.cpp @@ -97,8 +97,10 @@ void HyperXDRAMController::SetAllColors(unsigned char red, unsigned char green, | Loop through all slots and only set those which are | | active. | \*-----------------------------------------------------*/ - for(int slot = 0; slot < 4; slot++) + for(unsigned int slot_idx = 0; slot_idx < 4; slot_idx++) { + unsigned char slot = slot_map[slot_idx]; + if((slots_valid & (1 << slot)) != 0) { unsigned char base = slot_base[slot]; @@ -136,7 +138,7 @@ void HyperXDRAMController::SetLEDColor(unsigned int led, unsigned char red, unsi \*-----------------------------------------------------*/ int led_slot = led / 5; int slot_id = -1; - int slot; + unsigned char slot; led -= (led_slot * 5); @@ -144,8 +146,10 @@ void HyperXDRAMController::SetLEDColor(unsigned int led, unsigned char red, unsi | Loop through all possible slots and only count those | | which are active. | \*-----------------------------------------------------*/ - for(slot = 0; slot < 4; slot++) + for(unsigned int slot_idx = 0; slot_idx < 4; slot_idx++) { + slot = slot_map[slot_idx]; + if((slots_valid & ( 1 << slot)) != 0) { slot_id++; @@ -157,21 +161,7 @@ void HyperXDRAMController::SetLEDColor(unsigned int led, unsigned char red, unsi } } - 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); + SetLEDColor(slot, led, red, green, blue); } diff --git a/Controllers/HyperXDRAMController/HyperXDRAMController.h b/Controllers/HyperXDRAMController/HyperXDRAMController.h index 1a9a2d23..3792fbe3 100644 --- a/Controllers/HyperXDRAMController/HyperXDRAMController.h +++ b/Controllers/HyperXDRAMController/HyperXDRAMController.h @@ -188,11 +188,19 @@ enum static const unsigned char slot_base[4] = { HYPERX_REG_SLOT0_LED0_RED, /* SPD 0x50 maps to slot 0 */ - HYPERX_REG_SLOT2_LED0_RED, /* SPD 0x51 maps to slot 2 */ HYPERX_REG_SLOT1_LED0_RED, /* SPD 0x52 maps to slot 1 */ + HYPERX_REG_SLOT2_LED0_RED, /* SPD 0x51 maps to slot 2 */ HYPERX_REG_SLOT3_LED0_RED /* SPD 0x53 maps to slot 3 */ }; +static const unsigned char slot_map[4] = +{ + 0, + 2, + 1, + 3 +}; + class HyperXDRAMController { public: