forked from letscontrolit/ESPEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serial.ino
44 lines (39 loc) · 1.31 KB
/
Serial.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/********************************************************************************************\
* Get data from Serial Interface
\*********************************************************************************************/
#define INPUT_BUFFER_SIZE 128
byte SerialInByte;
int SerialInByteCounter = 0;
char InputBuffer_Serial[INPUT_BUFFER_SIZE + 2];
void serial()
{
while (Serial.available())
{
yield();
SerialInByte = Serial.read();
if (SerialInByte == 255) // binary data...
{
Serial.flush();
return;
}
if (isprint(SerialInByte))
{
if (SerialInByteCounter < INPUT_BUFFER_SIZE) // add char to string if it still fits
InputBuffer_Serial[SerialInByteCounter++] = SerialInByte;
}
if (SerialInByte == '\n')
{
InputBuffer_Serial[SerialInByteCounter] = 0; // serial data completed
Serial.write('>');
Serial.println(InputBuffer_Serial);
String action = InputBuffer_Serial;
struct EventStruct TempEvent;
parseCommandString(&TempEvent, action);
TempEvent.Source = VALUE_SOURCE_SERIAL;
if (!PluginCall(PLUGIN_WRITE, &TempEvent, action))
ExecuteCommand(VALUE_SOURCE_SERIAL, InputBuffer_Serial);
SerialInByteCounter = 0;
InputBuffer_Serial[0] = 0; // serial data processed, clear buffer
}
}
}