From b7a0a3b4f77cd7db38cd496d66bf8515563b3e61 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 3 Aug 2021 00:15:05 +1000 Subject: [PATCH] Updating controller to allow 'Direct' mode for FW0012 + Adjusted setLedsDirect() for new protocol --- .../CMSmallARGBController.cpp | 67 ++++++++----------- .../CMSmallARGBController.h | 2 +- .../RGBController_CMSmallARGBController.cpp | 16 ++--- .../RGBController_CMSmallARGBController.h | 1 + 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/Controllers/CoolerMasterController/CMSmallARGBController.cpp b/Controllers/CoolerMasterController/CMSmallARGBController.cpp index 6e9d059b..f9df75f7 100644 --- a/Controllers/CoolerMasterController/CMSmallARGBController.cpp +++ b/Controllers/CoolerMasterController/CMSmallARGBController.cpp @@ -148,38 +148,34 @@ void CMSmallARGBController::SetMode(unsigned char mode, unsigned char speed, uns SendUpdate(); } -void CMSmallARGBController::SetLedsDirect(RGBColor* /*led_colours*/, unsigned int /*led_count*/) +void CMSmallARGBController::SetLedsDirect(RGBColor* led_colours, unsigned int led_count) { - // Mode not yet Tested - /* - const unsigned char buffer_size = 0x41; - unsigned char buffer[buffer_size] = { 0x00 }; - unsigned char packet_count = 0x00; - std::vector colours; + const unsigned char buffer_size = CM_SMALL_ARGB_PACKET_SIZE; + unsigned char buffer[buffer_size] = { 0x00, 0x00, 0x10, 0x02 }; + unsigned char packet_count = 0; + std::vector colours; - //Set up the RGB triplets to send - for(int i = 0; i < led_count; i++) + /*---------------------------------------------*\ + | Set up the RGB triplets to send | + \*---------------------------------------------*/ + for(unsigned int i = 0; i < led_count; i++) { RGBColor colour = led_colours[i]; - unsigned char r = RGBGetRValue(colour); - unsigned char g = RGBGetGValue(colour); - unsigned char b = RGBGetBValue(colour); - colours.push_back(r); - colours.push_back(g); - colours.push_back(b); + colours.push_back( RGBGetRValue(colour) ); + colours.push_back( RGBGetGValue(colour) ); + colours.push_back( RGBGetBValue(colour) ); } - //buffer[CM_ARGB_REPORT_BYTE] = packet_count; - buffer[CM_SMALL_ARGB_COMMAND_BYTE] = 0x10; - buffer[CM_SMALL_ARGB_FUNCTION_BYTE] = 0x02; - buffer[CM_SMALL_ARGB_ZONE_BYTE] = small_argb_header_data[zone_index].header; - buffer[CM_SMALL_ARGB_MODE_BYTE] = 0x30; //30 might be the LED count?? - unsigned char buffer_idx = CM_SMALL_ARGB_MODE_BYTE + 1; //Start colour info from + buffer[CM_SMALL_ARGB_ZONE_BYTE] = zone_index - 1; //argb_header_data[zone_index].header; + buffer[CM_SMALL_ARGB_MODE_BYTE] = led_count; + unsigned char buffer_idx = CM_SMALL_ARGB_MODE_BYTE + 1; - for (std::vector::iterator it = colours.begin(); it != colours.end(); buffer_idx = 0) + for(std::vector::iterator it = colours.begin(); it != colours.end(); buffer_idx = CM_SMALL_ARGB_COMMAND_BYTE) { - //Fill the write buffer till its full or the colour buffer is empty + /*-----------------------------------------------------------------*\ + | Fill the write buffer till its full or the colour buffer is empty | + \*-----------------------------------------------------------------*/ buffer[CM_SMALL_ARGB_REPORT_BYTE] = packet_count; while (( buffer_idx < buffer_size) && ( it != colours.end() )) { @@ -188,24 +184,19 @@ void CMSmallARGBController::SetLedsDirect(RGBColor* /*led_colours*/, unsigned in it++; } - hid_write(dev, buffer, buffer_size); - hid_read_timeout(dev, buffer, buffer_size, CM_SMALL_ARGB_INTERRUPT_TIMEOUT); + if(it == colours.end()) + { + buffer[CM_SMALL_ARGB_REPORT_BYTE] += 0x80; + } - //reset the write buffer - memset(buffer, 0x00, sizeof(buffer) ); + hid_write(dev, buffer, buffer_size); + + /*-----------------------------------------------------------------*\ + | Reset the write buffer | + \*-----------------------------------------------------------------*/ + memset(buffer, 0x00, buffer_size ); packet_count++; } - buffer[CM_SMALL_ARGB_REPORT_BYTE] = 0x82; - buffer[CM_SMALL_ARGB_COMMAND_BYTE] = 0x62; - buffer[CM_SMALL_ARGB_FUNCTION_BYTE] = 0x00; - buffer[CM_SMALL_ARGB_ZONE_BYTE] = 0x73; - buffer[CM_SMALL_ARGB_MODE_BYTE] = 0x00; - buffer[CM_SMALL_ARGB_SPEED_BYTE] = 0x33; - buffer[CM_SMALL_ARGB_COLOUR_INDEX_BYTE] = 0x18; - - hid_write(dev, buffer, buffer_size); - hid_read_timeout(dev, buffer, buffer_size, CM_SMALL_ARGB_INTERRUPT_TIMEOUT); - */ } void CMSmallARGBController::SendUpdate() diff --git a/Controllers/CoolerMasterController/CMSmallARGBController.h b/Controllers/CoolerMasterController/CMSmallARGBController.h index 98796b8b..99376675 100644 --- a/Controllers/CoolerMasterController/CMSmallARGBController.h +++ b/Controllers/CoolerMasterController/CMSmallARGBController.h @@ -16,7 +16,7 @@ #pragma once -#define CM_SMALL_ARGB_PACKET_SIZE 65 +#define CM_SMALL_ARGB_PACKET_SIZE 65 #define CM_SMALL_ARGB_INTERRUPT_TIMEOUT 250 enum diff --git a/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.cpp b/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.cpp index b8c44fe0..cc6314ab 100644 --- a/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.cpp +++ b/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.cpp @@ -18,7 +18,7 @@ RGBController_CMSmallARGBController::RGBController_CMSmallARGBController(CMSmall vendor = "Cooler Master"; type = DEVICE_TYPE_LEDSTRIP; description = cmargb->GetDeviceName(); - version = "1.0"; + version = "2.0 for FW0012"; serial = cmargb->GetSerial(); location = cmargb->GetLocation(); @@ -245,17 +245,17 @@ void RGBController_CMSmallARGBController::DeviceUpdateLEDs() } } -void RGBController_CMSmallARGBController::UpdateZoneLEDs(int /*zone*/) +void RGBController_CMSmallARGBController::UpdateZoneLEDs(int zone) { - //bool random_colours = (modes[active_mode].color_mode == MODE_COLORS_RANDOM); - - //cmargb->SetLedsDirect(zones[zone].colors, random_colours); + if(serial >= CM_SMALL_ARGB_FW0012) + { + cmargb->SetLedsDirect( zones[zone].colors, zones[zone].leds_count ); + } } -void RGBController_CMSmallARGBController::UpdateSingleLED(int /*led*/) +void RGBController_CMSmallARGBController::UpdateSingleLED(int led) { - //cmargb->SetMode( modes[active_mode].value, modes[active_mode].speed ); - //cmargb->SetLedsDirect( zones[0].colors, zones[0].leds_count ); + UpdateZoneLEDs(led); } void RGBController_CMSmallARGBController::SetCustomMode() diff --git a/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.h b/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.h index 2507772e..dadffbf8 100644 --- a/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.h +++ b/Controllers/CoolerMasterController/RGBController_CMSmallARGBController.h @@ -15,6 +15,7 @@ #define CM_SMALL_ARGB_MIN_LEDS 4 #define CM_SMALL_ARGB_MAX_LEDS 48 #define CM_SMALL_ARGB_BRIGHTNESS_MAX 0xFF +#define CM_SMALL_ARGB_FW0012 "A202104052336" class RGBController_CMSmallARGBController : public RGBController {