ECE 4180 - Final Project Team / Mbed 2 deprecated WalkieTalkie

Dependencies:   mbed 4DGL-uLCD-SE mbed-rtos nRF24L01P

Committer:
drechtmann3
Date:
Sun Apr 29 15:26:52 2018 +0000
Revision:
37:b146a0a0b894
Parent:
36:c3cac3494e9b
Child:
38:a651c032e2b6
added class comment

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nurchu 20:e068469ffb89 1 #pragma once
Nurchu 20:e068469ffb89 2 // Simple "queue" type data structure
Nurchu 20:e068469ffb89 3 // Data is pushed onto the queue to add it to the FIFO buffer
Nurchu 20:e068469ffb89 4 // It is then popped off the queue to remove it from the FIFO buffer
Nurchu 20:e068469ffb89 5 // (It really should be enqueue and dequeue, but it's too late now)
Nurchu 20:e068469ffb89 6 //
Nurchu 20:e068469ffb89 7 // The circular buffer uses an array as the base and acts just like the name
Nurchu 20:e068469ffb89 8 // suggests
Nurchu 20:e068469ffb89 9 // You can push data on one side and remove from the other
Nurchu 20:e068469ffb89 10 // As you add and remove data, the location of the data "moves" around the circle
Nurchu 20:e068469ffb89 11 // https://en.wikipedia.org/wiki/Circular_buffer
drechtmann3 37:b146a0a0b894 12 /**
drechtmann3 37:b146a0a0b894 13 * Circular Buffer class.
drechtmann3 37:b146a0a0b894 14 */
Nurchu 20:e068469ffb89 15 template <typename T>
Nurchu 20:e068469ffb89 16 class CircularBuf {
Nurchu 14:4637a9f02919 17 public:
drechtmann3 35:99aa54a25a9e 18 // Argument:
drechtmann3 35:99aa54a25a9e 19 //
drechtmann3 35:99aa54a25a9e 20 /**
drechtmann3 35:99aa54a25a9e 21 * @param size Size of the buffer.
drechtmann3 36:c3cac3494e9b 22 * Assigns a circular buffer of the diven size.
drechtmann3 35:99aa54a25a9e 23 */
Nurchu 20:e068469ffb89 24 CircularBuf(unsigned int size);
Nurchu 20:e068469ffb89 25 ~CircularBuf();
drechtmann3 35:99aa54a25a9e 26 /**
drechtmann3 35:99aa54a25a9e 27 Pushes data onto the buffer
drechtmann3 35:99aa54a25a9e 28 (Adds data to the buffer)
Nurchu 14:4637a9f02919 29 // Arguement:
drechtmann3 35:99aa54a25a9e 30 * @param data The array of data to add to the buffer.
drechtmann3 35:99aa54a25a9e 31 * @param size The size of the array "data"
drechtmann3 36:c3cac3494e9b 32 * data, The array of data to add
drechtmann3 36:c3cac3494e9b 33 * size, The amount of data in the array
drechtmann3 36:c3cac3494e9b 34 * Return:
drechtmann3 36:c3cac3494e9b 35 * Amount of data actually written
drechtmann3 36:c3cac3494e9b 36 *
drechtmann3 36:c3cac3494e9b 37 * Example Code:
drechtmann3 36:c3cac3494e9b 38 *
drechtmann3 36:c3cac3494e9b 39 * int dataToAdd[2];
drechtmann3 36:c3cac3494e9b 40 * dataToAdd[0] = 15;
drechtmann3 36:c3cac3494e9b 41 * dataToAdd[1] = 23;
drechtmann3 36:c3cac3494e9b 42 * buffer.push(dataToAdd, 2);
drechtmann3 36:c3cac3494e9b 43 *
drechtmann3 36:c3cac3494e9b 44 * buffer now contains [15, 23]
drechtmann3 35:99aa54a25a9e 45 */
Nurchu 17:604f9c4bd6d3 46 unsigned int push(T* data, unsigned int size);
Nurchu 14:4637a9f02919 47
drechtmann3 35:99aa54a25a9e 48 /**
Nurchu 14:4637a9f02919 49 // Pops data from the buffer
Nurchu 14:4637a9f02919 50 // Arguement:
Nurchu 14:4637a9f02919 51 // data, The array of data popped
Nurchu 14:4637a9f02919 52 // size, The amount of data to pop
Nurchu 14:4637a9f02919 53 // Return:
Nurchu 14:4637a9f02919 54 // Amount of data actually popped
Nurchu 20:e068469ffb89 55 //
Nurchu 20:e068469ffb89 56 // Example Code:
Nurchu 20:e068469ffb89 57 //
Nurchu 20:e068469ffb89 58 // int dataToRemove[2];
Nurchu 20:e068469ffb89 59 // buffer.pop(dataToRemove, 2);
Nurchu 20:e068469ffb89 60 //
Nurchu 20:e068469ffb89 61 // dataToRemove now contains the 2 oldest values that were in buffer
drechtmann3 35:99aa54a25a9e 62 */
Nurchu 14:4637a9f02919 63 unsigned int pop(T* data, unsigned int size);
Nurchu 14:4637a9f02919 64
Nurchu 14:4637a9f02919 65 // Amount of data in the buffer
Nurchu 14:4637a9f02919 66 unsigned int size();
Nurchu 14:4637a9f02919 67
Nurchu 14:4637a9f02919 68 // Clears the buffer completely
Nurchu 14:4637a9f02919 69 void clear();
Nurchu 14:4637a9f02919 70
Nurchu 14:4637a9f02919 71 T* _data;
Nurchu 17:604f9c4bd6d3 72 // Size of the array
Nurchu 14:4637a9f02919 73 unsigned int _size;
Nurchu 17:604f9c4bd6d3 74 // Start pointer
Nurchu 17:604f9c4bd6d3 75 unsigned int _head;
Nurchu 17:604f9c4bd6d3 76 // End pointer
Nurchu 17:604f9c4bd6d3 77 unsigned int _tail;
Nurchu 14:4637a9f02919 78 };