#define MESSENGERBUFFERSIZE 64 // The length of the commandbuffer (default: 64)
class SerialReader
{
private:
char buffer[MESSENGERBUFFERSIZE]; // Buffer that holds the data
char *current; // Pointer to current buffer position
//Stream *comms; // Serial data stream
char term; // Character indicating end of message (default: '\n')
public:
SerialReader(const char terminator = '\n'){
term = terminator;
}
bool msgComplete;
void reset()
{
current = &buffer[0];
current = '\0';
}
void feedinSerialData()
{
while (!msgComplete && Serial.available())
{
// The Stream class has a readBytes() function that reads many bytes at once. On Teensy 2.0 and 3.0, readBytes() is optimized.
// Benchmarks about the incredible difference it makes: http://www.pjrc.com/teensy/benchmark_usb_serial_receive.html
size_t bytesAvailable = min(Serial.available(), MAXSTREAMBUFFERSIZE);
Serial.readBytes(buffer, bytesAvailable);
// Process the bytes in the stream buffer, and handles dispatches callbacks, if commands are received
for (size_t byteNo = 0; byteNo < bytesAvailable; byteNo++)
{
int msgComplete = processLine(streamBuffer[byteNo]);
// If waiting for acknowledge command
if (streamBuffer[byteNo] == term)
{
msgComplete = true;
return;
}
}
}
}
};
void setup() {
// Initialize serial
Serial.begin(115200);
// Put your setup code here, to run once:
// Notify that setup has ended
Serial.println(F("Start"));
}
void loop() {
timerUpdate();
}