87 lines
1.9 KiB
C++
87 lines
1.9 KiB
C++
/**
|
|
* @file outputBuf.h
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief Contains a small class that provide a streambuf
|
|
*
|
|
* The streambuf is used to double the std::cout to consol
|
|
* and MQTT.
|
|
*
|
|
* @version 0.1
|
|
* @date 2022-02-14
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
|
|
#ifndef OUTPUT_STREAM_MQTT_H
|
|
#define OUTPUT_STREAM_MQTT_H
|
|
|
|
#include <iostream>
|
|
#include <streambuf>
|
|
#include <locale>
|
|
#include <cstdio>
|
|
|
|
#include "debugMqtt.h"
|
|
|
|
#include <BluetoothSerial.h>
|
|
|
|
/**
|
|
* @brief A alternativ streambuf for std::cout
|
|
*
|
|
* The streambuf is used to double the std::cout to consol
|
|
* and MQTT.
|
|
*
|
|
*/
|
|
class OutputBuf : public std::streambuf {
|
|
public:
|
|
/**
|
|
* @brief Construct a new Output Buf Mqtt object
|
|
*
|
|
* @param debugMqtt
|
|
* @param serialBT
|
|
*/
|
|
OutputBuf(DebugMqtt* debugMqtt = nullptr, BluetoothSerial* serialBT = nullptr);
|
|
|
|
/**
|
|
* @brief Activate the mqtt output
|
|
*
|
|
* This only works if the DebugMqtt is set by
|
|
* setDebugMqtt.
|
|
*
|
|
* @param status
|
|
*/
|
|
void activateMqtt(bool status);
|
|
|
|
/**
|
|
* @brief Active the output over the bluetooth serial consol
|
|
*
|
|
* This only works if BluetoothSerial is set by
|
|
* setSerialBT.
|
|
*
|
|
* @param status
|
|
*/
|
|
void activateSerialBT(bool status);
|
|
|
|
void setDebugMqtt(DebugMqtt* debugMqtt);
|
|
void setSerialBT(BluetoothSerial* serialBT);
|
|
|
|
|
|
protected:
|
|
/**
|
|
* @brief
|
|
*
|
|
* @param c
|
|
* @return std::streambuf::int_type
|
|
*/
|
|
virtual std::streambuf::int_type overflow(std::streambuf::int_type c);
|
|
|
|
private:
|
|
bool isMqttActive = false;
|
|
bool isSerialBTActive = false;
|
|
|
|
DebugMqtt* debugMqtt;
|
|
BluetoothSerial* serialBT;
|
|
};
|
|
|
|
#endif // OUTPUT_STREAM_MQTT_H
|