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
00001 #pragma once 00002 // Simple "queue" type data structure 00003 // Data is pushed onto the queue to add it to the FIFO buffer 00004 // It is then popped off the queue to remove it from the FIFO buffer 00005 // (It really should be enqueue and dequeue, but it's too late now) 00006 // 00007 // The circular buffer uses an array as the base and acts just like the name 00008 // suggests 00009 // You can push data on one side and remove from the other 00010 // As you add and remove data, the location of the data "moves" around the circle 00011 // https://en.wikipedia.org/wiki/Circular_buffer 00012 /** 00013 * Circular Buffer class. 00014 */ 00015 template <typename T> 00016 class CircularBuf { 00017 public: 00018 /** 00019 * Assigns a circular buffer of the given size. 00020 * @param size Size of the buffer. 00021 */ 00022 CircularBuf(unsigned int size); 00023 ~CircularBuf(); 00024 /** 00025 * Pushes data onto the buffer. Returns the amount of data actually written. 00026 * @param Data The array of data to add to the buffer 00027 * @param size The amount of data in the array. 00028 00029 * (Adds data to the buffer) 00030 * Argument:/n 00031 * Data: The array of data to add to the buffer. 00032 * data: The array of data to add 00033 * size: The amount of data in the array 00034 * Return: 00035 * Amount of data actually written 00036 * 00037 * Example Code: 00038 * 00039 * int dataToAdd[2]; 00040 * dataToAdd[0] = 15; 00041 * dataToAdd[1] = 23; 00042 * buffer.push(dataToAdd, 2); 00043 * 00044 * buffer now contains [15, 23] 00045 */ 00046 unsigned int push(T* data, unsigned int size); 00047 00048 /** 00049 * Pops data from the buffer 00050 * @param data The array of data popped 00051 * @param size The amount of data to pop 00052 * Return: 00053 * Amount of data actually popped 00054 * 00055 * Example Code: 00056 * 00057 * int dataToRemove[2]; 00058 * buffer.pop(dataToRemove, 2); 00059 * 00060 * dataToRemove now contains the 2 oldest values that were in buffer 00061 */ 00062 unsigned int pop(T* data, unsigned int size); 00063 00064 // Amount of data in the buffer 00065 unsigned int size(); 00066 00067 // Clears the buffer completely 00068 void clear(); 00069 00070 T* _data; 00071 // Size of the array 00072 unsigned int _size; 00073 // Start pointer 00074 unsigned int _head; 00075 // End pointer 00076 unsigned int _tail; 00077 };
Generated on Tue Jul 12 2022 11:14:19 by
1.7.2