diff --git a/SerialAgent.h b/SerialAgent.h index 90fb41c..724b82f 100644 --- a/SerialAgent.h +++ b/SerialAgent.h @@ -1,28 +1,36 @@ -class SerialAgent : public SoftwareSerial{ +#define HARD_SERIAL Serial + +class SerialAgent { private: String str_buff; bool isAvailable; void serialRead(); public: - SerialAgent(int rx, int tx); + SerialAgent(); + void begin(int); int available(); + void print(String); + void println(String); String readStringUntil(char c); }; - -SerialAgent::SerialAgent(int rx, int tx) :SoftwareSerial(rx, tx) { +SerialAgent::SerialAgent() { isAvailable = false; } +void SerialAgent::begin(int baudrate) { + HARD_SERIAL.begin(baudrate); +} + void SerialAgent::serialRead() { if (isAvailable) { str_buff = ""; isAvailable = false; } - if (int count = SoftwareSerial::available() > 0) { + if (int count = HARD_SERIAL.available() > 0) { char c_buff = '\0'; for (int i = 0; i < count; i++) { - c_buff = (char)SoftwareSerial::read(); + c_buff = (char)HARD_SERIAL.read(); if ( c_buff != '\n' ) { str_buff += c_buff; } else { @@ -34,7 +42,7 @@ } String SerialAgent::readStringUntil(char c) { - int foundIndex = str_buff.indexOf(c); + int foundIndex = str_buff.indexOf(c); if ( foundIndex == -1 ) return "\n"; String result = str_buff.substring(0,foundIndex); str_buff = str_buff.substring(foundIndex+1); @@ -45,3 +53,11 @@ serialRead(); return isAvailable; } + +void SerialAgent::print(String str) { + HARD_SERIAL.print(str); +} + +void SerialAgent::println(String str) { + HARD_SERIAL.println(str); +}