Updating controller to allow 'Direct' mode for FW0012

+ Adjusted setLedsDirect() for new protocol
This commit is contained in:
Chris 2021-08-03 00:15:05 +10:00 committed by Adam Honse
parent 3e6acbd049
commit b7a0a3b4f7
4 changed files with 39 additions and 47 deletions

View file

@ -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<unsigned char> 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<uint8_t> 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<unsigned char>::iterator it = colours.begin(); it != colours.end(); buffer_idx = 0)
for(std::vector<unsigned char>::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()

View file

@ -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

View file

@ -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()

View file

@ -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
{