2 // A simple ringbuffer holding Size elements of type T
3 template <typename T, uint8_t Size>
7 uint8_t head_{0}, tail_{0};
9 inline uint8_t nextPosition(uint8_t position) {
10 return (position + 1) % Size;
13 inline uint8_t prevPosition(uint8_t position) {
20 inline bool enqueue(const T &item) {
21 static_assert(Size > 1, "RingBuffer size must be > 1");
22 uint8_t next = nextPosition(head_);
33 inline bool get(T &dest, bool commit = true) {
41 tail = nextPosition(tail);
49 inline bool empty() const { return head_ == tail_; }
51 inline uint8_t size() const {
52 int diff = head_ - tail_;
63 inline bool peek(T &item) {
64 return get(item, false);