mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-05-15 18:14:44 -04:00
Some code cleanup - set colors vector size for improved performance and add sleep to fix Hue Plus device update
This commit is contained in:
@@ -48,30 +48,29 @@ char* HuePlusController::GetLEDString()
|
||||
|
||||
unsigned int HuePlusController::GetStripsOnChannel(unsigned int channel)
|
||||
{
|
||||
unsigned char serial_buf[] =
|
||||
{
|
||||
0x8D, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
unsigned int ret_val = 0;
|
||||
|
||||
if (serialport != NULL)
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x01] = channel;
|
||||
|
||||
serialport->serial_flush_rx();
|
||||
serialport->serial_write((char *)serial_buf, 2);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
Sleep(50);
|
||||
|
||||
int bytes_read = serialport->serial_read((char *)serial_buf, 5);
|
||||
|
||||
if(bytes_read == 5)
|
||||
{
|
||||
unsigned char *serial_buf;
|
||||
serial_buf = new unsigned char[5];
|
||||
|
||||
serial_buf[0] = 0x8D;
|
||||
serial_buf[1] = channel;
|
||||
|
||||
serialport->serial_flush_rx();
|
||||
serialport->serial_write((char *)serial_buf, 2);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
Sleep(50);
|
||||
|
||||
int bytes_read = serialport->serial_read((char *)serial_buf, 5);
|
||||
|
||||
if(bytes_read == 5)
|
||||
{
|
||||
ret_val = serial_buf[4];
|
||||
}
|
||||
|
||||
delete[] serial_buf;
|
||||
ret_val = serial_buf[4];
|
||||
}
|
||||
|
||||
return(ret_val);
|
||||
@@ -114,7 +113,6 @@ void HuePlusController::SetChannelEffect(unsigned int channel, unsigned int mode
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00
|
||||
};
|
||||
int actual = 0;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in serial packet |
|
||||
@@ -140,40 +138,72 @@ void HuePlusController::SetChannelEffect(unsigned int channel, unsigned int mode
|
||||
|
||||
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
void HuePlusController::SetChannelLEDs(unsigned int channel, std::vector<RGBColor> colors)
|
||||
{
|
||||
if (serialport != NULL)
|
||||
unsigned char serial_buf[] =
|
||||
{
|
||||
unsigned char *serial_buf;
|
||||
0x4B, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00
|
||||
};
|
||||
|
||||
serial_buf = new unsigned char[HUE_PLUS_PACKET_SIZE];
|
||||
/*-----------------------------------------------------*\
|
||||
| Set channel in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x01] = channel;
|
||||
|
||||
serial_buf[0] = 0x4B;
|
||||
serial_buf[1] = channel;
|
||||
serial_buf[2] = HUE_PLUS_MODE_FIXED;
|
||||
serial_buf[3] = 0x00;
|
||||
serial_buf[4] = 0x00;
|
||||
/*-----------------------------------------------------*\
|
||||
| Set mode in serial packet |
|
||||
\*-----------------------------------------------------*/
|
||||
serial_buf[0x02] = HUE_PLUS_MODE_FIXED;
|
||||
|
||||
for (int i = 5; i < HUE_PLUS_PACKET_SIZE; i++)
|
||||
{
|
||||
serial_buf[i] = 0x00;
|
||||
}
|
||||
|
||||
for (unsigned int idx = 0; idx < (colors.size() * 3); idx += 3)
|
||||
{
|
||||
int pixel_idx = idx / 3;
|
||||
RGBColor color = colors[pixel_idx];
|
||||
serial_buf[idx + 5] = RGBGetGValue(color);
|
||||
serial_buf[idx + 6] = RGBGetRValue(color);
|
||||
serial_buf[idx + 7] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
delete[] serial_buf;
|
||||
/*-----------------------------------------------------*\
|
||||
| Fill in color data |
|
||||
\*-----------------------------------------------------*/
|
||||
for (unsigned int idx = 0; idx < (colors.size() * 3); idx += 3)
|
||||
{
|
||||
int pixel_idx = idx / 3;
|
||||
RGBColor color = colors[pixel_idx];
|
||||
serial_buf[idx + 5] = RGBGetGValue(color);
|
||||
serial_buf[idx + 6] = RGBGetRValue(color);
|
||||
serial_buf[idx + 7] = RGBGetBValue(color);
|
||||
}
|
||||
|
||||
serialport->serial_write((char *)serial_buf, HUE_PLUS_PACKET_SIZE);
|
||||
serialport->serial_flush_tx();
|
||||
|
||||
Sleep(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user