Code Monkey home page Code Monkey logo

Comments (1)

obones avatar obones commented on June 10, 2024

Obviously, if SerialDebug is declared inside the #ifndef INCLUDE_UTIL_H_ section from 7_Utils.h, it will not be possible to control its activation on a plugin by plugin basis.
This is because all the C files for each plugins are hard included in the main 5_Plugin.cpp file, which in and of itself is an issue that would be worth looking at.

That being said, it is possible to allow a per plugin control, by moving the above macro definitions out of the #ifndef INCLUDE_UTIL_H_ section while adding a #undef declaration at the end of the block, like so:

#ifdef SerialDebugActivated
#define SerialDebug(method, arguments...)  Serial.method(arguments)
#else
#define SerialDebug(method, arguments...)  /**/
#endif
#define SerialDebugPrintln(arguments...)   SerialDebug(println, arguments)
#define SerialDebugPrint(arguments...)     SerialDebug(print, arguments)
#undef SerialDebugActivated

This way, every plugin that includes 7_Utils.h gets a chance to set SerialDebugActivated for itself, effectively giving control on a per plugin basis.

However, this emits a warning: "SerialDebug" redefined
This is fixed by undefining it before redefining it, which gives the final following block:

#ifdef SerialDebugActivated
#undef SerialDebug
#define SerialDebug(method, arguments...)  Serial.method(arguments)
#else
#undef SerialDebug
#define SerialDebug(method, arguments...)  /**/
#endif
#define SerialDebugPrintln(arguments...)   SerialDebug(println, arguments)
#define SerialDebugPrint(arguments...)     SerialDebug(print, arguments)
#undef SerialDebugActivated

Obviously, there would be an explanation comment in front of that block in the pull request.

from rflink32.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.