3-phase PV router
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
32
33#ifndef DEBUG_H
34#define DEBUG_H
35
36#include <Arduino.h>
37
38#include "config.h" // SERIAL_OUTPUT_TYPE, ENABLE_DEBUG
39
40// A config.h of the former layout defines CONFIG_H and includes this file itself: stop on the
41// reason, before the follow-on errors.
42#if defined(CONFIG_H)
43#error "This config.h has the former layout, with #include lines and derived values. config.h now only holds the settings: create it again with the configurator, or see 'config.h holds the settings only' in the CHANGELOG to update it by hand."
44#endif
45
46#include "serial_output.h"
47
52
56template< typename... Args >
57__attribute__((always_inline)) inline void info(const Args&... args)
58{
60 Serial.print(args...);
61}
62
66template< typename... Args >
67__attribute__((always_inline)) inline void infoln(const Args&... args)
68{
70 Serial.println(args...);
71}
72
79__attribute__((noinline)) inline void info(const __FlashStringHelper* text)
80{
82 Serial.print(text);
83}
84
88__attribute__((noinline)) inline void infoln(const __FlashStringHelper* text)
89{
91 Serial.println(text);
92}
93
100inline void infolnDecimals(const int32_t value, const uint8_t decimals)
101{
103 SerialOutput::printDecimals(Serial, value, decimals);
104 Serial.println();
105}
106
110inline void infolnDecimals_P(const int32_t* value, const uint8_t decimals)
111{
112 infolnDecimals(static_cast< int32_t >(pgm_read_dword(value)), decimals);
113}
114
118template< typename... Args >
119__attribute__((always_inline)) inline void status(const Args&... args)
120{
121 if constexpr (STATUS_OUTPUT_ENABLED)
122 {
123 info(args...);
124 }
125}
126
130template< typename... Args >
131__attribute__((always_inline)) inline void statusln(const Args&... args)
132{
133 if constexpr (STATUS_OUTPUT_ENABLED)
134 {
135 infoln(args...);
136 }
137}
138
142template< typename... Args >
143__attribute__((always_inline)) inline void debug(const Args&... args)
144{
145 if constexpr (ENABLE_DEBUG)
146 {
147 info(args...);
148 }
149}
150
154template< typename... Args >
155__attribute__((always_inline)) inline void debugln(const Args&... args)
156{
157 if constexpr (ENABLE_DEBUG)
158 {
159 infoln(args...);
160 }
161}
162
163#endif // DEBUG_H
Router configuration: loads, relays, control pins and features.
constexpr SerialOutputType SERIAL_OUTPUT_TYPE
Definition config.h:24
constexpr bool ENABLE_DEBUG
Definition config.h:29
void infoln(const Args &... args)
Print an informational message and a line end, as Serial.println() does.
Definition debug.h:67
void infolnDecimals_P(const int32_t *value, const uint8_t decimals)
Same as infolnDecimals(), with the value read from PROGMEM.
Definition debug.h:110
void statusln(const Args &... args)
Print a status message and a line end, as Serial.println() does (human-readable output only).
Definition debug.h:131
constexpr bool STATUS_OUTPUT_ENABLED
Whether the status changes are printed while running: in human-readable output only.
Definition debug.h:51
void debugln(const Args &... args)
Print a debug message and a line end, as Serial.println() does (only with ENABLE_DEBUG).
Definition debug.h:155
void info(const Args &... args)
Print an informational message, as Serial.print() does.
Definition debug.h:57
void status(const Args &... args)
Print a status message, as Serial.print() does (human-readable output only).
Definition debug.h:119
void debug(const Args &... args)
Print a debug message, as Serial.print() does (only with ENABLE_DEBUG).
Definition debug.h:143
void infolnDecimals(const int32_t value, const uint8_t decimals)
Print a value given as an integer with a fixed number of decimals, and a line end.
Definition debug.h:100
void complete()
Write whatever is left of the current output to Serial, waiting like a plain print.
void printDecimals(Print &out, int32_t value, uint8_t decimals)
Print a value given as an integer with a fixed number of decimals (see toDecimals())
Non-blocking serial output of the datalog.