Fix some errors and increase the readability of some code

This commit is contained in:
Zhi Yan 2024-07-09 15:56:16 +00:00 committed by Adam Honse
parent 474b33fef4
commit 91b7c649c9
3 changed files with 18 additions and 13 deletions

View file

@ -49,15 +49,15 @@ void DRGBController::SetChannelLEDs(unsigned char /*channel*/, RGBColor* /*color
}
void DRGBController::SendPacket(unsigned char* colors, unsigned int buf_packets , unsigned int Array)
void DRGBController::SendPacket(unsigned char* colors, unsigned int buf_packets , unsigned int LEDtotal)
{
unsigned char usb_buf[1025];
unsigned int buf_idx = 0;
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x00] = 0x00;
unsigned int HigCount = Array / 256 >= 1 ? 1 : 0;
unsigned int LowCount = Array >= 316 ? 60 : (Array % 256) ;
Array = Array <= 316 ? 0 : (Array-316);
unsigned int HigCount = LEDtotal / 256 >= 1 ? 1 : 0;
unsigned int LowCount = LEDtotal >= DRGB_V4_ONE_PACKAGE_SIZE ? 60 : (LEDtotal % 256) ;
LEDtotal = LEDtotal <= DRGB_V4_ONE_PACKAGE_SIZE ? 0 : (LEDtotal-DRGB_V4_ONE_PACKAGE_SIZE);
for(unsigned int i = 0; i < buf_packets; i++)
{
usb_buf[1] = i + 100 ;
@ -70,11 +70,11 @@ void DRGBController::SendPacket(unsigned char* colors, unsigned int buf_packets
usb_buf[k+5] = colors[buf_idx + k];
}
hid_write(dev, usb_buf, 1025);
if(Array)
if(LEDtotal)
{
HigCount = Array / 256 >= 1 ? 1 : 0;
LowCount = Array >= 340 ? 84 : (Array % 256) ;
Array = Array <= 340 ? 0 : (Array-316);
HigCount = LEDtotal / 256 >= 1 ? 1 : 0;
LowCount = LEDtotal >= DRGB_V4_PACKAGE_SIZE ? 84 : (LEDtotal % 256) ;
LEDtotal = LEDtotal <= DRGB_V4_PACKAGE_SIZE ? 0 : (LEDtotal-DRGB_V4_PACKAGE_SIZE);
}
}
}

View file

@ -16,6 +16,11 @@
#include <hidapi/hidapi.h>
#include "RGBController.h"
#define DRGB_V4_ONE_PACKAGE_SIZE 316
#define DRGB_V4_PACKAGE_SIZE 340
#define DRGB_V3_PACKAGE_SIZE 21
#define DRGB_V2_PACKAGE_SIZE 20
class DRGBController
{
public:
@ -24,7 +29,7 @@ public:
std::string GetSerialString();
unsigned short GetDevicePID();
void SetChannelLEDs(unsigned char channel, RGBColor * colors, unsigned int num_colors);
void SendPacket(unsigned char* colors,unsigned int buf_packets ,unsigned int Array);
void SendPacket(unsigned char* colors,unsigned int buf_packets ,unsigned int LEDtotal);
void SendPacketFS(unsigned char* colors,unsigned int buf_packets ,bool Array);
private:
hid_device* dev;

View file

@ -299,9 +299,9 @@ void RGBController_DRGB::DeviceUpdateLEDs()
}
}
unsigned int col_packets = 1 ;
if(led_index > 316)
if(led_index > DRGB_V4_ONE_PACKAGE_SIZE)
{
col_packets = ((led_index - 316) / 340) + (((led_index - 316) % 340) > 0);
col_packets = 1 + ((led_index - DRGB_V4_ONE_PACKAGE_SIZE) / DRGB_V4_PACKAGE_SIZE) + (((led_index - DRGB_V4_ONE_PACKAGE_SIZE) % DRGB_V4_PACKAGE_SIZE) > 0);
}
controller->SendPacket(&RGBData[0], col_packets,led_index);
break;
@ -334,7 +334,7 @@ void RGBController_DRGB::DeviceUpdateLEDs()
break;
}
}
unsigned int col_packets = (led_index / 21) + ((led_index % 64) > 0);
unsigned int col_packets = (led_index / DRGB_V3_PACKAGE_SIZE) + ((led_index % DRGB_V3_PACKAGE_SIZE) > 0);
controller->SendPacketFS(&ArrayData[0], 1,0);
controller->SendPacketFS(&RGBData[0], col_packets,1);
break;
@ -353,7 +353,7 @@ void RGBController_DRGB::DeviceUpdateLEDs()
RGBData[i * 3 +1] = (RGBcolors >> 8) & 0xFF;
RGBData[i * 3 +2] = (RGBcolors >> 16) & 0xFF;
}
unsigned char NumPackets = (LEDnum / 20) + ((LEDnum % 20) > 0);
unsigned char NumPackets = LEDnum / DRGB_V2_PACKAGE_SIZE + ((LEDnum % DRGB_V2_PACKAGE_SIZE) > 0);
for (unsigned int CurrPacket = 1 ; CurrPacket <= NumPackets; CurrPacket++)
{
ArrayData[0] = CurrPacket;