use configurable length for buffer

This commit is contained in:
Nicu Hodos 2023-01-20 10:11:35 +01:00
parent 803f94fe63
commit 55d02cd4d0
2 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "SerialReader", "name": "SerialReader",
"version": "1.0.1", "version": "1.0.0",
"description": "Helper class for reading Serial input, without blocking", "description": "Helper class for reading Serial input, without blocking",
"repository": "repository":
{ {

View File

@ -2,8 +2,8 @@
#include <Arduino.h> #include <Arduino.h>
template <size_t bufferLength>
class SerialReader { class SerialReader {
static const int bufferLength = 50;
char buffer[bufferLength]; char buffer[bufferLength];
public: public:
@ -12,8 +12,8 @@ public:
} }
int readLine(HardwareSerial &serial) { int readLine(HardwareSerial &serial) {
static int pos = 0; static size_t pos = 0;
int rpos; size_t rpos;
int readCh; int readCh;
for (int i = 0, avail = serial.available(); i < avail && (readCh = serial.read()) > 0; i++) { for (int i = 0, avail = serial.available(); i < avail && (readCh = serial.read()) > 0; i++) {