2013-05-29 20:53:15 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2012-11-05 00:29:29 -04:00
|
|
|
|
|
|
|
/// @file AP_Buffer.h
|
|
|
|
/// @brief fifo buffer template class
|
|
|
|
|
2012-11-19 20:57:50 -04:00
|
|
|
#ifndef __AP_BUFFER_H__
|
|
|
|
#define __AP_BUFFER_H__
|
2012-11-05 00:29:29 -04:00
|
|
|
|
2012-11-19 20:57:50 -04:00
|
|
|
#include <stdint.h>
|
2012-11-05 00:29:29 -04:00
|
|
|
|
|
|
|
/// @class AP_Buffer
|
|
|
|
template <class T, uint8_t SIZE>
|
|
|
|
class AP_Buffer {
|
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
AP_Buffer();
|
|
|
|
|
|
|
|
// clear - removes all points from the curve
|
2013-04-21 07:56:08 -03:00
|
|
|
void clear();
|
2012-11-05 00:29:29 -04:00
|
|
|
|
|
|
|
// add - adds an item to the buffer. returns TRUE if successfully added
|
2013-04-21 09:24:46 -03:00
|
|
|
void add( T item );
|
2012-11-05 00:29:29 -04:00
|
|
|
|
|
|
|
// get - returns the next value in the buffer
|
2013-04-21 07:56:08 -03:00
|
|
|
T get();
|
2012-11-05 00:29:29 -04:00
|
|
|
|
|
|
|
// peek - check what the next value in the buffer is but don't pull it off
|
2013-04-21 07:56:08 -03:00
|
|
|
T peek(uint8_t position = 0) const;
|
2012-11-05 00:29:29 -04:00
|
|
|
|
|
|
|
// num_values - returns number of values in the buffer
|
2013-04-21 07:56:08 -03:00
|
|
|
uint8_t num_items() const { return _num_items; }
|
2012-11-05 00:29:29 -04:00
|
|
|
|
2013-04-21 07:56:08 -03:00
|
|
|
private:
|
2012-11-05 00:29:29 -04:00
|
|
|
uint8_t _num_items; // number of items in the buffer
|
|
|
|
uint8_t _head; // first item in the buffer (will be returned with the next get call)
|
|
|
|
T _buff[SIZE]; // x values of each point on the curve
|
|
|
|
};
|
|
|
|
|
2013-04-21 07:56:08 -03:00
|
|
|
// Typedef for convenience - add more as needed
|
2012-12-09 11:41:59 -04:00
|
|
|
typedef AP_Buffer<float,5> AP_BufferFloat_Size5;
|
2012-11-05 00:29:29 -04:00
|
|
|
typedef AP_Buffer<float,15> AP_BufferFloat_Size15;
|
|
|
|
|
2012-11-19 20:57:50 -04:00
|
|
|
#endif // __AP_BUFFER_H__
|