Debug.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Debug.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "HardwareSerial.h"
14 #include "Clock.h"
15 #include "WString.h"
17 
22 
26 typedef struct {
27  DebugPrintCharDelegate debugDelegate = nullptr;
28  Stream* debugStream = nullptr;
30 
34 typedef enum {
37 } eDBGPrefix;
38 
49 class DebugClass : public Print
50 {
51 public:
55  DebugClass();
56 
59  void initCommand();
60 
63  void start();
64 
67  void stop();
68 
72  bool status()
73  {
74  return started;
75  }
76 
81  void setDebug(DebugPrintCharDelegate reqDelegate);
82 
87  void setDebug(Stream& reqStream);
88 
89  /* implementation of write for Print Class */
90  size_t write(uint8_t) override;
91 
92 private:
93  bool started = false;
94  bool useDebugPrefix = true;
95  bool newDebugLine = true;
96  DebugOuputOptions debugOut;
97  void printPrefix();
98  void processDebugCommands(String commandLine, CommandOutput* commandOutput);
99 };
100 
109 extern DebugClass Debug;
110 
Delegate< void(char dbgChar)> DebugPrintCharDelegate
Delegate constructor usage: (&YourClass::method, this)
Definition: Debug.h:21
Provides debug output to stream (e.g. Serial) or delegate function handler.
Definition: Debug.h:49
void initCommand()
Enable control of debug output from CLI command handler output.
The String class.
Definition: WString.h:136
Provides formatted output to stream.
Definition: Print.h:36
void setDebug(DebugPrintCharDelegate reqDelegate)
Configure debug to use delegate handler for its output.
Do not use debug prefix.
Definition: Debug.h:35
DebugClass Debug
Global instance of Debug object.
Definition: CommandOutput.h:15
size_t write(uint8_t) override
Writes a single character to output stream.
eDBGPrefix
Debug prefix state.
Definition: Debug.h:34
Structure for debug options.
Definition: Debug.h:26
Use debug prefix.
Definition: Debug.h:36
bool status()
Get debug status.
Definition: Debug.h:72
void start()
Start debug output.
void stop()
Stop debug output.
DebugClass()
Instantiate a debug object.
Base Stream class.
Definition: Stream.h:32