From 62c6d40f1f54bbd809ba678b7bb68f2ff9684ec2 Mon Sep 17 00:00:00 2001 From: Paul Riseborough Date: Fri, 22 Apr 2016 08:21:36 +1000 Subject: [PATCH] EKF: Add methods to ring buffer to access specific indices --- EKF/RingBuffer.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/EKF/RingBuffer.h b/EKF/RingBuffer.h index 376d8e5851..b16f25cde1 100644 --- a/EKF/RingBuffer.h +++ b/EKF/RingBuffer.h @@ -160,6 +160,30 @@ public: return _buffer[index]; } + // return data at the specified index + data_type get_from_index(unsigned index) + { + if (index >= _size) { + index = _size-1; + } + return _buffer[index]; + } + + // push data to the specified index + void push_to_index(unsigned index, data_type sample) + { + if (index >= _size) { + index = _size-1; + } + _buffer[index] = sample; + } + + // return the length of the buffer + unsigned get_length() + { + return _size; + } + private: data_type *_buffer; unsigned _head, _tail, _size;