30 lines
923 B
C++
30 lines
923 B
C++
|
|
#pragma once
|
||
|
|
#include <Arduino.h>
|
||
|
|
|
||
|
|
#ifndef ENABLE_SERIAL_DEBUG
|
||
|
|
#define ENABLE_SERIAL_DEBUG 0
|
||
|
|
#endif
|
||
|
|
|
||
|
|
struct Debug {
|
||
|
|
static constexpr bool enabled = static_cast<bool>(ENABLE_SERIAL_DEBUG);
|
||
|
|
static inline void begin(unsigned long baud) {
|
||
|
|
if constexpr (enabled) Serial.begin(baud);
|
||
|
|
}
|
||
|
|
template<typename... Args>
|
||
|
|
static inline void print(Args&&... args) {
|
||
|
|
if constexpr (enabled) { (Serial.print(std::forward<Args>(args)), ...); }
|
||
|
|
}
|
||
|
|
template<typename... Args>
|
||
|
|
static inline void println(Args&&... args) {
|
||
|
|
if constexpr (enabled) {
|
||
|
|
(Serial.print(std::forward<Args>(args)), ...);
|
||
|
|
Serial.println();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
template<typename... Args>
|
||
|
|
static inline void printf(const char *fmt, Args&&... args) {
|
||
|
|
if constexpr (enabled) {
|
||
|
|
Serial.printf(fmt, std::forward<Args>(args)...);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|