Skip to content

Conversation

@hoeken
Copy link

@hoeken hoeken commented Nov 23, 2025

I really like this library and use it a lot. I love the simplicity and it really makes debugging a lot easier.

One thing I find myself constantly doing when debugging is to create interval timers which usually means a global variable declared and then some code to check and update the timer variable. Then you have a bunch of scattered extra things just for debugging!

This solves that problem with a self contained INTERVAL() call that keeps track of all that internally.

This example code will call TRACE() every 1000ms.

if (INTERVAL(1000))
  TRACE();

It also respects the ARDUINOTRACE_ENABLE, so INTERVAL() is defined as false when ARDUINOTRACE_ENABLE = 0

@bblanchon
Copy link
Owner

Hi @hoeken,

Thank you for this pull request.

This is an interesting feature, but I don't think it is the right interface for it.
Indeed, inattentive users might write something like that:

if (INTERVAL(1000)) {
  doSomething();
  TRACE();
}

Then they wouldn't understand why the code doesn't work after setting ARDUINOTRACE_ENABLE to 0.
Also, defining a macro name INTERVAL is likely to clash with existing code.

Instead, I think it should be something like:

- if (INTERVAL(1000))
-   TRACE();
+ TRACE_THROTTLED(1000);

...or something along those lines.
Then, of course, we also need the same for DUMP().

For future contributions, I'd appreciate if we could discuss the approach first through an issue - it helps ensure we're aligned on the design before implementation work begins. Also, please avoid updating version numbers in PRs as I handle those during releases.

I'll take over implementing this feature using the approach I outlined above. Thanks for bringing this idea forward!

Best regards,
Benoit

@hoeken
Copy link
Author

hoeken commented Nov 28, 2025

I'm glad you like the idea. You're right that it might cause a little bit of confusion as INTERVAL alone.

If I could suggest, maybe it would be possible to add milliseconds as an optional parameter to the DUMP and TRACE functions? I'm not an expert on macro style functions like these.

Something like:

DUMP(variable, 1000);
TRACE(500);

Or if that is doesn't work, then something short would be nice. One of the things that I love about this library is how non-verbose it is and how it makes debugging so much easier because of that.

Maybe something like:

TRACE_TIMED(500)

Either way, as long as some sort of timed option makes it into the library I will be very happy. Sorry about bumping the version number. Some maintainers like that, some don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants