embeddedartistry / arduino-printf

Add printf support to the Arduino SDK
MIT License
91 stars 15 forks source link

what is the macro to disable all prints #33

Closed oneandonlyonebutyou closed 2 years ago

oneandonlyonebutyou commented 2 years ago

Is there any macro where I could diable all prints, and basically fully remove the lib, when I am not debugging

phillipjohnston commented 2 years ago

Not at present. What I have done in the past is to make an internal print macro, such as debug_print. If a definition is present, such as DISABLE_DEBUG_PRINTS, it is defined to an empty value, otherwise it simply aliases printf.

I'll work on implementing something like that in the Arduino library wrapper next week.

phillipjohnston commented 2 years ago

Alternatively, our logging library already supports this behavior (as well as configurable log levels): https://github.com/embeddedartistry/arduino-logger

oneandonlyonebutyou commented 2 years ago

Not at present. What I have done in the past is to make an internal print macro, such as debug_print. If a definition is present, such as DISABLE_DEBUG_PRINTS, it is defined to an empty value, otherwise it simply aliases printf.

I'll work on implementing something like that in the Arduino library wrapper next week.

Thank you..: I am not such an expert on macros How does your macro looks like to be able to print multiple values

phillipjohnston commented 2 years ago

General form:

#ifdef DISABLE_DEBUG_PRINT
#define debug_print(...)
#else
#define debug_print(...) printf(__VA_ARGS__)
#endif
phillipjohnston commented 2 years ago

Whoops, corrected printf(...) to printf(__VA_ARGS__)

oneandonlyonebutyou commented 2 years ago

Thank you .. :)

phillipjohnston commented 2 years ago

Sometimes i do this on a per-file basis for fine grained control. For application wide control i would make a new header like debug_print.h. In that you could include the printf header. Your source files will include the debug_printf.h header

Cheers,

Phillip

On May 20, 2022, at 14:16, Joseph @.***> wrote:

 thank you so much .. Do I need to put that in all files ... ? I put this on my mian, and other files do not see it ..

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.