In version 1.0 after loop() has finished serialEventRun is called to make serial events possible (see main.cpp below)
#include <Arduino.h>
int main(void)
{
init();
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
void serialEventRun(void)
{
#ifdef serialEvent_implemented
if (Serial.available()) serialEvent();
#endif
#ifdef serialEvent1_implemented
if (Serial1.available()) serialEvent1();
#endif
#ifdef serialEvent2_implemented
if (Serial2.available()) serialEvent2();
#endif
#ifdef serialEvent3_implemented
if (Serial3.available()) serialEvent3();
#endif
}
I think it would improve if the number of bytes available were passed as a parameter to serialEvent(int bytes);
That way it would not be necessary to check the available bytes in the event handler again.
If one wants to handle a single byte/char => just ignore the param
So I propose something like (removed defines for readability)
void serialEventRun(void)
{
uint8_t count = Serial.available()
if (count ) serialEvent(count );
count = Serial1.available()
if (count) serialEvent1(count);
count = Serial2.available()
if (count) serialEvent2(count);
count = Serial3.available()
if (count) serialEvent3(count);
}
Opinions why this is a bad idea?