ME507 Utility Library
0.2.1
Mechatronics Course Support Software for ARM/Arduino/FreeRTOS
devnull.h
Go to the documentation of this file.
1
/** @file devnull.h
2
* This file allows debugging printouts to be conveniently turned on and off.
3
* It contains a class which doesn't print anything when given things which
4
* are not to be printed using the @c << operator, and it creates a single
5
* object called @c Debug. In @b this @b file are lines which either define or
6
* undefine the macro @c DEBUG_PRINT_OFF.
7
*
8
* * If the macro @c DEBUG_PRINT_OFF is defined, the @c Debug object will be a
9
* member of class @c DevNull (named for the Unix file @c /dev/null which is
10
* sort of a black hole for data, never mind the black hole quantum
11
* information paradox) and whenever code sends information to @c Debug with
12
* the shift operator using code such as
13
* @code {.cpp}
14
* Debug << "Velocity is " << velocity << endl;
15
* @endcode
16
* Nothing will be printed (in fact, pretty much nothing will happen at all).
17
*
18
* * If the macro @c DEBUG_PRINT_OFF is undefined, the @c Debug object will be
19
* a reference to @c Serial and debugging information will be printed there.
20
*
21
* * TODO: Add the ability to send debugging information to other children of
22
* class @c Print such as SD cards or other serial ports.
23
*
24
* @author JR Ridgely
25
* @date 2021-Nov-26 JRR Original file
26
*
27
* License:
28
* This file is copyright 2021 by JR Ridgely and released under the
29
* Lesser GNU Public License, version 2. It intended for educational use
30
* only, but its use is not limited thereto. */
31
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
32
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIB-
35
* UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
36
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
41
* THE POSSIBILITY OF SUCH DAMAGE. */
42
43
#include <PrintStream.h>
44
45
/// If defined, this macro causes debugging printouts to be suppressed.
46
// One of the following two lines should be active and the other commented out
47
#define DEBUG_PRINT_OFF
48
// #undef DEBUG_PRINT_OFF
49
50
51
/** @brief Class which doesn't print anything when debugging printouts have
52
* been turned off.
53
* @details This class doesn't really do anything. It is provided as a target
54
* for definitions of @c operator<< as provided by the PrintStream
55
* library, which originally comes from
56
* @c https://github.com/tttapa/Arduino-PrintStream
57
* and has been forked on the Spluttflob ME507 GitHub site.
58
*
59
* <b>For usage instructions, see the documentation for
60
* @c devnull.h. </b>
61
*/
62
class
DevNull
63
{
64
public
:
65
/** The constructor creates an inert debug printer which does nothing
66
* except take the place of a @c Print child class such as a serial port
67
* when one doesn't want debugging printouts but would rather not delete
68
* code which creates those printouts...because who knows when a bug may
69
* appear and those printouts will be needed again.
70
*/
71
DevNull
(
void
) { }
72
};
73
74
75
DevNull
& operator<< (
DevNull
& no,
const
__FlashStringHelper *s);
76
DevNull
& operator<< (
DevNull
& no,
const
String &s);
77
DevNull
& operator<< (
DevNull
& no,
const
char
s[]);
78
DevNull
& operator<< (
DevNull
& no,
char
c);
79
DevNull
& operator<< (
DevNull
& no,
unsigned
char
c);
80
DevNull
& operator<< (
DevNull
& no,
int
i);
81
DevNull
& operator<< (
DevNull
& no,
unsigned
int
i);
82
DevNull
& operator<< (
DevNull
& no, int8_t i);
83
DevNull
& operator<< (
DevNull
& no,
long
i);
84
DevNull
& operator<< (
DevNull
& no,
unsigned
long
i);
85
DevNull
& operator<< (
DevNull
& no,
double
d);
86
DevNull
& operator<< (
DevNull
& no,
const
Printable &p);
87
DevNull
& operator<< (
DevNull
& no,
bool
b);
88
DevNull
& operator<< (
DevNull
& no, manipulator pf);
89
DevNull
& operator<< (
DevNull
& no, _Setbase __f);
90
DevNull
& operator<< (
DevNull
& no, _Setprecision __f);
91
DevNull
& operator<< (
DevNull
& no, _Setbytesep __f);
92
93
94
/// Defining this macro causes debugging printouts to be suppressed
95
// #define DEBUG_PRINT_OFF
96
97
#ifdef DEBUG_PRINT_OFF
98
/// If debugging printouts have been turned off, create an object of class
99
/// @c DevNull which doesn't cause anything to be printed
100
extern
DevNull
Debug
;
101
#else
102
/// If debugging printouts haven't been turned off, use the regular serial
103
/// port @c Serial to print debugging messages
104
// #define debug Serial
105
extern
Print&
Debug
;
106
#endif
DevNull::DevNull
DevNull(void)
Definition:
devnull.h:71
Debug
DevNull Debug
Defining this macro causes debugging printouts to be suppressed.
Definition:
devnull.cpp:52
DevNull
Class which doesn't print anything when debugging printouts have been turned off.
Definition:
devnull.h:62
src
devnull.h
Generated by
1.8.17