debug output


  • Mod

    Is it save to do something like:

    gw.debug("%s output", "short");

    The reason I ask: I would like to avoid having to comment or uncomment output that I need/use for debugging purposes πŸ™‚


  • Admin

    debug() is a #define using the debugPrint-method which isn't public. You'll have to modify the class to be able to do it.


  • Mod

    @hek Is there a reason why it is not public?


  • Mod

    @hek let me change my previous question πŸ™‚
    Is it possible to make this public by default?
    I would like to avoid changing the libs and it would also make my library more accessible...
    Or is there an important reason not to do this?


  • Admin

    @marceltrapman said:

    Is it possible to make this public by default?

    Yes

    I would like to avoid changing the libs and it would also make my library more accessible...
    Or is there an important reason not to do this?

    I don't know if debug prints is part of the core things we would like to expose for a communication library. It doesn't really fit the profile ;). We might decide to change or remove this without any notice and your sketches would stop working.

    There are probably much better debug print libraries available. Another option is just to copy the code to you own marcel-utility library. πŸ™‚


  • Mod

    @hek said:

    I don't know if debug prints is part of the core things we would like to expose for a communication library.

    Good point hek! πŸ‘
    Stick to the subject πŸ˜‰


  • Mod

    @hek now that I think of it I have access to MyConfig.h anyway so creating my own stuff is basically a no-brainer πŸ™‚


  • Contest Winner

    @marceltrapman

    Why not just drop in your own debug flag:

    boolean myBugFlag = true;
    

    then add it to your code

    if (myBugFlag) Serial.print("Expect to see something here...");

  • Mod

    @BulldogLowell Here's Macro-guy again πŸ˜‰

    How about (at the top of your sketch):

    #ifdef DEBUG
    #define debug(x)     Serial.print(x)
    #define debugln(x)   Serial.println(x)
    #else
    #define debug(x)     // define empty, so macro does nothing
    #define debugln(x)
    #endif 
    

    Use like regular Serial.print throughout your code:

    debug("This is some debug text\n");
    debugln("This is some debug text with newline");
    

    When you #define DEBUG in your code the debug text will be output to the serial port, when you don't define it the debug output will not be compiled in (saves some flash/ram, but doesn't allow dynamic switching of debug statements -- this also can be done though)


  • Contest Winner

    Yes, even better.

    Also to help avoid the ram issue, building on that, just use the F() macro to put all if your text constants into Flash

    DeBugln(F("here is your example."));

  • Mod

    Guys, thanks for thinking with me.

    I like to just use the DEBUG variable as defined in config.h.

    And @Yveaux nice thinking but I want to be able to use formatting so I am going to do something similar to what @hek uses.

    And @BulldogLowell I use PCNL(...) right now. Any (dis-)advantage of either one that you can think of?


  • Hero Member

    Just in case it's useful to somebody, my current approach is:

    // Debug PRinting with LiNefeed and maybe Flash strings or 2nd mode param
    #ifdef DEBUG
    #define DPR(x)      Serial.print(x)
    #define DPR2(x,m)   Serial.print(x,m)
    #define DPRLIN()    Serial.println()
    #define DPRLN(x)    Serial.println(x)
    #define DPRLN2(x,m) Serial.println(x,m)
    // saving string in Flash ProgMem
    #define DPRF(x)     Serial.print(F(x))
    #define DPRLNF(x)   Serial.println(F(x))
    #else
    #define DPR(x)
    #define DPR2(x,m)
    #define DPRLIN()
    #define DPRLN(x)
    #define DPRLN2(x,m)
    #define DPRF(x)
    #define DPRLNF(x)
    #endif
    

    This allows substitute for println() with no args, and for print(val, HEX) type modes as well. I got tired of typing the extra F(...) so added macros to incorporate that too.

    You can make this into a library to include as a .h file - as a note, you still need a corresponding .c file even if empty.


Log in to reply
 

Suggested Topics

23
Online

11.2k
Users

11.1k
Topics

112.5k
Posts