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

Method SetLEDs

Controllers/BlinkyTapeController/BlinkyTapeController.cpp:62–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void BlinkyTapeController::SetLEDs(std::vector<RGBColor> colors)
63{
64 if(serialport == nullptr)
65 {
66 return;
67 }
68
69 /*-------------------------------------------------------------*\
70 | BlinkyTape Protocol |
71 | |
72 | Packet size: Number of data bytes + 1 |
73 | |
74 | 0-n: Data Byte (0-254) |
75 | n+1: Packet End Byte (0xFF) |
76 \*-------------------------------------------------------------*/
77 const unsigned int payload_size = (colors.size() * 3);
78 const unsigned int packet_size = payload_size + 1;
79
80 std::vector<unsigned char> serial_buf(packet_size);
81
82 /*-------------------------------------------------------------*\
83 | Set up end byte |
84 \*-------------------------------------------------------------*/
85 serial_buf[packet_size - 1] = 0xFF;
86
87 /*-------------------------------------------------------------*\
88 | Copy in color data in RGB order |
89 \*-------------------------------------------------------------*/
90 for(unsigned int color_idx = 0; color_idx < colors.size(); color_idx++)
91 {
92 const unsigned int color_offset = color_idx * 3;
93
94 serial_buf[0x00 + color_offset] = std::min((unsigned int)254, RGBGetRValue(colors[color_idx]));
95 serial_buf[0x01 + color_offset] = std::min((unsigned int)254, RGBGetGValue(colors[color_idx]));
96 serial_buf[0x02 + color_offset] = std::min((unsigned int)254, RGBGetBValue(colors[color_idx]));
97 }
98
99 /*-------------------------------------------------------------*\
100 | Send the packet |
101 \*-------------------------------------------------------------*/
102 serialport->serial_write((char *)serial_buf.data(), packet_size);
103}
104

Callers 3

DeviceUpdateLEDsMethod · 0.45
UpdateZoneLEDsMethod · 0.45
UpdateSingleLEDMethod · 0.45

Calls 3

serial_writeMethod · 0.80
dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected