diff --git a/Controllers/PolychromeController/PolychromeController.cpp b/Controllers/PolychromeController/PolychromeController.cpp index f0b562440..273350b09 100644 --- a/Controllers/PolychromeController/PolychromeController.cpp +++ b/Controllers/PolychromeController/PolychromeController.cpp @@ -19,16 +19,19 @@ PolychromeController::PolychromeController(i2c_smbus_interface* bus, polychrome_ { case FIRMWARE_VER_1_PT_10: led_count = 1; + asr_led = true; strcpy(device_name, "ASRock ASR LED FW 1.10"); break; case FIRMWARE_VER_2_PT_00: led_count = 1; + asr_led = false; strcpy(device_name, "ASRock Polychrome FW 2.00"); break; case FIRMWARE_VER_3_PT_00: led_count = 1; + asr_led = false; strcpy(device_name, "ASRock Polychrome FW 3.00"); break; } @@ -68,28 +71,40 @@ unsigned int PolychromeController::GetLEDCount() void PolychromeController::SetAllColors(unsigned char red, unsigned char green, unsigned char blue) { - unsigned char* colors = new unsigned char[led_count * 3]; - - for (int i = 0; i < (led_count * 3); i += 3) + if (asr_led) { - colors[i + 0] = red; - colors[i + 1] = blue; - colors[i + 2] = green; - } - delete colors; + } + else + { + unsigned char colors[3] = { red, green, blue }; + + bus->i2c_smbus_write_block_data(dev, POLYCHROME_REG_COLOR, 3, colors); + } } void PolychromeController::SetLEDColor(unsigned int led, unsigned char red, unsigned char green, unsigned char blue) { - unsigned char colors[3] = { red, blue, green }; + if (asr_led) + { + + } + else + { + unsigned char colors[3] = { red, green, blue }; + + bus->i2c_smbus_write_block_data(dev, POLYCHROME_REG_COLOR, 3, colors); + } } void PolychromeController::SetMode(unsigned char mode) { - // For ASR LED protocol - //placeholder// + if (asr_led) + { - // For Polychrome protocol - bus->i2c_smbus_write_byte_data(dev, POLYCHROME_REG_MODE, mode); + } + else + { + bus->i2c_smbus_write_byte_data(dev, POLYCHROME_REG_MODE, mode); + } } \ No newline at end of file diff --git a/Controllers/PolychromeController/PolychromeController.h b/Controllers/PolychromeController/PolychromeController.h index 87eeb1bd2..db9b73cda 100644 --- a/Controllers/PolychromeController/PolychromeController.h +++ b/Controllers/PolychromeController/PolychromeController.h @@ -27,6 +27,8 @@ enum ASRLED_REG_MODE = 0x30, /* Mode selection register */ }; +#define ASRLED_NUM_MODES 8 /* Number of ASR LED modes */ + enum { ASRLED_MODE_OFF = 0x10, /* OFF mode */ @@ -46,6 +48,8 @@ enum POLYCHROME_REG_COLOR = 0x34, /* Color register: Red, Green, Blue */ }; +#define POLYCHROME_NUM_MODES 14 /* Number of Polychrome modes */ + enum { POLYCHROME_MODE_OFF = 0x10, /* OFF mode */ @@ -78,6 +82,7 @@ public: unsigned short GetFirmwareVersion(); private: + bool asr_led; char device_name[32]; unsigned int led_count; i2c_smbus_interface* bus; diff --git a/RGBController/RGBController_Polychrome.cpp b/RGBController/RGBController_Polychrome.cpp new file mode 100644 index 000000000..a817965ca --- /dev/null +++ b/RGBController/RGBController_Polychrome.cpp @@ -0,0 +1,112 @@ +/*-----------------------------------------*\ +| RGBController_Polychrome.cpp | +| | +| Generic RGB Interface for OpenRGB | +| ASRock ASR LED and Polychrome RGB Driver | +| | +| Adam Honse (CalcProgrammer1) 12/15/2019 | +\*-----------------------------------------*/ + +#include "RGBController_Polychrome.h" + +int RGBController_Polychrome::GetMode() +{ + return(polychrome->GetMode()); +} + +void RGBController_Polychrome::SetMode(int mode) +{ + polychrome->SetMode(mode); +} + +void RGBController_Polychrome::SetCustomMode() +{ + polychrome->SetMode(POLYCHROME_MODE_STATIC); +} + +void RGBController_Polychrome::SetAllLEDs(RGBColor color) +{ + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + polychrome->SetAllColors(red, grn, blu); +} + +void RGBController_Polychrome::SetAllZoneLEDs(int zone, RGBColor color) +{ + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + polychrome->SetLEDColor(zone, red, grn, blu); +} + +void RGBController_Polychrome::SetLED(int led, RGBColor color) +{ + unsigned char red = RGBGetRValue(color); + unsigned char grn = RGBGetGValue(color); + unsigned char blu = RGBGetBValue(color); + + polychrome->SetLEDColor(led, red, grn, blu); +} + +void RGBController_Polychrome::UpdateLEDs() +{ + for (int led = 0; led < colors.size(); led++) + { + unsigned char red = RGBGetRValue(colors[led]); + unsigned char grn = RGBGetGValue(colors[led]); + unsigned char blu = RGBGetBValue(colors[led]); + + polychrome->SetLEDColor(led, red, grn, blu); + } +} + +static const char* polychrome_zone_names[] = +{ + "Motherboard" +}; + +RGBController_Polychrome::RGBController_Polychrome(PolychromeController* polychrome_ptr) +{ + polychrome = polychrome_ptr; + + name = polychrome->GetDeviceName(); + + mode polychrome_modes[POLYCHROME_NUM_MODES]; + + polychrome_modes[0].name = "Static"; + polychrome_modes[1].name = "Breathing"; + polychrome_modes[2].name = "Flashing"; + + for (int i = 0; i < POLYCHROME_NUM_MODES; i++) + { + modes.push_back(polychrome_modes[i]); + } + + // Search through all LEDs and create zones for each channel type + for (int i = 0; i < polychrome->GetLEDCount(); i++) + { + zone* new_zone = new zone(); + led* new_led = new led(); + + std::vector* zone_row = new std::vector(); + + // Set zone name to channel name + new_zone->name = polychrome_zone_names[i]; + new_led->name = polychrome_zone_names[i]; + + zone_row->push_back(i); + + // Aura devices can be either single or linear, never matrix + // That means only one row is needed + new_zone->map.push_back(*zone_row); + + // Push new LED to LEDs vector + leds.push_back(*new_led); + + // Push new zone to zones vector + zones.push_back(*new_zone); + } +} \ No newline at end of file diff --git a/RGBController/RGBController_Polychrome.h b/RGBController/RGBController_Polychrome.h new file mode 100644 index 000000000..1fc26ffca --- /dev/null +++ b/RGBController/RGBController_Polychrome.h @@ -0,0 +1,29 @@ +/*-----------------------------------------*\ +| RGBController_Polychrome.h | +| | +| Generic RGB Interface for OpenRGB | +| ASRock ASR LED and Polychrome RGB Driver | +| | +| Adam Honse (CalcProgrammer1) 12/15/2019 | +\*-----------------------------------------*/ + +#pragma once + +#include "RGBController.h" +#include "PolychromeController.h" + +class RGBController_Polychrome : public RGBController +{ +public: + RGBController_Polychrome(PolychromeController* polychrome_ptr); + int GetMode(); + void SetMode(int mode); + void SetCustomMode(); + void SetAllLEDs(RGBColor color); + void SetAllZoneLEDs(int zone, RGBColor color); + void SetLED(int led, RGBColor color); + void UpdateLEDs(); + +private: + PolychromeController* polychrome; +}; \ No newline at end of file