diff --git a/Controllers/CoolerMasterController/CMARGBcontroller.cpp b/Controllers/CoolerMasterController/CMARGBcontroller.cpp index 98750b1f..44a489fe 100644 --- a/Controllers/CoolerMasterController/CMARGBcontroller.cpp +++ b/Controllers/CoolerMasterController/CMARGBcontroller.cpp @@ -8,17 +8,8 @@ \*-------------------------------------------------------------------*/ #include "CMARGBcontroller.h" -#include -static unsigned char argb_colour_index_data[2][2][2] = -{ //B0 B1 - { { 0x00, 0x03 }, //G0 R0 - { 0x02, 0x06 }, }, //G1 R0 - { { 0x01, 0x05 }, //G0 R1 - { 0x04, 0x07 }, } //G1 R1 -}; - -CMARGBController::CMARGBController(hid_device* dev_handle, char *_path, unsigned char _zone_idx) +CMARGBController::CMARGBController(hid_device* dev_handle, char *_path, unsigned char _zone_idx, std::shared_ptr cm_mutex) { const int szTemp = 256; wchar_t tmpName[szTemp]; @@ -26,6 +17,7 @@ CMARGBController::CMARGBController(hid_device* dev_handle, char *_path, unsigned dev = dev_handle; location = _path; zone_index = _zone_idx; + mutex_ptr = cm_mutex; hid_get_manufacturer_string(dev, tmpName, szTemp); std::wstring wName = std::wstring(tmpName); @@ -66,6 +58,12 @@ void CMARGBController::GetStatus() rgb_offset = 1; } + /*---------------------------------------------*\ + | Guard the writes to the controller until the | + | for loop has completed to avoid collisons | + \*---------------------------------------------*/ + std::lock_guard guard(*mutex_ptr); + /*---------------------------------------------------------*\ | If this is the group then just return the first status | \*---------------------------------------------------------*/ @@ -132,38 +130,6 @@ bool CMARGBController::GetRandomColours() return bool_random; } -unsigned int CMARGBController::GetLargestColour(unsigned int red, unsigned int green, unsigned int blue) -{ - unsigned int largest; - if ( red > green ) - { - ( red > blue ) ? largest = red : largest = blue; - } - else - { - ( green > blue ) ? largest = green : largest = blue; - } - - return (largest == 0) ? 1 : largest; -} - -unsigned char CMARGBController::GetColourIndex(unsigned char red, unsigned char green, unsigned char blue) -{ - /*---------------------------------------------------------------------------------------------------------*\ - | The Cooler Master ARGB controller V0008 uses a limited colour pallette referenced by an index | - | Starting at 0x00 Random, 0x01 Red, 0x02 Green, 0x03 Blue, 0x04 Yellow, 0x05 Purple, 0x06 Cyan, 0x07 White | - | The index can be calculated by normalising the input colour, rounding those values | - | and using them as the indicies of a 3d array containing the correct index | - \*---------------------------------------------------------------------------------------------------------*/ - unsigned int divisor = GetLargestColour( red, green, blue); - unsigned int r = round( red / divisor ); - unsigned int g = round( green / divisor ); - unsigned int b = round( blue / divisor ); - unsigned char idx = argb_colour_index_data[r][g][b]; - - return idx; -} - void CMARGBController::SetLedCount(int zone, int led_count) { unsigned char buffer[CM_ARGB_PACKET_SIZE] = { 0x00, 0x80, 0x0D, 0x02 }; @@ -173,18 +139,24 @@ void CMARGBController::SetLedCount(int zone, int led_count) buffer[CM_ARGB_MODE_BYTE] = led_count; buffer[CM_ARGB_COLOUR_INDEX_BYTE] = (0x0F - led_count > 0) ? 0x0F - led_count : 0x01; + /*---------------------------------------------*\ + | Guard the writes to the controller until the | + | for loop has completed to avoid collisons | + \*---------------------------------------------*/ + std::lock_guard guard(*mutex_ptr); + hid_write(dev, buffer, buffer_size); } -void CMARGBController::SetMode(unsigned char mode, unsigned char speed, RGBColor colour, bool random_colours) +void CMARGBController::SetMode(uint8_t mode, uint8_t speed, uint8_t brightness, RGBColor colour, bool random_colours) { - bool needs_update = !( (current_mode == mode) && (current_speed == speed) && (current_brightness == 0xFF) && (ToRGBColor(current_red, current_green, current_blue) == colour)); + bool needs_update = !( (current_mode == mode) && (current_speed == speed) && (current_brightness == brightness) && (ToRGBColor(current_red, current_green, current_blue) == colour)); if (needs_update) { current_mode = mode; current_speed = speed; - current_brightness = 0xFF; + current_brightness = brightness; current_red = RGBGetRValue(colour); current_green = RGBGetGValue(colour); current_blue = RGBGetBValue(colour); @@ -197,9 +169,9 @@ void CMARGBController::SetMode(unsigned char mode, unsigned char speed, RGBColor void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_count) { const unsigned char buffer_size = CM_ARGB_PACKET_SIZE; - unsigned char buffer[buffer_size] = { 0x00, 0x10, 0x02 }; + unsigned char buffer[buffer_size] = { 0x00, 0x00, 0x07, 0x02 }; unsigned char packet_count = 0; - std::vector colours; + std::vector colours; /*---------------------------------------------*\ | Set up the RGB triplets to send | @@ -213,11 +185,17 @@ void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_cou colours.push_back( RGBGetBValue(colour) ); } - buffer[CM_ARGB_ZONE_BYTE] = argb_header_data[zone_index].header; - buffer[CM_ARGB_MODE_BYTE] = led_count; - unsigned char buffer_idx = CM_ARGB_MODE_BYTE + 1; + buffer[CM_ARGB_FUNCTION_BYTE] = zone_index - 1; + buffer[CM_ARGB_ZONE_BYTE] = led_count; + unsigned char buffer_idx = CM_ARGB_MODE_BYTE; - for(std::vector::iterator it = colours.begin(); it != colours.end(); buffer_idx = 0) + /*---------------------------------------------*\ + | Guard the writes to the controller until the | + | for loop has completed to avoid collisons | + \*---------------------------------------------*/ + std::lock_guard guard(*mutex_ptr); + + for(std::vector::iterator it = colours.begin(); it != colours.end(); buffer_idx = CM_ARGB_COMMAND_BYTE) { /*-----------------------------------------------------------------*\ | Fill the write buffer till its full or the colour buffer is empty | @@ -230,8 +208,12 @@ void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_cou it++; } + if(it == colours.end()) + { + buffer[CM_ARGB_REPORT_BYTE] += 0x80; + } + hid_write(dev, buffer, buffer_size); - hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); /*-----------------------------------------------------------------*\ | Reset the write buffer | @@ -239,21 +221,15 @@ void CMARGBController::SetLedsDirect(RGBColor *led_colours, unsigned int led_cou memset(buffer, 0x00, buffer_size ); packet_count++; } - - buffer[CM_ARGB_REPORT_BYTE] = 0x82; - /*buffer[CM_ARGB_COMMAND_BYTE] = 0x62; - buffer[CM_ARGB_FUNCTION_BYTE] = 0x00; - buffer[CM_ARGB_ZONE_BYTE] = 0x73; - buffer[CM_ARGB_MODE_BYTE] = 0x00; - buffer[CM_ARGB_COLOUR_INDEX_BYTE] = 0x33; - buffer[CM_ARGB_SPEED_BYTE] = 0x1B;*/ - - hid_write(dev, buffer, buffer_size); - hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); } void CMARGBController::SendUpdate() { + /*---------------------------------------------*\ + | Guard the writes to the controller | + \*---------------------------------------------*/ + std::lock_guard guard(*mutex_ptr); + unsigned char buffer[CM_ARGB_PACKET_SIZE] = { 0x00 }; int buffer_size = (sizeof(buffer) / sizeof(buffer[0])); bool boolARGB_header = argb_header_data[zone_index].digital; @@ -262,22 +238,29 @@ void CMARGBController::SendUpdate() unsigned char function = boolPassthru ? (boolARGB_header ? 0x02 : 0x04) : (boolARGB_header ? 0x01 : 0x03); buffer[CM_ARGB_REPORT_BYTE] = 0x80; buffer[CM_ARGB_COMMAND_BYTE] = 0x01; - buffer[CM_ARGB_FUNCTION_BYTE] = boolDirect ? 0x01 : function; + + if(boolDirect) + { + buffer[CM_ARGB_FUNCTION_BYTE] = 0x01; + buffer[CM_ARGB_ZONE_BYTE] = 0x02; + + hid_write(dev, buffer, buffer_size); + hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); + + /*-----------------------------------------------------------------*\ + | Direct mode is now set up and no other mode packet is required | + \*-----------------------------------------------------------------*/ + return; + } + + buffer[CM_ARGB_FUNCTION_BYTE] = function; hid_write(dev, buffer, buffer_size); hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); - /*-----------------------------------------------------------------*\ - | Direct mode is now set up and no other mode packet is required | - \*-----------------------------------------------------------------*/ - if(boolDirect) - { - return; - } - if(boolARGB_header) { - buffer[CM_ARGB_COMMAND_BYTE] = 0x0b; //ARGB sends 0x0b (1011) RGB sends 0x04 (0100) + buffer[CM_ARGB_COMMAND_BYTE] = 0x0B; //ARGB sends 0x0B (1011) RGB sends 0x04 (0100) buffer[CM_ARGB_FUNCTION_BYTE] = (false) ? 0x01 : 0x02; //This controls direct mode TODO buffer[CM_ARGB_ZONE_BYTE] = argb_header_data[zone_index].header; buffer[CM_ARGB_MODE_BYTE] = current_mode; @@ -287,9 +270,6 @@ void CMARGBController::SendUpdate() buffer[CM_ARGB_RED_BYTE] = current_red; buffer[CM_ARGB_GREEN_BYTE] = current_green; buffer[CM_ARGB_BLUE_BYTE] = current_blue; - - hid_write(dev, buffer, buffer_size); - hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); } else { @@ -301,8 +281,8 @@ void CMARGBController::SendUpdate() buffer[CM_ARGB_RED_BYTE + CM_RGB_OFFSET] = current_red; buffer[CM_ARGB_GREEN_BYTE + CM_RGB_OFFSET] = current_green; buffer[CM_ARGB_BLUE_BYTE + CM_RGB_OFFSET] = current_blue; - - hid_write(dev, buffer, buffer_size); - hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); } + + hid_write(dev, buffer, buffer_size); + hid_read_timeout(dev, buffer, buffer_size, CM_ARGB_INTERRUPT_TIMEOUT); } diff --git a/Controllers/CoolerMasterController/CMARGBcontroller.h b/Controllers/CoolerMasterController/CMARGBcontroller.h index 736a185a..4dedb7fc 100644 --- a/Controllers/CoolerMasterController/CMARGBcontroller.h +++ b/Controllers/CoolerMasterController/CMARGBcontroller.h @@ -10,8 +10,9 @@ \*-------------------------------------------------------------------*/ #include +#include #include -#include //Needed by round() +#include #include #include "RGBController.h" //Needed to set the direct mode @@ -25,6 +26,10 @@ #define CM_RGB_OFFSET -2 #define HID_MAX_STR 255 +#define CM_ARGB_BRIGHTNESS_MAX 255 +#define CM_ARGB_FW0023 std::string("A202011171238") +#define CM_ARGB_FW0028 std::string("A202105291658") + enum { CM_ARGB_REPORT_BYTE = 1, @@ -48,14 +53,14 @@ struct argb_headers unsigned int count; }; -static argb_headers argb_header_data[6] = +static argb_headers argb_header_data[] = { { "RGB Header", 0xFE, false, 1 }, { "Digital ARGB1", 0x01, true, 12 }, { "Digital ARGB2", 0x02, true, 12 }, { "Digital ARGB3", 0x04, true, 12 }, { "Digital ARGB4", 0x08, true, 12 }, - { "All Digital ARGB", 0xFF, true, 12 } + //{ "All Digital ARGB", 0xFF, true, 12 } }; enum @@ -96,7 +101,7 @@ enum class CMARGBController { public: - CMARGBController(hid_device* dev_handle, char *_path, unsigned char _zone_idx); + CMARGBController(hid_device* dev_handle, char *_path, unsigned char _zone_idx, std::shared_ptr cm_mutex); ~CMARGBController(); std::string GetDeviceName(); @@ -111,27 +116,26 @@ public: unsigned char GetLedSpeed(); bool GetRandomColours(); void SetLedCount(int zone, int led_count); - void SetMode(unsigned char mode, unsigned char speed, RGBColor colour, bool random_colours); + void SetMode(uint8_t mode, uint8_t speed, uint8_t brightness, RGBColor colour, bool random_colours); void SetLedsDirect(RGBColor * led_colours, unsigned int led_count); private: - std::string device_name; - std::string serial; - std::string location; - hid_device* dev; + std::string device_name; + std::string serial; + std::string location; + hid_device* dev; + std::shared_ptr mutex_ptr; - unsigned char zone_index; - unsigned char current_mode; - unsigned char current_speed; + unsigned char zone_index; + unsigned char current_mode; + unsigned char current_speed; - unsigned char current_red; - unsigned char current_green; - unsigned char current_blue; - unsigned char current_brightness; - bool bool_random; + unsigned char current_red; + unsigned char current_green; + unsigned char current_blue; + unsigned char current_brightness; + bool bool_random; - unsigned int GetLargestColour(unsigned int red, unsigned int green, unsigned int blue); - unsigned char GetColourIndex(unsigned char red, unsigned char green, unsigned char blue); void GetStatus(); void SendUpdate(); }; diff --git a/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp b/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp index 31047193..0281b1d7 100644 --- a/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp +++ b/Controllers/CoolerMasterController/CoolerMasterControllerDetect.cpp @@ -46,9 +46,15 @@ void DetectCoolerMasterARGB(hid_device_info* info, const std::string&) hid_device* dev = hid_open_path(info->path); if(dev) { + /*-------------------------------------------------*\ + | Create mutex to prevent the controllers sharing a | + | receiver from interfering with each other | + \*-------------------------------------------------*/ + std::shared_ptr cm_mutex = std::make_shared(); + for(std::size_t i = 0; i < CM_ARGB_HEADER_DATA_SIZE; i++) { - CMARGBController* controller = new CMARGBController(dev, info->path, i); + CMARGBController* controller = new CMARGBController(dev, info->path, i, cm_mutex); RGBController_CMARGBController* rgb_controller = new RGBController_CMARGBController(controller); // Constructor sets the name ResourceManager::get()->RegisterRGBController(rgb_controller); diff --git a/Controllers/CoolerMasterController/RGBController_CMARGBController.cpp b/Controllers/CoolerMasterController/RGBController_CMARGBController.cpp index 18bf9a81..ed001b22 100644 --- a/Controllers/CoolerMasterController/RGBController_CMARGBController.cpp +++ b/Controllers/CoolerMasterController/RGBController_CMARGBController.cpp @@ -11,206 +11,245 @@ RGBController_CMARGBController::RGBController_CMARGBController(CMARGBController *cmargb_ptr) { - cmargb = cmargb_ptr; - unsigned char speed = cmargb->GetLedSpeed(); + cmargb = cmargb_ptr; + unsigned char speed = cmargb->GetLedSpeed(); - name = argb_header_data[cmargb->GetZoneIndex()].name; - vendor = "Cooler Master"; - type = DEVICE_TYPE_LEDSTRIP; - description = cmargb->GetDeviceName(); - version = "2.0 for FW0023"; - serial = cmargb->GetSerial(); - location = cmargb->GetLocation(); + name = argb_header_data[cmargb->GetZoneIndex()].name; + vendor = "Cooler Master"; + type = DEVICE_TYPE_LEDSTRIP; + description = cmargb->GetDeviceName(); + version = "3.0 for FW0028"; + serial = cmargb->GetSerial(); + location = cmargb->GetLocation(); if(argb_header_data[cmargb->GetZoneIndex()].digital) { mode Off; - Off.name = "Turn Off"; - Off.value = CM_ARGB_MODE_OFF; - Off.color_mode = MODE_COLORS_NONE; + Off.name = "Turn Off"; + Off.value = CM_ARGB_MODE_OFF; + Off.color_mode = MODE_COLORS_NONE; modes.push_back(Off); mode Reload; - Reload.name = "Reload"; - Reload.value = CM_ARGB_MODE_RELOAD; - Reload.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Reload.colors_min = 1; - Reload.colors_max = 1; + Reload.name = "Reload"; + Reload.value = CM_ARGB_MODE_RELOAD; + Reload.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Reload.colors_min = 1; + Reload.colors_max = 1; Reload.colors.resize(Reload.colors_max); - Reload.speed_min = CM_ARGB_SPEED_SLOWEST; - Reload.speed_max = CM_ARGB_SPEED_FASTEST; - Reload.color_mode = MODE_COLORS_MODE_SPECIFIC; - Reload.speed = speed; + Reload.brightness_min = 0; + Reload.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Reload.brightness = CM_ARGB_BRIGHTNESS_MAX; + Reload.speed_min = CM_ARGB_SPEED_SLOWEST; + Reload.speed_max = CM_ARGB_SPEED_FASTEST; + Reload.color_mode = MODE_COLORS_MODE_SPECIFIC; + Reload.speed = speed; modes.push_back(Reload); mode Recoil; - Recoil.name = "Recoil"; - Recoil.value = CM_ARGB_MODE_RECOIL; - Recoil.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Recoil.colors_min = 1; - Recoil.colors_max = 1; + Recoil.name = "Recoil"; + Recoil.value = CM_ARGB_MODE_RECOIL; + Recoil.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Recoil.colors_min = 1; + Recoil.colors_max = 1; Recoil.colors.resize(Recoil.colors_max); - Recoil.speed_min = CM_ARGB_SPEED_SLOWEST; - Recoil.speed_max = CM_ARGB_SPEED_FASTEST; - Recoil.color_mode = MODE_COLORS_MODE_SPECIFIC; - Recoil.speed = speed; + Recoil.brightness_min = 0; + Recoil.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Recoil.brightness = CM_ARGB_BRIGHTNESS_MAX; + Recoil.speed_min = CM_ARGB_SPEED_SLOWEST; + Recoil.speed_max = CM_ARGB_SPEED_FASTEST; + Recoil.color_mode = MODE_COLORS_MODE_SPECIFIC; + Recoil.speed = speed; modes.push_back(Recoil); mode Breathing; - Breathing.name = "Breathing"; - Breathing.value = CM_ARGB_MODE_BREATHING; - Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Breathing.colors_min = 1; - Breathing.colors_max = 1; + Breathing.name = "Breathing"; + Breathing.value = CM_ARGB_MODE_BREATHING; + Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Breathing.colors_min = 1; + Breathing.colors_max = 1; Breathing.colors.resize(Breathing.colors_max); - Breathing.speed_min = CM_ARGB_SPEED_SLOWEST; - Breathing.speed_max = CM_ARGB_SPEED_FASTEST; - Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; - Breathing.speed = speed; + Breathing.brightness_min = 0; + Breathing.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Breathing.brightness = CM_ARGB_BRIGHTNESS_MAX; + Breathing.speed_min = CM_ARGB_SPEED_SLOWEST; + Breathing.speed_max = CM_ARGB_SPEED_FASTEST; + Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; + Breathing.speed = speed; modes.push_back(Breathing); mode Refill; - Refill.name = "Refill"; - Refill.value = CM_ARGB_MODE_REFILL; - Refill.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Refill.colors_min = 1; - Refill.colors_max = 1; + Refill.name = "Refill"; + Refill.value = CM_ARGB_MODE_REFILL; + Refill.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Refill.colors_min = 1; + Refill.colors_max = 1; Refill.colors.resize(Refill.colors_max); - Refill.speed_min = CM_ARGB_SPEED_SLOWEST; - Refill.speed_max = CM_ARGB_SPEED_FASTEST; - Refill.color_mode = MODE_COLORS_MODE_SPECIFIC; - Refill.speed = speed; + Refill.brightness_min = 0; + Refill.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Refill.brightness = CM_ARGB_BRIGHTNESS_MAX; + Refill.speed_min = CM_ARGB_SPEED_SLOWEST; + Refill.speed_max = CM_ARGB_SPEED_FASTEST; + Refill.color_mode = MODE_COLORS_MODE_SPECIFIC; + Refill.speed = speed; modes.push_back(Refill); mode Demo; - Demo.name = "Demo"; - Demo.value = CM_ARGB_MODE_DEMO; - Demo.flags = MODE_FLAG_HAS_SPEED; - Demo.speed_min = CM_ARGB_SPEED_SLOWEST; - Demo.speed_max = CM_ARGB_SPEED_FASTEST; - Demo.color_mode = MODE_COLORS_NONE; - Demo.speed = speed; + Demo.name = "Demo"; + Demo.value = CM_ARGB_MODE_DEMO; + Demo.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; + Demo.brightness_min = 0; + Demo.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Demo.brightness = CM_ARGB_BRIGHTNESS_MAX; + Demo.speed_min = CM_ARGB_SPEED_SLOWEST; + Demo.speed_max = CM_ARGB_SPEED_FASTEST; + Demo.color_mode = MODE_COLORS_NONE; + Demo.speed = speed; modes.push_back(Demo); mode Spectrum; - Spectrum.name = "Spectrum"; - Spectrum.value = CM_ARGB_MODE_SPECTRUM; - Spectrum.flags = MODE_FLAG_HAS_SPEED; - Spectrum.speed_min = CM_ARGB_SPEED_SLOWEST; - Spectrum.speed_max = CM_ARGB_SPEED_FASTEST; - Spectrum.color_mode = MODE_COLORS_NONE; - Spectrum.speed = speed; + Spectrum.name = "Spectrum"; + Spectrum.value = CM_ARGB_MODE_SPECTRUM; + Spectrum.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; + Spectrum.brightness_min = 0; + Spectrum.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Spectrum.brightness = CM_ARGB_BRIGHTNESS_MAX; + Spectrum.speed_min = CM_ARGB_SPEED_SLOWEST; + Spectrum.speed_max = CM_ARGB_SPEED_FASTEST; + Spectrum.color_mode = MODE_COLORS_NONE; + Spectrum.speed = speed; modes.push_back(Spectrum); mode FillFlow; - FillFlow.name = "Fill Flow"; - FillFlow.value = CM_ARGB_MODE_FILLFLOW; - FillFlow.flags = MODE_FLAG_HAS_SPEED; - FillFlow.speed_min = CM_ARGB_SPEED_SLOWEST; - FillFlow.speed_max = CM_ARGB_SPEED_FASTEST; - FillFlow.color_mode = MODE_COLORS_NONE; - FillFlow.speed = speed; + FillFlow.name = "Fill Flow"; + FillFlow.value = CM_ARGB_MODE_FILLFLOW; + FillFlow.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; + FillFlow.brightness_min = 0; + FillFlow.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + FillFlow.brightness = CM_ARGB_BRIGHTNESS_MAX; + FillFlow.speed_min = CM_ARGB_SPEED_SLOWEST; + FillFlow.speed_max = CM_ARGB_SPEED_FASTEST; + FillFlow.color_mode = MODE_COLORS_NONE; + FillFlow.speed = speed; modes.push_back(FillFlow); mode Rainbow; - Rainbow.name = "Rainbow"; - Rainbow.value = CM_ARGB_MODE_RAINBOW; - Rainbow.flags = MODE_FLAG_HAS_SPEED; - Rainbow.speed_min = CM_ARGB_SPEED_SLOWEST; - Rainbow.speed_max = CM_ARGB_SPEED_FASTEST; - Rainbow.color_mode = MODE_COLORS_NONE; - Rainbow.speed = speed; + Rainbow.name = "Rainbow"; + Rainbow.value = CM_ARGB_MODE_RAINBOW; + Rainbow.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_BRIGHTNESS; + Rainbow.brightness_min = 0; + Rainbow.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Rainbow.brightness = CM_ARGB_BRIGHTNESS_MAX; + Rainbow.speed_min = CM_ARGB_SPEED_SLOWEST; + Rainbow.speed_max = CM_ARGB_SPEED_FASTEST; + Rainbow.color_mode = MODE_COLORS_NONE; + Rainbow.speed = speed; modes.push_back(Rainbow); mode Static; - Static.name = "Static"; - Static.value = CM_ARGB_MODE_STATIC; - Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR; - Static.colors_min = 1; - Static.colors_max = 1; + Static.name = "Static"; + Static.value = CM_ARGB_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Static.colors_min = 1; + Static.colors_max = 1; Static.colors.resize(Static.colors_max); - Static.speed_min = CM_ARGB_SPEED_SLOWEST; - Static.speed_max = CM_ARGB_SPEED_FASTEST; - Static.color_mode = MODE_COLORS_MODE_SPECIFIC; - Static.speed = speed; + Static.brightness_min = 0; + Static.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Static.brightness = CM_ARGB_BRIGHTNESS_MAX; + Static.speed_min = CM_ARGB_SPEED_SLOWEST; + Static.speed_max = CM_ARGB_SPEED_FASTEST; + Static.color_mode = MODE_COLORS_MODE_SPECIFIC; + Static.speed = speed; modes.push_back(Static); mode Direct; - Direct.name = "Direct"; - Direct.value = CM_ARGB_MODE_DIRECT; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - Direct.color_mode = MODE_COLORS_PER_LED; + Direct.name = (serial >= CM_ARGB_FW0028) ? "Direct" : "Custom"; + Direct.value = CM_ARGB_MODE_DIRECT; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; modes.push_back(Direct); mode PassThru; - PassThru.name = "Pass Thru"; - PassThru.value = CM_ARGB_MODE_PASSTHRU; - PassThru.flags = 0; - PassThru.color_mode = MODE_COLORS_NONE; + PassThru.name = "Pass Thru"; + PassThru.value = CM_ARGB_MODE_PASSTHRU; + PassThru.flags = 0; + PassThru.color_mode = MODE_COLORS_NONE; modes.push_back(PassThru); } else { mode Static; - Static.name = "Static"; - Static.value = CM_RGB_MODE_STATIC; - Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR; - Static.colors_min = 1; - Static.colors_max = 1; + Static.name = "Static"; + Static.value = CM_RGB_MODE_STATIC; + Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Static.colors_min = 1; + Static.colors_max = 1; Static.colors.resize(Static.colors_max); - Static.color_mode = MODE_COLORS_MODE_SPECIFIC; - Static.speed = 0; + Static.brightness_min = 0; + Static.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Static.brightness = CM_ARGB_BRIGHTNESS_MAX; + Static.color_mode = MODE_COLORS_MODE_SPECIFIC; + Static.speed = 0; modes.push_back(Static); mode Breathing; - Breathing.name = "Breathing"; - Breathing.value = CM_RGB_MODE_BREATHING; - Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Breathing.colors_min = 1; - Breathing.colors_max = 1; + Breathing.name = "Breathing"; + Breathing.value = CM_RGB_MODE_BREATHING; + Breathing.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Breathing.colors_min = 1; + Breathing.colors_max = 1; Breathing.colors.resize(Breathing.colors_max); - Breathing.speed_min = CM_ARGB_SPEED_SLOWEST; - Breathing.speed_max = CM_ARGB_SPEED_FASTEST; - Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; - Breathing.speed = CM_ARGB_SPEED_NORMAL; + Breathing.brightness_min = 0; + Breathing.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Breathing.brightness = CM_ARGB_BRIGHTNESS_MAX; + Breathing.speed_min = CM_ARGB_SPEED_SLOWEST; + Breathing.speed_max = CM_ARGB_SPEED_FASTEST; + Breathing.color_mode = MODE_COLORS_MODE_SPECIFIC; + Breathing.speed = CM_ARGB_SPEED_NORMAL; modes.push_back(Breathing); mode Flash; - Flash.name = "Flash"; - Flash.value = CM_RGB_MODE_FLASH; - Flash.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Flash.colors_min = 1; - Flash.colors_max = 1; + Flash.name = "Flash"; + Flash.value = CM_RGB_MODE_FLASH; + Flash.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Flash.colors_min = 1; + Flash.colors_max = 1; Flash.colors.resize(Flash.colors_max); - Flash.speed_min = CM_ARGB_SPEED_SLOWEST; - Flash.speed_max = CM_ARGB_SPEED_FASTEST; - Flash.color_mode = MODE_COLORS_MODE_SPECIFIC; - Flash.speed = CM_ARGB_SPEED_NORMAL; + Flash.brightness_min = 0; + Flash.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Flash.brightness = CM_ARGB_BRIGHTNESS_MAX; + Flash.speed_min = CM_ARGB_SPEED_SLOWEST; + Flash.speed_max = CM_ARGB_SPEED_FASTEST; + Flash.color_mode = MODE_COLORS_MODE_SPECIFIC; + Flash.speed = CM_ARGB_SPEED_NORMAL; modes.push_back(Flash); mode Mirage; - Mirage.name = "Mirage"; - Mirage.value = CM_RGB_MODE_MIRAGE; - Mirage.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR; - Mirage.colors_min = 1; - Mirage.colors_max = 1; + Mirage.name = "Mirage"; + Mirage.value = CM_RGB_MODE_MIRAGE; + Mirage.flags = MODE_FLAG_HAS_SPEED | MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_RANDOM_COLOR | MODE_FLAG_HAS_BRIGHTNESS; + Mirage.colors_min = 1; + Mirage.colors_max = 1; Mirage.colors.resize(Mirage.colors_max); - Mirage.speed_min = CM_ARGB_SPEED_SLOWEST; - Mirage.speed_max = CM_ARGB_SPEED_FASTEST; - Mirage.color_mode = MODE_COLORS_MODE_SPECIFIC; - Mirage.speed = CM_ARGB_SPEED_NORMAL; + Mirage.brightness_min = 0; + Mirage.brightness_max = CM_ARGB_BRIGHTNESS_MAX; + Mirage.brightness = CM_ARGB_BRIGHTNESS_MAX; + Mirage.speed_min = CM_ARGB_SPEED_SLOWEST; + Mirage.speed_max = CM_ARGB_SPEED_FASTEST; + Mirage.color_mode = MODE_COLORS_MODE_SPECIFIC; + Mirage.speed = CM_ARGB_SPEED_NORMAL; modes.push_back(Mirage); mode PassThru; - PassThru.name = "Pass Thru"; - PassThru.value = CM_RGB_MODE_PASSTHRU; - PassThru.color_mode = MODE_COLORS_NONE; + PassThru.name = "Pass Thru"; + PassThru.value = CM_RGB_MODE_PASSTHRU; + PassThru.color_mode = MODE_COLORS_NONE; modes.push_back(PassThru); mode Off; - Off.name = "Turn Off"; - Off.value = CM_RGB_MODE_OFF; - Off.color_mode = MODE_COLORS_NONE; + Off.name = "Turn Off"; + Off.value = CM_RGB_MODE_OFF; + Off.color_mode = MODE_COLORS_NONE; modes.push_back(Off); } @@ -229,8 +268,8 @@ RGBController_CMARGBController::RGBController_CMARGBController(CMARGBController if (modes[active_mode].flags & MODE_FLAG_HAS_MODE_SPECIFIC_COLOR) { modes[active_mode].colors[0] = ToRGBColor(cmargb->GetLedRed(), cmargb->GetLedGreen(), cmargb->GetLedBlue()); + modes[active_mode].color_mode = (cmargb->GetRandomColours()) ? MODE_COLORS_RANDOM : MODE_COLORS_MODE_SPECIFIC; } - modes[active_mode].color_mode = (cmargb->GetRandomColours()) ? MODE_COLORS_RANDOM : MODE_COLORS_MODE_SPECIFIC; if (modes[active_mode].flags & MODE_FLAG_HAS_SPEED) { modes[active_mode].speed = cmargb->GetLedSpeed(); @@ -336,9 +375,9 @@ void RGBController_CMARGBController::DeviceUpdateLEDs() } } -void RGBController_CMARGBController::UpdateZoneLEDs(int /*zone*/) +void RGBController_CMARGBController::UpdateZoneLEDs(int zone) { - //cmargb->SetLedsDirect( zones[zone].colors, zones[zone].leds_count ); + cmargb->SetLedsDirect( zones[zone].colors, zones[zone].leds_count ); } void RGBController_CMARGBController::UpdateSingleLED(int led) @@ -363,7 +402,7 @@ void RGBController_CMARGBController::DeviceUpdateMode() bool random_colours = (modes[active_mode].color_mode == MODE_COLORS_RANDOM); RGBColor colour = (modes[active_mode].color_mode == MODE_COLORS_MODE_SPECIFIC) ? modes[active_mode].colors[0] : 0; - cmargb->SetMode( modes[active_mode].value, modes[active_mode].speed, colour, random_colours ); + cmargb->SetMode( modes[active_mode].value, modes[active_mode].speed, modes[active_mode].brightness, colour, random_colours ); } int RGBController_CMARGBController::GetLED_Zone(int led_idx)