diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-01 09:22:37 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-03-01 09:22:37 +0100 |
commit | 249323fc5fa14dbc4c1a6316873cfc07f468f43b (patch) | |
tree | bd53ea18ab364e5f19993d0f7ef07a39ce10f60f /src/serial.cpp | |
parent | 61f11389ea6296fb0c28dd7aa4d0bfa6feb919f3 (diff) |
refactor: fix serial stream & unique ptr
Diffstat (limited to 'src/serial.cpp')
-rw-r--r-- | src/serial.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/serial.cpp b/src/serial.cpp index d03f8e8..acf92fa 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -2,46 +2,45 @@ #include "std/conversion.hpp" -SerialStream::SerialStream(Serial_ serial, uint64_t baud_rate) : _serial(serial) +SerialStream::SerialStream(Serial_ serial, const unsigned long &baud_rate) + : _serial(serial) { - this->_serial.begin(baud_rate); - - while (!this->_serial) {} + _serial.begin(baud_rate); } SerialStream &SerialStream::operator<<(const char *str) { - this->write(str); + write(str); return *this; } SerialStream &SerialStream::operator<<(const SmartString &str) { - this->write(str.c_str); + write(str.c_str); return *this; } SerialStream &SerialStream::operator<<(const double &num) { - this->write(doubleToStr(num)->c_str); + write(doubleToStr(num)->c_str); return *this; } SerialStream &SerialStream::operator<<(const int &num) { - this->write(intToStr(num)->c_str); + write(intToStr(num)->c_str); return *this; } SerialStream &SerialStream::operator<<(const unsigned int &num) { - this->write(uintToStr(num)->c_str); + write(uintToStr(num)->c_str); return *this; } SerialStream &SerialStream::operator<<(const unsigned long &num) { - this->write(uintToStr(num)->c_str); + write(uintToStr(num)->c_str); return *this; } @@ -51,14 +50,19 @@ SerialStream &SerialStream::operator<<(void (*manipulator)(SerialStream *)) return *this; } +void SerialStream::waitReady() +{ + while (!_serial) {} +} + void SerialStream::write(const char *str) { - this->_serial.write(str); + _serial.write(str); } void SerialStream::flush() { - this->_serial.flush(); + _serial.flush(); } void endl(SerialStream *serial_stream) |