STM works

This commit is contained in:
2024-04-22 11:20:53 +03:00
parent 03d74e30cd
commit e334625864
8 changed files with 381 additions and 274 deletions

39
RingBuffer.h Normal file
View 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;
};