Skip to content

Commit e634a77

Browse files
Add LED alternate names field to SDK protocol
1 parent 1d9779d commit e634a77

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

RGBController/RGBController.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
145145
unsigned short num_zones = (unsigned short)zones.size();
146146
unsigned short num_leds = (unsigned short)leds.size();
147147
unsigned short num_colors = (unsigned short)colors.size();
148+
unsigned short num_led_alt_names= (unsigned short)led_alt_names.size();
148149

149150
unsigned short *mode_name_len = new unsigned short[num_modes];
150151
unsigned short *zone_name_len = new unsigned short[num_zones];
@@ -267,6 +268,26 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
267268
data_size += sizeof(leds[led_index].value);
268269
}
269270

271+
/*---------------------------------------------------------*\
272+
| LED alternate names |
273+
\*---------------------------------------------------------*/
274+
if(protocol_version >= 5)
275+
{
276+
/*-----------------------------------------------------*\
277+
| Number of LED alternate names |
278+
\*-----------------------------------------------------*/
279+
data_size += sizeof(num_led_alt_names);
280+
281+
/*-----------------------------------------------------*\
282+
| LED alternate name strings |
283+
\*-----------------------------------------------------*/
284+
for(int led_idx = 0; led_idx < led_alt_names.size(); led_idx++)
285+
{
286+
data_size += sizeof(unsigned short);
287+
data_size += strlen(led_alt_names[led_idx].c_str()) + 1;
288+
}
289+
}
290+
270291
data_size += sizeof(num_colors);
271292
data_size += num_colors * sizeof(RGBColor);
272293

@@ -684,6 +705,32 @@ unsigned char * RGBController::GetDeviceDescription(unsigned int protocol_versio
684705
data_ptr += sizeof(colors[color_index]);
685706
}
686707

708+
/*---------------------------------------------------------*\
709+
| LED alternate names data |
710+
\*---------------------------------------------------------*/
711+
if(protocol_version >= 5)
712+
{
713+
/*---------------------------------------------------------*\
714+
| Number of LED alternate name strings |
715+
\*---------------------------------------------------------*/
716+
memcpy(&data_buf[data_ptr], &num_led_alt_names, sizeof(num_led_alt_names));
717+
data_ptr += sizeof(num_led_alt_names);
718+
719+
for(int led_idx = 0; led_idx < led_alt_names.size(); led_idx++)
720+
{
721+
/*---------------------------------------------------------*\
722+
| Copy in LED alternate name (size+data) |
723+
\*---------------------------------------------------------*/
724+
unsigned short string_length = strlen(led_alt_names[led_idx].c_str()) + 1;
725+
726+
memcpy(&data_buf[data_ptr], &string_length, sizeof(string_length));
727+
data_ptr += sizeof(string_length);
728+
729+
strcpy((char *)&data_buf[data_ptr], led_alt_names[led_idx].c_str());
730+
data_ptr += string_length;
731+
}
732+
}
733+
687734
delete[] mode_name_len;
688735
delete[] zone_name_len;
689736
delete[] led_name_len;
@@ -1113,6 +1160,34 @@ void RGBController::ReadDeviceDescription(unsigned char* data_buf, unsigned int
11131160
colors.push_back(new_color);
11141161
}
11151162

1163+
/*---------------------------------------------------------*\
1164+
| Copy in LED alternate names data |
1165+
\*---------------------------------------------------------*/
1166+
if(protocol_version >= 5)
1167+
{
1168+
/*---------------------------------------------------------*\
1169+
| Copy in number of LED alternate names |
1170+
\*---------------------------------------------------------*/
1171+
unsigned short num_led_alt_names;
1172+
1173+
memcpy(&num_led_alt_names, &data_buf[data_ptr], sizeof(num_led_alt_names));
1174+
data_ptr += sizeof(num_led_alt_names);
1175+
1176+
for(int led_idx = 0; led_idx < num_led_alt_names; led_idx++)
1177+
{
1178+
unsigned short string_length = 0;
1179+
1180+
/*---------------------------------------------------------*\
1181+
| Copy in LED alternate name string (size+data) |
1182+
\*---------------------------------------------------------*/
1183+
memcpy(&string_length, &data_buf[data_ptr], sizeof(string_length));
1184+
data_ptr += sizeof(string_length);
1185+
1186+
led_alt_names.push_back((char *)&data_buf[data_ptr]);
1187+
data_ptr += string_length;
1188+
}
1189+
}
1190+
11161191
/*---------------------------------------------------------*\
11171192
| Setup colors |
11181193
\*---------------------------------------------------------*/

0 commit comments

Comments
 (0)