improve debug
This commit is contained in:
30
include/debugutil.hpp
Normal file
30
include/debugutil.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#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)...);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user