Skip to content

Commit

Permalink
Implement sending messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Mackrodt authored and Eric Mackrodt committed Apr 9, 2018
1 parent 9af6cf2 commit c379d2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/SerialMessenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/SerialMessenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -47,6 +48,7 @@ class SerialMessenger
String _getParameter();
bool _isChannel(String channel);
int _read();
void _print(String message);
};

#endif

0 comments on commit c379d2f

Please sign in to comment.