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.hpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/serial.hpp') diff --git a/src/serial.hpp b/src/serial.hpp index 36aa6ed..ae51c3f 100644 --- a/src/serial.hpp +++ b/src/serial.hpp @@ -4,10 +4,28 @@ #include +#define LEONARDO_XINPUT_VID 0x045E // NOLINT(cppcoreguidelines-macro-usage) +#define LEONARDO_XINPUT_PID 0x028E // NOLINT(cppcoreguidelines-macro-usage) + class SerialStream { public: - SerialStream(Serial_ serial, const unsigned long &baud_rate); + SerialStream(Serial_ serial, const unsigned long &baud_rate) noexcept; + + void waitReady(); + + void write(const char *str); + + void flush(); + + constexpr static bool is_enabled() noexcept + { +#if USB_VID != LEONARDO_XINPUT_VID && USB_PID != LEONARDO_XINPUT_PID + return true; +#else + return false; +#endif + } SerialStream &operator<<(const char *str); SerialStream &operator<<(const common::String &str); @@ -18,12 +36,6 @@ public: SerialStream &operator<<(void (*manipulator)(SerialStream *)); - void waitReady(); - - void write(const char *str); - - void flush(); - private: Serial_ _serial; }; -- cgit v1.2.3-18-g5258