![]() |
kBuffer
1.1
|
A ringbuffer consists of variables, which can be accessed in a continuous way.
You have to define, which datatype you want to have the elements.
By default, the elements are unsigned 16bit integers (uint16_t).
You can change the datatype by defining it. This definition must be before the inclusion of th kBuffer.h header file
Instead of uint16_t, you can insert (almost) any datatype you want.
At first, you have to include the kBuffer library into your project. This can be done by copying the files from src/kBuffer to your project's directory. You can include the header as usual:
In your code, you have to define an instance of buffer_t. You have to init this instance with the function bufferInit(). If you want to have a ringbuffer with 8 elements:
To check, if the initialization was successfull, you need to parse the return value of bufferInit():
If you want to avoid the memory overhead of the dynamic memory allocation of the malloc() function you could use the bufferInitStatic() function.
To write data to the buffer, you can use the bufferWrite() function:
To read data from the buffer, you can use the bufferRead() function: