MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / SetLEDsTPM2

Method SetLEDsTPM2

Controllers/LEDStripController/LEDStripController.cpp:307–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307void LEDStripController::SetLEDsTPM2(std::vector<RGBColor> colors)
308{
309 unsigned char *serial_buf;
310
311 /*-------------------------------------------------------------*\
312 | TPM2 Protocol |
313 | |
314 | Packet size: Number of data bytes + 5 |
315 | |
316 | 0: Packet Start Byte (0xC9) |
317 | 1: Packet Type (0xDA - Data, 0xC0 - Command, 0xAA - Read) |
318 | 2: Payload Size MSB |
319 | 3: Payload Size LSB |
320 | 4-n: Data Bytes |
321 | n+1: Packet End Byte (0x36) |
322 \*-------------------------------------------------------------*/
323 unsigned int payload_size = (colors.size() * 3);
324 unsigned int packet_size = payload_size + 5;
325
326 serial_buf = new unsigned char[packet_size];
327
328 /*-------------------------------------------------------------*\
329 | Set up header and end byte |
330 \*-------------------------------------------------------------*/
331 serial_buf[0x00] = 0xC9;
332 serial_buf[0x01] = 0xDA;
333 serial_buf[0x02] = (payload_size >> 8);
334 serial_buf[0x03] = (payload_size & 0xFF);
335 serial_buf[packet_size - 1] = 0x36;
336
337 /*-------------------------------------------------------------*\
338 | Copy in color data in RGB order |
339 \*-------------------------------------------------------------*/
340 for(unsigned int color_idx = 0; color_idx < colors.size(); color_idx++)
341 {
342 unsigned int color_offset = color_idx * 3;
343
344 serial_buf[0x04 + color_offset] = RGBGetRValue(colors[color_idx]);
345 serial_buf[0x05 + color_offset] = RGBGetGValue(colors[color_idx]);
346 serial_buf[0x06 + color_offset] = RGBGetBValue(colors[color_idx]);
347 }
348
349 /*-------------------------------------------------------------*\
350 | Send the packet |
351 \*-------------------------------------------------------------*/
352 if (serialport != NULL)
353 {
354 serialport->serial_write((char *)serial_buf, packet_size);
355 }
356
357 delete[] serial_buf;
358}
359
360void LEDStripController::SetLEDsBasicI2C(std::vector<RGBColor> colors)
361{

Callers

nothing calls this directly

Calls 2

serial_writeMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected