summaryrefslogtreecommitdiff
path: root/src/utils/serial.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-02-14 10:11:32 +0100
committerHampusM <hampus@hampusmat.com>2022-02-14 10:11:32 +0100
commit7892ef9d248c189be68ce7faf63230ec0a318b67 (patch)
tree7c3d07779d5ce96994f81c0cc22e8b667601ee9d /src/utils/serial.cpp
parenta03dfe959fcafd238119bdf7f27c07b92064496e (diff)
refactor: reorganize & add debugging
Diffstat (limited to 'src/utils/serial.cpp')
-rw-r--r--src/utils/serial.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/utils/serial.cpp b/src/utils/serial.cpp
new file mode 100644
index 0000000..11be550
--- /dev/null
+++ b/src/utils/serial.cpp
@@ -0,0 +1,57 @@
+#include "serial.hpp"
+
+#include "general.hpp"
+
+SerialStream::SerialStream(Serial_ serial, unsigned long baud_rate)
+{
+ this->_serial = serial;
+
+ this->_serial.begin(baud_rate);
+
+ while (!this->_serial) {}
+}
+
+SerialStream::~SerialStream()
+{
+ Serial.end();
+}
+
+SerialStream &SerialStream::operator<<(const char *str)
+{
+ this->write(str);
+ return *this;
+}
+
+SerialStream &SerialStream::operator<<(const SmartString &str)
+{
+ this->write(str.c_str);
+ return *this;
+}
+
+SerialStream &SerialStream::operator<<(const float num)
+{
+ this->write(floatToStr(num)->c_str);
+ return *this;
+}
+
+SerialStream &SerialStream::operator<<(void (*manipulator)(SerialStream *))
+{
+ manipulator(this);
+ return *this;
+}
+
+void SerialStream::write(const char *str)
+{
+ this->_serial.write(str);
+}
+
+void SerialStream::flush()
+{
+ this->_serial.flush();
+}
+
+void endl(SerialStream *serial_stream)
+{
+ serial_stream->write("\n");
+ serial_stream->flush();
+}