I am trying to write a LED strip driver in C ++. Now I have a class Stripand Driver; the class Stripabstracts an LED strip with several pixels, and the class Drivercombines the data Stripinto a single buffer for sending over a UDP connection.
Relevant partial classes:
class Strip {
public:
...
??? getPixelData();
int getPixelDataLength();
protected:
std::vector<unsigned char> mPixelData;
class Driver {
public:
...
void aggregateStrips();
protected:
vector<unsigned char> mBuffer;
serializerecords all pixel data with red-green blue in vector<unsigned char>. Then the driver calls Strip.getPixelData()to get the address mPixelDataand getPixelDataLength()to find out how many bytes are for memcpy().
aggregateStrips() does something like this:
int packetLength = 0;
for(auto strip : Strips) {
memcpy(&mBuffer[packetLength], strip->getPixelData(), strip->getPixelDataLength());
packetLength += strip.getPixelDataLength();
}
, getPixelData()? (shared_ptr?) ? , , ? ( ), memcpy .
!