DMX Frame buffer
Both DMX_Master and DMX_Slave objects are using the DMX_FrameBuffer, this object allocates and manages the memory being used for storing data that needs to be sent or received.
Normally the DMX_Master or DMX_Slave creates this buffer internally for you based on the number of channels you supplied while initiating those objects.
No matter the less you can manipulate the buffer directly or instantiate your own and make the DMX_Master or DMX_Slave use your buffer instead.
Both DMX_Master and DMX_Slave implement the function: getBuffer (); , calling this function will return a reference to the buffer being used by either of those objects and allows you to access the slot data directly.
The following instruction will create a buffer consisting of 100 slots. be aware that the first slot no matter whether you are going to use it as a slave or master buffer will always keep the start byte. That being said will leave you with 99 slots which are used for channel 1-99
DMX_FrameBuffer my_buffer ( 100 );
DMX_FrameBuffer functions:
// Return the size of the buffer, if the buffer cannot allocate // the requested space it will be set to zero uint16_t getBufferSize ( void ); // Slot manipulation functions uint8_t getSlotValue ( uint16_t index ); void setSlotValue ( uint16_t index, uint8_t value ); void setSlotRange ( uint16_t start, uint16_t end, uint8_t value ); void clear ( void ); // access slots via the index operator uint8_t &operator[] ( uint16_t index );
NOTE: After initiating a DMX_FrameBuffer you should check the size of the buffer to verify the memory has really been allocated. If not enough memory is available the size will remain zero after instantiation
Minimum buffer size is 2 bytes/slots (1x start byte, 1x Channel)
While creating your DMX_Master or DMX_Slave object you can instead of giving it the number of channels pass it a reference to you buffer instead:
**DMX_Master dmx_master ( my_buffer, RXEN_PIN );
The master will derive its max channels from the buffer size directly which will be in this case 99 channels to transmit.
Same applies for the DMX slave:
DMX_Slave dmx_slave ( my_buffer );
Instead of getting and setting channels via you DMX_Master or DMX_Slave controller you can do it now directly on the buffer. This gives you the ability to implement the frame buffer in one of your other objects if you want to do so.
Copying behavior
If you make a copy of the buffer the internal memory buffer will be referenced instead if being copied,
in other words, copying a 100 byte buffer does not take another 100 bytes of memory.
for example:
DMX_FrameBuffer my_second_buffer ( my_buffer );
The internal allocated memory will be free(ed) automatically when all objects using it are deleted.