diff --git a/lib/MQTT/outputBufMqtt.cpp b/lib/MQTT/outputBufMqtt.cpp deleted file mode 100644 index f7abb56..0000000 --- a/lib/MQTT/outputBufMqtt.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @file outputBufMqtt.cpp - * @author Alexander Klein (alex@kleiax.de) - * @brief Contains the implementation of the class OutputBufMqtt - * @version 0.1 - * @date 2022-02-14 - * - * @copyright Copyright (c) 2022 - * - */ - -#include "outputBufMqtt.h" - -OutputBufMqtt::OutputBufMqtt(DebugMqtt* debugMqtt) - : std::streambuf() { - this->debugMqtt = debugMqtt; -} - -std::streambuf::int_type OutputBufMqtt::overflow(std::streambuf::int_type c) { - if (c != EOF) { - // c = std::toupper(static_cast(c), getloc()); - - this->debugMqtt->addCharacter((char) c); - Serial.print((char) c); - // if (putchar(c) == EOF) { - // return EOF; - // } - } - return c; -} diff --git a/platformio.ini b/platformio.ini index b85e034..dd55a82 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,7 +14,9 @@ board = esp32doit-devkit-v1 board_build.partitions = no_ota.csv framework = arduino monitor_speed = 115200 +upload_speed = 921600 monitor_port = COM3 +;build_flags = -DCORE_DEBUG_LEVEL=5 lib_deps = madhephaestus/ESP32Encoder@^0.4.0 jvpernis/PS3 Controller Host@^1.1.0 diff --git a/src/OutputBuf/outputBuf.cpp b/src/OutputBuf/outputBuf.cpp new file mode 100644 index 0000000..1e761d0 --- /dev/null +++ b/src/OutputBuf/outputBuf.cpp @@ -0,0 +1,59 @@ +/** + * @file outputBufMqtt.cpp + * @author Alexander Klein (alex@kleiax.de) + * @brief Contains the implementation of the class OutputBufMqtt + * @version 0.1 + * @date 2022-02-14 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "OutputBuf/outputBuf.h" + +OutputBuf::OutputBuf(DebugMqtt* debugMqtt, BluetoothSerial* serialBT) + : std::streambuf() { + this->debugMqtt = debugMqtt; + this->serialBT = serialBT; + + if (debugMqtt) + this->isMqttActive = true; + + if (serialBT) + this->isMqttActive = true; +} + +void OutputBuf::activateMqtt(bool status) { + if (debugMqtt) + this->isMqttActive = status; +} + +void OutputBuf::activateSerialBT(bool status) { + if (serialBT) + this->isSerialBTActive = status; +} + +void OutputBuf::setDebugMqtt(DebugMqtt* debugMqtt) { + this->debugMqtt = debugMqtt; + this->isMqttActive = true; +} + +void OutputBuf::setSerialBT(BluetoothSerial* serialBT) { + this->serialBT = serialBT; + this->isSerialBTActive = true;; +} + +std::streambuf::int_type OutputBuf::overflow(std::streambuf::int_type c) { + if (c != EOF) { + // c = std::toupper(static_cast(c), getloc()); + + if (this->debugMqtt && this->isMqttActive) + this->debugMqtt->addCharacter((char) c); + + if (this->serialBT && this->isSerialBTActive && this->serialBT->connected()) + this->serialBT->print((char) c); + + Serial.print((char) c); + } + return c; +} diff --git a/lib/MQTT/outputBufMqtt.h b/src/OutputBuf/outputBuf.h similarity index 68% rename from lib/MQTT/outputBufMqtt.h rename to src/OutputBuf/outputBuf.h index 5ded5b9..3c6d9e7 100644 --- a/lib/MQTT/outputBufMqtt.h +++ b/src/OutputBuf/outputBuf.h @@ -23,6 +23,8 @@ #include "debugMqtt.h" +#include + /** * @brief A alternativ streambuf for std::cout * @@ -30,14 +32,20 @@ * and MQTT. * */ -class OutputBufMqtt : public std::streambuf { +class OutputBuf : public std::streambuf { public: /** * @brief Construct a new Output Buf Mqtt object * * @param debugMqtt */ - OutputBufMqtt(DebugMqtt* debugMqtt); + OutputBuf(DebugMqtt* debugMqtt = nullptr, BluetoothSerial* serialBT = nullptr); + void activateMqtt(bool status); + void activateSerialBT(bool status); + + void setDebugMqtt(DebugMqtt* debugMqtt); + void setSerialBT(BluetoothSerial* serialBT); + protected: /** @@ -48,8 +56,12 @@ class OutputBufMqtt : public std::streambuf { */ virtual std::streambuf::int_type overflow(std::streambuf::int_type c); - public: + private: + bool isMqttActive = false; + bool isSerialBTActive = false; + DebugMqtt* debugMqtt; + BluetoothSerial* serialBT; }; #endif // OUTPUT_STREAM_MQTT_H