From c379d2f0dd80447a024a6d31258adfa174f2d543 Mon Sep 17 00:00:00 2001 From: Eric Mackrodt Date: Tue, 10 Apr 2018 01:12:48 +1000 Subject: [PATCH] Implement sending messages. --- src/SerialMessenger.cpp | 14 +++++++++++++- src/SerialMessenger.h | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) 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