Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P
CircularBuf.h
- Committer:
- drechtmann3
- Date:
- 2018-04-29
- Revision:
- 38:a651c032e2b6
- Parent:
- 37:b146a0a0b894
- Child:
- 39:54441fa8756f
File content as of revision 38:a651c032e2b6:
#pragma once
// Simple "queue" type data structure
// Data is pushed onto the queue to add it to the FIFO buffer
// It is then popped off the queue to remove it from the FIFO buffer
// (It really should be enqueue and dequeue, but it's too late now)
//
// The circular buffer uses an array as the base and acts just like the name
// suggests
// You can push data on one side and remove from the other
// As you add and remove data, the location of the data "moves" around the circle
// https://en.wikipedia.org/wiki/Circular_buffer
/**
* Circular Buffer class.
*/
template <typename T>
class CircularBuf {
public:
// Argument:
//
/**
* @param size Size of the buffer.
* Assigns a circular buffer of the fiven size.
*/
CircularBuf(unsigned int size);
~CircularBuf();
/**
Pushes data onto the buffer
* @param data The array of data to add to the buffer.
* @param size The size of the array "data"
(Adds data to the buffer)
Arguement:/n
Data: The array of data to add to the buffer.
* @param size The size of the array "data"
* data, The array of data to add
* size, The amount of data in the array
* Return:
* Amount of data actually written
*
* Example Code:
*
* int dataToAdd[2];
* dataToAdd[0] = 15;
* dataToAdd[1] = 23;
* buffer.push(dataToAdd, 2);
*
* buffer now contains [15, 23]
*/
unsigned int push(T* data, unsigned int size);
/**
// Pops data from the buffer
// Arguement:
// data, The array of data popped
// size, The amount of data to pop
// Return:
// Amount of data actually popped
//
// Example Code:
//
// int dataToRemove[2];
// buffer.pop(dataToRemove, 2);
//
// dataToRemove now contains the 2 oldest values that were in buffer
*/
unsigned int pop(T* data, unsigned int size);
// Amount of data in the buffer
unsigned int size();
// Clears the buffer completely
void clear();
T* _data;
// Size of the array
unsigned int _size;
// Start pointer
unsigned int _head;
// End pointer
unsigned int _tail;
};