|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 Anders Löfgren |
| 3 | + * |
| 4 | + * License (MIT license): |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +#ifndef __CONDITIONALPRINTER_H__ |
| 26 | +#define __CONDITIONALPRINTER_H__ |
| 27 | + |
| 28 | +class ConditionalPrinter |
| 29 | +{ |
| 30 | + |
| 31 | +public: |
| 32 | + |
| 33 | + /** |
| 34 | + * Set whether the normal events occurring in the library will be printed to Serial or not. |
| 35 | + * |
| 36 | + * @param enabled If true, library Serial prints are activated. |
| 37 | + */ |
| 38 | + void setVerboseModeState(const bool enabled); |
| 39 | + bool verboseMode() const; |
| 40 | + |
| 41 | + /** |
| 42 | + * Only print stringToPrint if verboseMode() returns true. |
| 43 | + * |
| 44 | + * @param stringToPrint String to print. |
| 45 | + * @param newline If true, will end the print with a newline. True by default. |
| 46 | + */ |
| 47 | + void verboseModePrint(const String &stringToPrint, const bool newline = true) const; |
| 48 | + |
| 49 | + /** |
| 50 | + * Same as verboseMode(), but used for printing from static functions. |
| 51 | + * |
| 52 | + * @param enabled If true, the normal events occurring in the library will be printed to Serial. |
| 53 | + */ |
| 54 | + static void setStaticVerboseModeState(const bool enabled); |
| 55 | + static bool staticVerboseMode(); |
| 56 | + |
| 57 | + /** |
| 58 | + * Only print stringToPrint if staticVerboseMode() returns true. |
| 59 | + * |
| 60 | + * @param stringToPrint String to print. |
| 61 | + * @param newline If true, will end the print with a newline. True by default. |
| 62 | + */ |
| 63 | + static void staticVerboseModePrint(const String &stringToPrint, const bool newline = true); |
| 64 | + |
| 65 | + /** |
| 66 | + * Set whether the warnings occurring in the library will be printed to Serial or not. On by default. |
| 67 | + * |
| 68 | + * @param printEnabled If true, warning Serial prints from the library are activated. |
| 69 | + */ |
| 70 | + static void setPrintWarnings(const bool printEnabled); |
| 71 | + static bool printWarnings(); |
| 72 | + |
| 73 | + /** |
| 74 | + * Only print stringToPrint if printWarnings() returns true. |
| 75 | + * |
| 76 | + * @param stringToPrint String to print. |
| 77 | + * @param newline If true, will end the print with a newline. True by default. |
| 78 | + */ |
| 79 | + static void warningPrint(const String &stringToPrint, const bool newline = true); |
| 80 | + |
| 81 | +private: |
| 82 | + |
| 83 | + bool _verboseMode = false; |
| 84 | + |
| 85 | +}; |
| 86 | + |
| 87 | +#endif |
0 commit comments