use configurable length for buffer
This commit is contained in:
parent
803f94fe63
commit
55d02cd4d0
@ -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":
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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++) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user