From d5b6bc7bb8250dd252b8569e0896febf94c60b12 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Mar 2022 14:14:47 +0100 Subject: refactor: add serial stream enabled check --- src/serial.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/serial.cpp') diff --git a/src/serial.cpp b/src/serial.cpp index e60de6c..874d6d7 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -2,12 +2,30 @@ #include "common/conversion.hpp" -SerialStream::SerialStream(Serial_ serial, const unsigned long &baud_rate) +SerialStream::SerialStream(Serial_ serial, const unsigned long &baud_rate) noexcept : _serial(serial) { _serial.begin(baud_rate); } +void SerialStream::waitReady() +{ + while (!_serial) {} +} + +void SerialStream::write(const char *str) +{ + if (SerialStream::is_enabled()) + { + _serial.write(str); + } +} + +void SerialStream::flush() +{ + _serial.flush(); +} + SerialStream &SerialStream::operator<<(const char *str) { write(str); @@ -50,21 +68,6 @@ SerialStream &SerialStream::operator<<(void (*manipulator)(SerialStream *)) return *this; } -void SerialStream::waitReady() -{ - while (!_serial) {} -} - -void SerialStream::write(const char *str) -{ - _serial.write(str); -} - -void SerialStream::flush() -{ - _serial.flush(); -} - void endl(SerialStream *serial_stream) { serial_stream->write("\n"); -- cgit v1.2.3-18-g5258