diff --git a/src/SerialMessenger.cpp b/src/SerialMessenger.cpp index 4c055ca..89033cc 100644 --- a/src/SerialMessenger.cpp +++ b/src/SerialMessenger.cpp @@ -30,8 +30,12 @@ void SerialMessenger::setDelimiter(char delimiter) { _delimiter = delimiter; } +void SerialMessenger::send(String channel) { + _print(_prefix + channel + _suffix); +} + void SerialMessenger::send(String channel, String message) { - + _print(_prefix + channel + _delimiter + message + _suffix); } void SerialMessenger::handle() { @@ -62,6 +66,14 @@ int SerialMessenger::_read() { } } +void SerialMessenger::_print(String message) { + if (_isHardwareSerial == true) { + Serial.print(message); + } else { + _softSerial->print(message); + } +} + bool SerialMessenger::_received() { if(_serialAvailable()) { char read = char(_read()); diff --git a/src/SerialMessenger.h b/src/SerialMessenger.h index 829bb9a..9678828 100644 --- a/src/SerialMessenger.h +++ b/src/SerialMessenger.h @@ -23,6 +23,7 @@ class SerialMessenger SerialMessenger(); SerialMessenger(SoftwareSerial* serial); int subscribe(String channel, void (*func)(String)); + void send(String message); void send(String channel, String message); void setPrefix(char prefix); void setSuffix(char suffix); @@ -47,6 +48,7 @@ class SerialMessenger String _getParameter(); bool _isChannel(String channel); int _read(); + void _print(String message); }; #endif