mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-28 05:09:40 +00:00
STM works
This commit is contained in:
39
RingBuffer.h
Normal file
39
RingBuffer.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "Arduino.h"
|
||||
template <typename T, unsigned int BufferSize>
|
||||
class RingBuffer {
|
||||
public:
|
||||
RingBuffer() : start(0), end(0) {}
|
||||
|
||||
bool isFull() const {
|
||||
return ((end + 1) % BufferSize) == start;
|
||||
}
|
||||
|
||||
bool isEmpty() const {
|
||||
return start == end;
|
||||
}
|
||||
|
||||
void push(T element) {
|
||||
noInterrupts();
|
||||
if (!isFull()) {
|
||||
data[end] = element;
|
||||
end = (end + 1) % BufferSize;
|
||||
}
|
||||
interrupts();
|
||||
}
|
||||
|
||||
T* pop() {
|
||||
noInterrupts();
|
||||
T* value = nullptr;
|
||||
if (!isEmpty()) {
|
||||
value = &data[start];
|
||||
start = (start + 1) % BufferSize;
|
||||
}
|
||||
interrupts();
|
||||
return value;
|
||||
}
|
||||
|
||||
private:
|
||||
T data[BufferSize];
|
||||
unsigned int start, end;
|
||||
};
|
Reference in New Issue
Block a user